BxOrgsSearchResult.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 Organizations Organizations
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxOrgsSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. $aUnitViews = array('gallery' => 'unit_with_cover.html', 'showcase' => 'unit_with_cover_showcase.html');
  16. if(!empty($aParams['unit_views']) && is_array($aParams['unit_views'])) {
  17. $aParams['unit_views'] = array_merge($aUnitViews, $aParams['unit_views']);
  18. }
  19. else {
  20. if (!is_array($aParams))
  21. $aParams = [];
  22. $aParams['unit_views'] = $aUnitViews;
  23. }
  24. parent::__construct($sMode, $aParams);
  25. $this->aCurrent = array(
  26. 'name' => 'bx_organizations',
  27. 'module_name' => 'bx_organizations',
  28. 'object_metatags' => 'bx_organizations',
  29. 'title' => _t('_bx_orgs_page_title_browse'),
  30. 'table' => 'sys_profiles',
  31. 'tableSearch' => 'bx_organizations_data',
  32. 'ownFields' => array(),
  33. 'searchFields' => array(),
  34. 'restriction' => array(
  35. 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
  36. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  37. 'perofileType' => array('value' => 'bx_organizations', 'field' => 'type', 'operator' => '='),
  38. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_organizations_data'),
  39. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_organizations_data'),
  40. 'online' => array('value' => '', 'field' => 'date', 'operator' => '>', 'table' => 'sys_sessions'),
  41. ),
  42. 'join' => array (
  43. 'profile' => array(
  44. 'type' => 'INNER',
  45. 'table' => 'bx_organizations_data',
  46. 'mainField' => 'content_id',
  47. 'onField' => 'id',
  48. 'joinFields' => array('id', 'org_name', 'picture', 'cover', 'cover_data', 'badge', 'badge_link', 'added', 'author', 'allow_view_to'),
  49. ),
  50. 'account' => array(
  51. 'type' => 'INNER',
  52. 'table' => 'sys_accounts',
  53. 'mainField' => 'account_id',
  54. 'onField' => 'id',
  55. 'joinFields' => array(),
  56. ),
  57. ),
  58. 'paginate' => array('perPage' => getParam('bx_organizations_per_page_browse'), 'start' => 0),
  59. 'sorting' => 'active',
  60. 'rss' => array(
  61. 'title' => '',
  62. 'link' => '',
  63. 'image' => '',
  64. 'profile' => 0,
  65. 'fields' => array (
  66. 'Guid' => 'link',
  67. 'Link' => 'link',
  68. 'Title' => 'org_name',
  69. 'DateTimeUTS' => 'added',
  70. 'Desc' => 'org_name',
  71. 'Image' => 'picture',
  72. ),
  73. ),
  74. 'ident' => 'id'
  75. );
  76. $this->sFilterName = 'bx_organizations_data_filter';
  77. $this->oModule = $this->getMain();
  78. $CNF = &$this->oModule->_oConfig->CNF;
  79. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  80. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  81. $oJoinedProfile = null;
  82. $bProcessConditionsForPrivateContent = true;
  83. $this->_setAccountConfirmationConditions($aParams);
  84. switch ($sMode) {
  85. case 'created_entries':
  86. if(!$this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile))
  87. $this->isError = true;
  88. break;
  89. case 'context':
  90. $oProfileContext = null;
  91. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileContext))
  92. $this->isError = true;
  93. break;
  94. case 'joined_entries':
  95. $oJoinedProfile = !empty($aParams['joined_profile']) ? BxDolProfile::getInstance((int)$aParams['joined_profile']) : null;
  96. if (!$oJoinedProfile) {
  97. $this->isError = true;
  98. break;
  99. }
  100. $bProcessConditionsForPrivateContent = false;
  101. $this->aCurrent['join']['fans'] = array(
  102. 'type' => 'INNER',
  103. 'table' => 'bx_organizations_fans',
  104. 'mainField' => 'id',
  105. 'onField' => 'content',
  106. 'joinFields' => array('initiator'),
  107. );
  108. $this->aCurrent['restriction']['fans'] = array('value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'bx_organizations_fans');
  109. $this->aCurrent['restriction']['fans2'] = array('value' => 1, 'field' => 'mutual', 'operator' => '=', 'table' => 'bx_organizations_fans');
  110. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  111. $this->aCurrent['title'] = _t('_bx_orgs_page_title_joined_entries');
  112. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode . '/' . $oJoinedProfile->id();
  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_orgs_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  121. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  122. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_connections', $oProfile->getDisplayName());
  123. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  124. }
  125. break;
  126. case 'familiar':
  127. if($this->_setFamiliarConnectionsConditions($aParams)) {
  128. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_familiar');
  129. unset($this->aCurrent['rss']);
  130. }
  131. break;
  132. case 'acl':
  133. if ($this->_setAclConditions($aParams)) {
  134. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_by_acl', implode(', ', $this->aCurrent['title']));
  135. unset($this->aCurrent['rss']);
  136. }
  137. break;
  138. case 'favorite':
  139. $oProfileAuthor = null;
  140. if(!$this->_setFavoriteConditions($sMode, $aParams, $oProfileAuthor)) {
  141. $this->isError = true;
  142. break;
  143. }
  144. break;
  145. case 'recent':
  146. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  147. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_recent');
  148. $this->aCurrent['sorting'] = 'last';
  149. $this->sBrowseUrl = 'page.php?i=organizations-home';
  150. break;
  151. case 'featured':
  152. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  153. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_featured');
  154. $this->aCurrent['restriction']['featured']['value'] = '0';
  155. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  156. $this->aCurrent['sorting'] = 'featured';
  157. break;
  158. case 'recommended':
  159. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  160. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_recommended');
  161. $this->aCurrent['restriction']['featured']['value'] = '0';
  162. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  163. $this->aCurrent['sorting'] = 'recommended';
  164. $this->_setConditionsForRecommended();
  165. break;
  166. case 'alphabetical':
  167. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  168. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_alphabetical');
  169. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  170. $this->aCurrent['sorting'] = 'alphabetical';
  171. break;
  172. case 'active':
  173. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  174. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_active');
  175. $this->aCurrent['sorting'] = 'active';
  176. $this->sBrowseUrl = 'page.php?i=organizations-active';
  177. break;
  178. case 'online':
  179. $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
  180. $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_online');
  181. $this->aCurrent['restriction']['online']['value'] = time() - 60 * (int)getParam('sys_account_online_time');
  182. $this->aCurrent['restriction_sql'] = ' AND `sys_accounts`.`profile_id`=`sys_profiles`.`id`';
  183. $this->aCurrent['join']['session'] = array(
  184. 'type' => 'INNER',
  185. 'table' => 'sys_sessions',
  186. 'mainField' => 'account_id',
  187. 'onField' => 'user_id',
  188. 'joinFields' => array('date'),
  189. 'groupTable' => $this->aCurrent['table'],
  190. 'groupField' => 'id'
  191. );
  192. $this->aCurrent['sorting'] = 'online';
  193. $this->sBrowseUrl = 'page.php?i=organizations-online';
  194. break;
  195. case '': // search results
  196. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  197. $this->aCurrent['title'] = _t('_bx_orgs');
  198. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  199. break;
  200. default:
  201. $this->isError = true;
  202. }
  203. if ($bProcessConditionsForPrivateContent)
  204. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  205. $this->sCenterContentUnitSelector = false;
  206. }
  207. function getAlterOrder()
  208. {
  209. switch ($this->aCurrent['sorting']) {
  210. case 'alphabetical':
  211. return array('order' => ' ORDER BY `bx_organizations_data`.`org_name` ASC ');
  212. case 'featured':
  213. return array('order' => ' ORDER BY `bx_organizations_data`.`featured` DESC ');
  214. case 'recommended':
  215. return array('order' => ' ORDER BY RAND() ');
  216. case 'none':
  217. return array();
  218. case 'active':
  219. return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
  220. case 'online':
  221. return array('order' => ' ORDER BY `sys_sessions`.`date` DESC ');
  222. case 'last':
  223. default:
  224. return array('order' => ' ORDER BY `bx_organizations_data`.`added` DESC ');
  225. }
  226. }
  227. function _getPseud ()
  228. {
  229. return array(
  230. 'id' => 'id',
  231. 'org_name' => 'org_name',
  232. 'added' => 'added',
  233. 'author' => 'author',
  234. 'picture' => 'picture',
  235. );
  236. }
  237. }
  238. /** @} */