BxBaseModGroupsSearchResult.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  92. if (!$oProfileAuthor)
  93. return false;
  94. $iProfileAuthor = $oProfileAuthor->id();
  95. $this->aCurrent['restriction']['owner']['value'] = $iProfileAuthor;
  96. if(!empty($aParams['per_page']))
  97. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  98. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  99. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  100. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  101. return true;
  102. }
  103. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  104. {
  105. $CNF = &$this->oModule->_oConfig->CNF;
  106. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  107. if (!$oProfileAuthor)
  108. return false;
  109. $iListId = 0;
  110. if(isset($aParams['list_id']))
  111. $iListId = (int)$aParams['list_id'];
  112. $iProfileAuthor = $oProfileAuthor->id();
  113. $oFavorite = $this->oModule->getObjectFavorite();
  114. if(!$oFavorite || (!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id()))
  115. return false;
  116. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor, $iListId);
  117. if(!empty($aConditions) && is_array($aConditions)) {
  118. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  119. $this->aCurrent['restriction'] = array();
  120. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  121. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  122. $this->aCurrent['join'] = array();
  123. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  124. }
  125. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  126. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  127. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  128. return true;
  129. }
  130. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  131. {
  132. $CNF = &$this->oModule->_oConfig->CNF;
  133. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  134. if (!$oProfileContext)
  135. return false;
  136. $iProfileIdContext = $oProfileContext->id();
  137. $this->aCurrent['restriction']['context'] = array(
  138. 'value' => -$iProfileIdContext,
  139. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  140. 'operator' => '=',
  141. 'table' => $CNF['TABLE_ENTRIES']
  142. );
  143. if(!empty($aParams['per_page']))
  144. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  145. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  146. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  147. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  148. return true;
  149. }
  150. }
  151. /** @} */