BxBaseModGeneralSearchResult.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_DOL_URL_ROOT . 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_DOL_URL_ROOT . $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->addConditionsForProhibitedCf($CNF);
  50. $this->addConditionsForViewerCf($CNF);
  51. }
  52. protected function addConditionsForAuthorStatus($CNF)
  53. {
  54. if (empty($CNF['FIELD_AUTHOR']))
  55. return;
  56. $this->aCurrent['restriction']['statusAuthor'] = [
  57. 'value' => 'active',
  58. 'field' => 'status',
  59. 'operator' => '=',
  60. 'table' => 'sys_profiles',
  61. ];
  62. $this->aCurrent['join']['statusAuthor'] = [
  63. 'type' => 'INNER',
  64. 'table' => 'sys_profiles',
  65. 'mainField' => $CNF['FIELD_AUTHOR'],
  66. 'onField' => 'id',
  67. 'joinFields' => array(),
  68. ];
  69. }
  70. protected function addConditionsForProhibitedCf($CNF)
  71. {
  72. if(empty($CNF['FIELD_CF']))
  73. return;
  74. $sValues = getParam('sys_cf_prohibited');
  75. if(!$sValues)
  76. return;
  77. $aValues = explode(',', $sValues);
  78. if(!$aValues)
  79. return;
  80. $this->aCurrent['restriction']['prohibited_cf'] = [
  81. 'value' => $aValues,
  82. 'field' => $CNF['FIELD_CF'],
  83. 'operator' => 'not in',
  84. ];
  85. }
  86. protected function addConditionsForViewerCf($CNF)
  87. {
  88. if(empty($CNF['FIELD_CF']) || !isLogged())
  89. return;
  90. $iViewer = bx_get_logged_profile_id();
  91. $aViewerInfo = BxDolProfileQuery::getInstance()->getInfoById($iViewer);
  92. if(empty($aViewerInfo) || !is_array($aViewerInfo))
  93. return;
  94. $this->aCurrent['restriction']['viewer_cf'] = [
  95. 'value' => $aViewerInfo['cfw_value'],
  96. 'field' => $CNF['FIELD_CF'],
  97. 'operator' => 'in_set',
  98. ];
  99. }
  100. /**
  101. * Add conditions for private content
  102. */
  103. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  104. {
  105. // default is bProcessPrivateContent = 1,
  106. // so private items are shown as empty boxes with "Private" title
  107. // we can show public content when privacy object is available
  108. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  109. return;
  110. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  111. if(!$oPrivacy)
  112. return;
  113. // for posts in some context we need to show all items, not only public content
  114. if (!empty($this->aCurrent['restriction']['context']['value']) || !empty($this->aCurrent['restriction']['author']['value'])) {
  115. $this->setProcessPrivateContent(true);
  116. return;
  117. }
  118. // build condition to show only public content
  119. $aCondition = $oPrivacy->getContentPublicAsCondition($oProfile ? $oProfile->id() : 0, $aCustomGroup);
  120. if(empty($aCondition) || !is_array($aCondition))
  121. return;
  122. if(isset($aCondition['restriction'])) {
  123. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  124. $this->aPrivateConditionsIndexes['restriction'] = array_keys($aCondition['restriction']);
  125. }
  126. if(isset($aCondition['join'])) {
  127. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  128. $this->aPrivateConditionsIndexes['join'] = array_keys($aCondition['join']);
  129. }
  130. $this->setProcessPrivateContent(false);
  131. }
  132. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  133. {
  134. if($this->bShowcaseView)
  135. return '';
  136. $sPagination = parent::showPagination ($bAdmin, $bChangePage, $bPageReload);
  137. if(empty($sPagination))
  138. return '';
  139. return $sPagination;
  140. }
  141. protected function getItemPerPageInShowCase ()
  142. {
  143. $iPerPageInShowCase = BX_SYS_PER_PAGE_BROWSE_SHOWCASE;
  144. $CNF = &$this->oModule->_oConfig->CNF;
  145. if (isset($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']))
  146. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']);
  147. return $iPerPageInShowCase;
  148. }
  149. function displayResultBlock()
  150. {
  151. if ($this->bShowcaseView) {
  152. $this->addContainerClass(array('bx-base-unit-showcase-wrapper'));
  153. $this->aCurrent['paginate']['perPage'] = $this->getItemPerPageInShowCase();
  154. $this->oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'));
  155. $this->oModule->_oTemplate->addJs(array('flickity/flickity.pkgd.min.js','modules/base/general/js/|showcase.js'));
  156. }
  157. return parent::displayResultBlock();
  158. }
  159. }
  160. /** @} */