BxGroupsSearchResult.php 8.9 KB

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