BxBaseModGroupsSearchResult.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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']) && $this->oModule->_oConfig->getJsClass('main') != '') {
  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. public function processingAPI ()
  37. {
  38. $aResult = parent::processingAPI();
  39. switch($this->_sMode) {
  40. case 'created_entries':
  41. if(isset($this->_aParams['author']))
  42. $aResult['params']['author'] = $this->_aParams['author'];
  43. break;
  44. case 'joined_entries':
  45. if(isset($this->_aParams['joined_profile']))
  46. $aResult['params']['joined_profile'] = $this->_aParams['joined_profile'];
  47. break;
  48. case 'followed_entries':
  49. if(isset($this->_aParams['followed_profile']))
  50. $aResult['params']['followed_profile'] = $this->_aParams['followed_profile'];
  51. break;
  52. case 'context':
  53. if(isset($this->_aParams['context']))
  54. $aResult['params']['context'] = $this->_aParams['context'];
  55. break;
  56. case 'connections':
  57. foreach(['object', 'type', 'profile', 'profile2', 'mutual'] as $sParam)
  58. if(isset($this->_aParams[$sParam]))
  59. $aResult['params'][$sParam] = $this->_aParams[$sParam];
  60. break;
  61. }
  62. return $aResult;
  63. }
  64. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  65. {
  66. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  67. return;
  68. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  69. if(!$oPrivacy)
  70. return;
  71. parent::addConditionsForPrivateContent($CNF, $oProfile, array_merge($aCustomGroup, $oPrivacy->getPartiallyVisiblePrivacyGroups()));
  72. }
  73. protected function addConditionsForAuthorStatus($CNF)
  74. {
  75. return;
  76. }
  77. protected function addConditionsForCf($CNF)
  78. {
  79. if(empty($CNF['FIELD_CF']))
  80. return;
  81. $oCf = BxDolContentFilter::getInstance();
  82. if(!$oCf->isEnabled())
  83. return;
  84. $aConditions = $oCf->getConditions($this->aCurrent['join']['profile']['table'], $CNF['FIELD_CF']);
  85. if(!empty($aConditions) && is_array($aConditions))
  86. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  87. }
  88. protected function _setAuthorConditions($sMode, $aParams, &$oProfileAuthor)
  89. {
  90. $CNF = &$this->oModule->_oConfig->CNF;
  91. if(!($oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author'])))
  92. return !($this->isError = true);
  93. $iProfileAuthor = $oProfileAuthor->id();
  94. $this->aCurrent['restriction']['owner']['value'] = $iProfileAuthor;
  95. if(!empty($aParams['per_page']))
  96. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  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 _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  103. {
  104. $CNF = &$this->oModule->_oConfig->CNF;
  105. if(!($oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user'])))
  106. return !($this->isError = true);
  107. $iListId = 0;
  108. if(isset($aParams['list_id']))
  109. $iListId = (int)$aParams['list_id'];
  110. $iProfileAuthor = $oProfileAuthor->id();
  111. $oFavorite = $this->oModule->getObjectFavorite();
  112. if(!$oFavorite || (!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id()))
  113. return !($this->isError = true);
  114. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor, $iListId);
  115. if(!empty($aConditions) && is_array($aConditions)) {
  116. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  117. $this->aCurrent['restriction'] = [];
  118. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  119. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  120. $this->aCurrent['join'] = [];
  121. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  122. }
  123. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  124. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  125. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  126. return true;
  127. }
  128. protected function _updateCurrentForJoinedEntries($sMode, $aParams, &$oJoinedProfile)
  129. {
  130. $CNF = &$this->oModule->_oConfig->CNF;
  131. if(!($oJoinedProfile = BxDolProfile::getInstance((int)$aParams['joined_profile'])))
  132. return !($this->isError = true);
  133. $sDbPrefix = $this->oModule->_oConfig->getDbPrefix();
  134. $this->aCurrent['join']['fans'] = [
  135. 'type' => 'INNER',
  136. 'table' => $sDbPrefix . 'fans',
  137. 'mainField' => 'id',
  138. 'onField' => 'content',
  139. 'joinFields' => ['initiator'],
  140. ];
  141. $this->aCurrent['restriction']['fans'] = ['value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => $sDbPrefix . 'fans'];
  142. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  143. $this->aCurrent['title'] = ($sKey = 'txt_joined_entries') && !empty($CNF['T'][$sKey]) ? _t($CNF['T'][$sKey]) : '';
  144. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $oJoinedProfile->id();
  145. return true;
  146. }
  147. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  148. {
  149. $CNF = &$this->oModule->_oConfig->CNF;
  150. if(!($oProfileContext = BxDolProfile::getInstance((int)$aParams['context'])))
  151. return !($this->isError = true);
  152. $iProfileIdContext = $oProfileContext->id();
  153. $this->aCurrent['restriction']['context'] = [
  154. 'value' => -$iProfileIdContext,
  155. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  156. 'operator' => '=',
  157. 'table' => $CNF['TABLE_ENTRIES']
  158. ];
  159. if(!empty($aParams['per_page']))
  160. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  161. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  162. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  163. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  164. return true;
  165. }
  166. protected function _updateCurrentForFollowedEntries($sMode, $aParams, &$oJoinedProfile)
  167. {
  168. $CNF = &$this->oModule->_oConfig->CNF;
  169. if(!($oJoinedProfile = BxDolProfile::getInstance((int)$aParams['followed_profile'])))
  170. return !($this->isError = true);
  171. $this->aCurrent['join']['followed'] = [
  172. 'type' => 'INNER',
  173. 'table' => 'sys_profiles_conn_subscriptions',
  174. 'mainField' => 'id',
  175. 'onField' => 'content',
  176. 'joinFields' => ['initiator'],
  177. ];
  178. $this->aCurrent['restriction']['followed'] = ['value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'sys_profiles_conn_subscriptions'];
  179. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_FOLLOWED_ENTRIES'] . '&profile_id={profile_id}';
  180. $this->aCurrent['title'] = ($sKey = 'txt_followed_entries') && !empty($CNF['T'][$sKey]) ? _t($CNF['T'][$sKey]) : '';
  181. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $oJoinedProfile->id();
  182. return true;
  183. }
  184. }
  185. /** @} */