BxGroupsSearchResult.php 8.1 KB

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