BxBaseModGeneralSearchResult.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_SYS_PER_PAGE_BROWSE_SHOWCASE', 32);
  12. class BxBaseModGeneralSearchResult extends BxTemplSearchResult
  13. {
  14. protected $oModule;
  15. protected $sFilterName;
  16. protected $bShowcaseView = false;
  17. protected $aUnitViews = array();
  18. protected $sUnitViewDefault = 'gallery';
  19. function __construct($sMode = '', $aParams = array())
  20. {
  21. $this->_sMode = $sMode;
  22. $this->_aParams = $aParams;
  23. parent::__construct();
  24. }
  25. function getMain()
  26. {
  27. return BxDolModule::getInstance($this->aCurrent['module_name']);
  28. }
  29. function getContentInfoObject()
  30. {
  31. return BxDolContentInfo::getObjectInstance($this->aCurrent['name']);
  32. }
  33. function getRssUnitLink (&$a)
  34. {
  35. $CNF = &$this->oModule->_oConfig->CNF;
  36. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $a[$CNF['FIELD_ID']]));
  37. }
  38. function getRssPageUrl ()
  39. {
  40. if (false === parent::getRssPageUrl())
  41. return false;
  42. $oPermalinks = BxDolPermalinks::getInstance();
  43. return bx_absolute_url($oPermalinks->permalink($this->aCurrent['rss']['link']));
  44. }
  45. function rss ()
  46. {
  47. if (!isset($this->aCurrent['rss']))
  48. return '';
  49. $this->aCurrent['paginate']['perPage'] = empty($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']) ? 10 : getParam($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']);
  50. return parent::rss();
  51. }
  52. protected function addCustomConditions($CNF, $oProfile, $sMode, $aParams)
  53. {
  54. $this->addConditionsForAuthorStatus($CNF);
  55. $this->addConditionsForCf($CNF);
  56. if(!empty($aParams['filter']) && is_array($aParams['filter']))
  57. $this->addConditionsForFilter($CNF, $sMode, $aParams);
  58. }
  59. protected function addConditionsForAuthorStatus($CNF)
  60. {
  61. if (empty($CNF['FIELD_AUTHOR']))
  62. return;
  63. $this->aCurrent['restriction']['statusAuthor'] = [
  64. 'value' => 'active',
  65. 'field' => 'status',
  66. 'operator' => '=',
  67. 'table' => 'sys_profiles',
  68. ];
  69. $this->aCurrent['join']['statusAuthor'] = [
  70. 'type' => 'INNER',
  71. 'table' => 'sys_profiles',
  72. 'mainField' => $CNF['FIELD_AUTHOR'],
  73. 'onField' => 'id',
  74. 'joinFields' => array(),
  75. ];
  76. }
  77. protected function addConditionsForCf($CNF)
  78. {
  79. if(empty($CNF['FIELD_CF']))
  80. return;
  81. $oCf = BxDolContentFilter::getInstance();
  82. if(!$oCf->isEnabled())
  83. return;
  84. $aConditions = $oCf->getConditions($this->aCurrent['table'], $CNF['FIELD_CF']);
  85. if(!empty($aConditions) && is_array($aConditions))
  86. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  87. }
  88. protected function addConditionsForFilter($CNF, $sMode, $aParams)
  89. {
  90. $aFilter = $aParams['filter'];
  91. if(empty($aFilter['field']) || empty($aFilter['value']))
  92. return;
  93. $aRestriction = [
  94. 'value' => $aFilter['value'],
  95. 'field' => $aFilter['field'],
  96. 'operator' => '=',
  97. ];
  98. if(isset($aFilter['operator']))
  99. $aRestriction['operator'] = $aFilter['operator'];
  100. if(isset($aFilter['table']))
  101. switch($aFilter['table']) {
  102. case 'table':
  103. $aRestriction['table'] = $this->aCurrent['table'];
  104. break;
  105. case 'tableSearch':
  106. $aRestriction['table'] = $this->aCurrent['tableSearch'];
  107. break;
  108. default:
  109. $aRestriction['table'] = $aFilter['table'];
  110. }
  111. $this->aCurrent['restriction']['filter'] = $aRestriction;
  112. }
  113. /**
  114. * Add conditions for private content
  115. */
  116. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  117. {
  118. // default is bProcessPrivateContent = 1,
  119. // so private items are shown as empty boxes with "Private" title
  120. // we can show public content when privacy object is available
  121. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  122. return;
  123. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  124. if(!$oPrivacy)
  125. return;
  126. // for posts in some context we need to show all items, not only public content
  127. if (!empty($this->aCurrent['restriction']['context']['value']) || !empty($this->aCurrent['restriction']['author']['value'])) {
  128. $this->setProcessPrivateContent(true);
  129. return;
  130. }
  131. // build condition to show only public content
  132. $aCondition = $oPrivacy->getContentPublicAsCondition($oProfile ? $oProfile->id() : 0, $aCustomGroup);
  133. if(empty($aCondition) || !is_array($aCondition))
  134. return;
  135. if(isset($aCondition['restriction'])) {
  136. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  137. $this->aPrivateConditionsIndexes['restriction'] = array_keys($aCondition['restriction']);
  138. }
  139. if(isset($aCondition['join'])) {
  140. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  141. $this->aPrivateConditionsIndexes['join'] = array_keys($aCondition['join']);
  142. }
  143. $this->setProcessPrivateContent(false);
  144. }
  145. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  146. {
  147. if($this->bShowcaseView)
  148. return '';
  149. $sPagination = parent::showPagination ($bAdmin, $bChangePage, $bPageReload);
  150. if(empty($sPagination))
  151. return '';
  152. return $sPagination;
  153. }
  154. protected function getItemPerPageInShowCase ()
  155. {
  156. $iPerPageInShowCase = BX_SYS_PER_PAGE_BROWSE_SHOWCASE;
  157. $CNF = &$this->oModule->_oConfig->CNF;
  158. if (isset($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']))
  159. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']);
  160. return $iPerPageInShowCase;
  161. }
  162. function displayResultBlock()
  163. {
  164. if ($this->bShowcaseView) {
  165. $this->addContainerClass(array('bx-base-unit-showcase-wrapper'));
  166. $this->aCurrent['paginate']['perPage'] = $this->getItemPerPageInShowCase();
  167. $this->oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'));
  168. $this->oModule->_oTemplate->addJs(array('flickity/flickity.pkgd.min.js','modules/base/general/js/|showcase.js'));
  169. }
  170. return parent::displayResultBlock();
  171. }
  172. function decodeDataAPI($a)
  173. {
  174. $bExtendedUnits = getParam('sys_api_extended_units') == 'on';
  175. foreach($a as $i => $r)
  176. $a[$i] = $this->oModule->decodeDataAPI($r, ['extended' => $bExtendedUnits]);
  177. return $a;
  178. }
  179. }
  180. /** @} */