1
0

BxGroupsSearchResult.php 7.8 KB

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