BxBaseModGeneralSearchResult.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. 'mainFieldFunc' => 'ABS',
  74. 'onField' => 'id',
  75. 'joinFields' => array(),
  76. ];
  77. }
  78. protected function addConditionsForCf($CNF)
  79. {
  80. if(empty($CNF['FIELD_CF']))
  81. return;
  82. $oCf = BxDolContentFilter::getInstance();
  83. if(!$oCf->isEnabled())
  84. return;
  85. $aConditions = $oCf->getConditions($this->aCurrent['table'], $CNF['FIELD_CF']);
  86. if(!empty($aConditions) && is_array($aConditions))
  87. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  88. }
  89. protected function addConditionsForFilter($CNF, $sMode, $aParams)
  90. {
  91. $aFilter = $aParams['filter'];
  92. if(empty($aFilter['field']) || empty($aFilter['value']))
  93. return;
  94. $aRestriction = [
  95. 'value' => $aFilter['value'],
  96. 'field' => $aFilter['field'],
  97. 'operator' => '=',
  98. ];
  99. if(isset($aFilter['operator']))
  100. $aRestriction['operator'] = $aFilter['operator'];
  101. if(isset($aFilter['table']))
  102. switch($aFilter['table']) {
  103. case 'table':
  104. $aRestriction['table'] = $this->aCurrent['table'];
  105. break;
  106. case 'tableSearch':
  107. $aRestriction['table'] = $this->aCurrent['tableSearch'];
  108. break;
  109. default:
  110. $aRestriction['table'] = $aFilter['table'];
  111. }
  112. $this->aCurrent['restriction']['filter'] = $aRestriction;
  113. }
  114. /**
  115. * Add conditions for private content
  116. */
  117. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  118. {
  119. // default is bProcessPrivateContent = 1,
  120. // so private items are shown as empty boxes with "Private" title
  121. // we can show public content when privacy object is available
  122. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  123. return;
  124. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  125. if(!$oPrivacy)
  126. return;
  127. // for posts in some context we need to show all items, not only public content
  128. if (!empty($this->aCurrent['restriction']['context']['value']) || !empty($this->aCurrent['restriction']['author']['value'])) {
  129. $this->setProcessPrivateContent(true);
  130. return;
  131. }
  132. // build condition to show only public content
  133. $aCondition = $oPrivacy->getContentPublicAsCondition($oProfile ? $oProfile->id() : 0, $aCustomGroup);
  134. if(empty($aCondition) || !is_array($aCondition))
  135. return;
  136. if(isset($aCondition['restriction'])) {
  137. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  138. $this->aPrivateConditionsIndexes['restriction'] = array_keys($aCondition['restriction']);
  139. }
  140. if(isset($aCondition['join'])) {
  141. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  142. $this->aPrivateConditionsIndexes['join'] = array_keys($aCondition['join']);
  143. }
  144. $this->setProcessPrivateContent(false);
  145. }
  146. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  147. {
  148. if($this->bShowcaseView)
  149. return '';
  150. $sPagination = parent::showPagination ($bAdmin, $bChangePage, $bPageReload);
  151. if(empty($sPagination))
  152. return '';
  153. return $sPagination;
  154. }
  155. protected function getItemPerPageInShowCase ()
  156. {
  157. $iPerPageInShowCase = BX_SYS_PER_PAGE_BROWSE_SHOWCASE;
  158. $CNF = &$this->oModule->_oConfig->CNF;
  159. if (isset($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']))
  160. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']);
  161. return $iPerPageInShowCase;
  162. }
  163. function displayResultBlock()
  164. {
  165. if ($this->bShowcaseView) {
  166. $this->addContainerClass(array('bx-base-unit-showcase-wrapper'));
  167. $this->aCurrent['paginate']['perPage'] = $this->getItemPerPageInShowCase();
  168. $this->oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'));
  169. $this->oModule->_oTemplate->addJs(array('flickity/flickity.pkgd.min.js','modules/base/general/js/|showcase.js'));
  170. }
  171. return parent::displayResultBlock();
  172. }
  173. function decodeDataAPI($a)
  174. {
  175. $bExtendedUnits = getParam('sys_api_extended_units') == 'on';
  176. foreach($a as $i => $r)
  177. $a[$i] = $this->oModule->decodeDataAPI($r, ['extended' => $bExtendedUnits]);
  178. return $a;
  179. }
  180. }
  181. /** @} */