BxGroupsSearchResult.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 Groups Groups
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxGroupsSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_groups',
  18. 'module_name' => 'bx_groups',
  19. 'object_metatags' => 'bx_groups',
  20. 'title' => _t('_bx_groups_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_groups_data',
  23. 'ownFields' => array(),
  24. 'searchFields' => array(),
  25. 'restriction' => array(
  26. 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
  27. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  28. 'perofileType' => array('value' => 'bx_groups', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_groups_data'),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_groups_data'),
  31. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_groups_data'),
  32. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '=', 'table' => 'bx_groups_data'),
  33. ),
  34. 'join' => array (
  35. 'profile' => array(
  36. 'type' => 'INNER',
  37. 'table' => 'bx_groups_data',
  38. 'mainField' => 'content_id',
  39. 'onField' => 'id',
  40. 'joinFields' => array('id', 'group_name', 'group_desc', 'picture', 'cover', 'cover_data', 'added', 'author', 'allow_view_to'),
  41. ),
  42. 'account' => array(
  43. 'type' => 'INNER',
  44. 'table' => 'sys_accounts',
  45. 'mainField' => 'account_id',
  46. 'onField' => 'id',
  47. 'joinFields' => array(),
  48. ),
  49. ),
  50. 'paginate' => array('perPage' => getParam('bx_groups_per_page_browse'), 'start' => 0, 'on_top' => true, 'on_bottom' => true),
  51. 'sorting' => 'last',
  52. 'rss' => array(
  53. 'title' => '',
  54. 'link' => '',
  55. 'image' => '',
  56. 'profile' => 0,
  57. 'fields' => array (
  58. 'Guid' => 'link',
  59. 'Link' => 'link',
  60. 'Title' => 'group_name',
  61. 'DateTimeUTS' => 'added',
  62. 'Desc' => 'group_name',
  63. 'Image' => 'picture',
  64. ),
  65. ),
  66. 'ident' => 'id'
  67. );
  68. $this->sFilterName = 'bx_groups_data_filter';
  69. $this->oModule = $this->getMain();
  70. $CNF = &$this->oModule->_oConfig->CNF;
  71. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  72. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  73. $oJoinedProfile = null;
  74. $bProcessConditionsForPrivateContent = true;
  75. switch ($sMode) {
  76. case 'created_entries':
  77. $this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile);
  78. break;
  79. case 'context':
  80. $oProfileContext = null;
  81. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileContext))
  82. break;
  83. if(!$this->aCurrent['title'])
  84. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_by_context');
  85. break;
  86. case 'joined_entries':
  87. $oJoinedProfile = null;
  88. if(!$this->_updateCurrentForJoinedEntries($sMode, $aParams, $oJoinedProfile))
  89. break;
  90. $bProcessConditionsForPrivateContent = false;
  91. if(!$this->aCurrent['title'])
  92. $this->aCurrent['title'] = _t('_bx_groups_page_title_joined_entries');
  93. break;
  94. case 'context_joined_entries':
  95. $oProfileContext = null;
  96. if(!$this->_updateCurrentForContext('context', $aParams, $oProfileContext))
  97. break;
  98. $oJoinedProfile = null;
  99. if(!$this->_updateCurrentForJoinedEntries('joined_entries', $aParams, $oJoinedProfile))
  100. break;
  101. $bProcessConditionsForPrivateContent = false;
  102. $this->sBrowseUrl = '';
  103. $this->aCurrent['title'] = '';
  104. unset($this->aCurrent['rss']);
  105. break;
  106. case 'followed_entries':
  107. $oJoinedProfile = null;
  108. if(!$this->_updateCurrentForFollowedEntries($sMode, $aParams, $oJoinedProfile))
  109. break;
  110. $bProcessConditionsForPrivateContent = false;
  111. if(!$this->aCurrent['title'])
  112. $this->aCurrent['title'] = _t('_bx_groups_page_title_followed_entries');
  113. break;
  114. case 'connections':
  115. if ($this->_setConnectionsConditions($aParams)) {
  116. $bProcessConditionsForPrivateContent = false;
  117. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  118. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  119. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  120. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  121. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  122. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_connections', $oProfile->getDisplayName());
  123. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  124. }
  125. break;
  126. case 'favorite':
  127. $this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile);
  128. break;
  129. case 'recent':
  130. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  131. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_recent');
  132. $this->aCurrent['sorting'] = 'last';
  133. $this->sBrowseUrl = 'page.php?i=groups-home';
  134. break;
  135. case 'featured':
  136. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  137. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_featured');
  138. $this->aCurrent['restriction']['featured']['value'] = '0';
  139. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  140. $this->aCurrent['sorting'] = 'featured';
  141. break;
  142. case 'recommended':
  143. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  144. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_recommended');
  145. $this->aCurrent['restriction']['featured']['value'] = '0';
  146. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  147. $this->aCurrent['sorting'] = 'recommended';
  148. $this->_setConditionsForRecommended();
  149. break;
  150. case 'top':
  151. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  152. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_top');
  153. $this->aCurrent['sorting'] = 'top';
  154. $this->sBrowseUrl = 'page.php?i=groups-top';
  155. break;
  156. case '': // search results
  157. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  158. $this->aCurrent['title'] = _t('_bx_groups');
  159. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  160. break;
  161. default:
  162. $this->isError = true;
  163. }
  164. if ($bProcessConditionsForPrivateContent) {
  165. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  166. $this->addCustomConditions($CNF, $oJoinedProfile, $sMode, $aParams);
  167. }
  168. $this->sCenterContentUnitSelector = false;
  169. }
  170. function getAlterOrder()
  171. {
  172. switch ($this->aCurrent['sorting']) {
  173. case 'featured':
  174. return array('order' => ' ORDER BY `bx_groups_data`.`featured` DESC ');
  175. case 'recommended':
  176. return array('order' => ' ORDER BY RAND() ');
  177. case 'none':
  178. return array();
  179. case 'top':
  180. return array('order' => ' ORDER BY `bx_groups_data`.`views` DESC ');
  181. case 'last':
  182. default:
  183. return array('order' => ' ORDER BY `bx_groups_data`.`added` DESC ');
  184. }
  185. }
  186. function _getPseud ()
  187. {
  188. return array(
  189. 'id' => 'id',
  190. 'group_name' => 'group_name',
  191. 'added' => 'added',
  192. 'author' => 'author',
  193. 'picture' => 'picture',
  194. );
  195. }
  196. }
  197. /** @} */