BxGroupsSearchResult.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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', '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' => 'none',
  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 'joined_entries':
  81. $oJoinedProfile = BxDolProfile::getInstance((int)$aParams['joined_profile']);
  82. if (!$oJoinedProfile) {
  83. $this->isError = true;
  84. break;
  85. }
  86. $bProcessConditionsForPrivateContent = false;
  87. $this->aCurrent['join']['fans'] = array(
  88. 'type' => 'INNER',
  89. 'table' => 'bx_groups_fans',
  90. 'mainField' => 'id',
  91. 'onField' => 'content',
  92. 'joinFields' => array('initiator'),
  93. );
  94. $this->aCurrent['restriction']['fans'] = array('value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'bx_groups_fans');
  95. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  96. $this->aCurrent['title'] = _t('_bx_groups_page_title_joined_entries');
  97. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode . '/' . $oJoinedProfile->id();
  98. break;
  99. case 'connections':
  100. if ($this->_setConnectionsConditions($aParams)) {
  101. $bProcessConditionsForPrivateContent = false;
  102. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  103. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  104. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  105. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  106. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  107. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_connections', $oProfile->getDisplayName());
  108. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  109. }
  110. break;
  111. case 'favorite':
  112. if(!$this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile)) {
  113. $this->isError = true;
  114. break;
  115. }
  116. break;
  117. case 'recent':
  118. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  119. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_recent');
  120. $this->aCurrent['sorting'] = 'last';
  121. $this->sBrowseUrl = 'page.php?i=groups-home';
  122. break;
  123. case 'featured':
  124. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  125. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_featured');
  126. $this->aCurrent['restriction']['featured']['value'] = '0';
  127. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  128. $this->aCurrent['sorting'] = 'featured';
  129. break;
  130. case 'recommended':
  131. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  132. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_recommended');
  133. $this->aCurrent['restriction']['featured']['value'] = '0';
  134. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  135. $this->aCurrent['sorting'] = 'recommended';
  136. $this->_setConditionsForRecommended();
  137. break;
  138. case 'top':
  139. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  140. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_top');
  141. $this->aCurrent['sorting'] = 'top';
  142. $this->sBrowseUrl = 'page.php?i=groups-top';
  143. break;
  144. case '': // search results
  145. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  146. $this->aCurrent['title'] = _t('_bx_groups');
  147. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  148. break;
  149. default:
  150. $this->isError = true;
  151. }
  152. if ($bProcessConditionsForPrivateContent)
  153. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  154. $this->sCenterContentUnitSelector = false;
  155. }
  156. function getAlterOrder()
  157. {
  158. switch ($this->aCurrent['sorting']) {
  159. case 'featured':
  160. return array('order' => ' ORDER BY `bx_groups_data`.`featured` DESC ');
  161. case 'recommended':
  162. return array('order' => ' ORDER BY RAND() ');
  163. case 'none':
  164. return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
  165. case 'top':
  166. return array('order' => ' ORDER BY `bx_groups_data`.`views` DESC ');
  167. case 'last':
  168. default:
  169. return array('order' => ' ORDER BY `bx_groups_data`.`added` DESC ');
  170. }
  171. }
  172. function _getPseud ()
  173. {
  174. return array(
  175. 'id' => 'id',
  176. 'group_name' => 'group_name',
  177. 'added' => 'added',
  178. 'author' => 'author',
  179. 'picture' => 'picture',
  180. );
  181. }
  182. }
  183. /** @} */