BxBaseModGroupsSearchResult.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsSearchResult extends BxBaseModProfileSearchResult
  12. {
  13. public function __construct($sMode = '', $aParams = array())
  14. {
  15. if (!isset($aParams['unit_views'])) {
  16. if (!is_array($aParams))
  17. $aParams = [];
  18. $aParams['unit_views'] = array('gallery' => 'unit.html', 'showcase' => 'unit_with_cover_showcase.html');
  19. }
  20. parent::__construct($sMode, $aParams);
  21. }
  22. public function displaySearchBox ($sContent, $sPaginate = '')
  23. {
  24. $aResult = parent::displaySearchBox($sContent, $sPaginate);
  25. if(!empty($aResult['content'])) {
  26. $this->oModule->_oTemplate->addJs(['modules/base/groups/js/|main.js', 'main.js']);
  27. $aResult['content'] = $this->oModule->_oTemplate->getJsCode('main', [
  28. 'sModule' => $this->oModule->getName()
  29. ], [
  30. 'wrap' => true,
  31. 'mask' => "if(window['{object}'] == undefined) window['{object}'] = new {class}({params});"
  32. ]) . $aResult['content'];
  33. }
  34. return $aResult;
  35. }
  36. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  37. {
  38. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  39. return;
  40. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  41. if(!$oPrivacy)
  42. return;
  43. parent::addConditionsForPrivateContent($CNF, $oProfile, array_merge($aCustomGroup, $oPrivacy->getPartiallyVisiblePrivacyGroups()));
  44. }
  45. protected function addConditionsForAuthorStatus($CNF)
  46. {
  47. return;
  48. }
  49. protected function addConditionsForCf($CNF)
  50. {
  51. if(empty($CNF['FIELD_CF']))
  52. return;
  53. $oCf = BxDolContentFilter::getInstance();
  54. if(!$oCf->isEnabled())
  55. return;
  56. $aConditions = $oCf->getConditions($this->aCurrent['join']['profile']['table'], $CNF['FIELD_CF']);
  57. if(!empty($aConditions) && is_array($aConditions))
  58. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  59. }
  60. protected function _setAuthorConditions($sMode, $aParams, &$oProfileAuthor)
  61. {
  62. $CNF = &$this->oModule->_oConfig->CNF;
  63. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  64. if (!$oProfileAuthor)
  65. return false;
  66. $iProfileAuthor = $oProfileAuthor->id();
  67. $this->aCurrent['restriction']['owner']['value'] = $iProfileAuthor;
  68. if(!empty($aParams['per_page']))
  69. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  70. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  71. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  72. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  73. return true;
  74. }
  75. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  76. {
  77. $CNF = &$this->oModule->_oConfig->CNF;
  78. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  79. if (!$oProfileAuthor)
  80. return false;
  81. $iListId = 0;
  82. if(isset($aParams['list_id']))
  83. $iListId = (int)$aParams['list_id'];
  84. $iProfileAuthor = $oProfileAuthor->id();
  85. $oFavorite = $this->oModule->getObjectFavorite();
  86. if(!$oFavorite || (!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id()))
  87. return false;
  88. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor, $iListId);
  89. if(!empty($aConditions) && is_array($aConditions)) {
  90. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  91. $this->aCurrent['restriction'] = array();
  92. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  93. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  94. $this->aCurrent['join'] = array();
  95. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  96. }
  97. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  98. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  99. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  100. return true;
  101. }
  102. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  103. {
  104. $CNF = &$this->oModule->_oConfig->CNF;
  105. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  106. if (!$oProfileContext)
  107. return false;
  108. $iProfileIdContext = $oProfileContext->id();
  109. $this->aCurrent['restriction']['context'] = array(
  110. 'value' => -$iProfileIdContext,
  111. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  112. 'operator' => '=',
  113. 'table' => $CNF['TABLE_ENTRIES']
  114. );
  115. if(!empty($aParams['per_page']))
  116. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  117. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  118. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  119. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  120. return true;
  121. }
  122. }
  123. /** @} */