BxBaseModGeneralSearchResult.php 7.1 KB

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