BxBaseModGeneralSearchResult.php 6.7 KB

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