BxEventsSearchResult.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 Events Events
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxEventsSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_events',
  18. 'module_name' => 'bx_events',
  19. 'object_metatags' => 'bx_events',
  20. 'title' => _t('_bx_events_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_events_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_events', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_events_data'),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_events_data'),
  31. 'upcoming' => array('value' => '', 'field' => 'date_end', 'operator' => '>', 'table' => 'bx_events_data'),
  32. 'past' => array('value' => '', 'field' => 'date_end', 'operator' => '<', 'table' => 'bx_events_data'),
  33. 'date_start_from' => array('value' => '', 'field' => 'date_start', 'operator' => '>=', 'table' => 'bx_events_data'),
  34. 'date_start_to' => array('value' => '', 'field' => 'date_start', 'operator' => '<=', 'table' => 'bx_events_data'),
  35. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_events_data'),
  36. ),
  37. 'join' => array (
  38. 'profile' => array(
  39. 'type' => 'INNER',
  40. 'table' => 'bx_events_data',
  41. 'mainField' => 'content_id',
  42. 'onField' => 'id',
  43. 'joinFields' => array('id', 'event_name', 'event_desc', 'picture', 'cover', 'added', 'author', 'allow_view_to', 'date_start', 'date_end'),
  44. ),
  45. 'account' => array(
  46. 'type' => 'INNER',
  47. 'table' => 'sys_accounts',
  48. 'mainField' => 'account_id',
  49. 'onField' => 'id',
  50. 'joinFields' => array(),
  51. ),
  52. ),
  53. 'paginate' => array('perPage' => getParam('bx_events_per_page_browse'), 'start' => 0),
  54. 'sorting' => 'last',
  55. 'rss' => array(
  56. 'title' => '',
  57. 'link' => '',
  58. 'image' => '',
  59. 'profile' => 0,
  60. 'fields' => array (
  61. 'Guid' => 'link',
  62. 'Link' => 'link',
  63. 'Title' => 'event_name',
  64. 'DateTimeUTS' => 'added',
  65. 'Desc' => 'event_name',
  66. 'Image' => 'picture',
  67. ),
  68. ),
  69. 'ident' => 'id'
  70. );
  71. $this->sFilterName = 'bx_events_data_filter';
  72. $this->oModule = $this->getMain();
  73. $CNF = &$this->oModule->_oConfig->CNF;
  74. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  75. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  76. $oJoinedProfile = null;
  77. $bProcessConditionsForPrivateContent = true;
  78. switch ($sMode) {
  79. case 'created_entries':
  80. if(!$this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile)) {
  81. $this->isError = true;
  82. break;
  83. }
  84. break;
  85. case 'context':
  86. $oProfileAuthor = null;
  87. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor))
  88. $this->isError = true;
  89. break;
  90. case 'joined_entries':
  91. $oJoinedProfile = BxDolProfile::getInstance((int)$aParams['joined_profile']);
  92. if (!$oJoinedProfile) {
  93. $this->isError = true;
  94. break;
  95. }
  96. $bProcessConditionsForPrivateContent = false;
  97. $this->aCurrent['join']['fans'] = array(
  98. 'type' => 'INNER',
  99. 'table' => 'bx_events_fans',
  100. 'mainField' => 'id',
  101. 'onField' => 'content',
  102. 'joinFields' => array('initiator'),
  103. );
  104. $this->aCurrent['restriction']['fans'] = array('value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'bx_events_fans');
  105. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  106. $this->aCurrent['title'] = _t('_bx_events_page_title_joined_entries');
  107. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode . '/' . $oJoinedProfile->id();
  108. break;
  109. case 'connections':
  110. if ($this->_setConnectionsConditions($aParams)) {
  111. $bProcessConditionsForPrivateContent = false;
  112. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  113. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  114. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  115. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  116. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  117. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections', $oProfile->getDisplayName());
  118. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  119. }
  120. break;
  121. case 'favorite':
  122. if(!$this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile)) {
  123. $this->isError = true;
  124. break;
  125. }
  126. break;
  127. case 'recent':
  128. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  129. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_recent');
  130. $this->aCurrent['sorting'] = 'last';
  131. $this->sBrowseUrl = 'page.php?i=events-home';
  132. break;
  133. case 'featured':
  134. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  135. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_featured');
  136. $this->aCurrent['restriction']['featured']['value'] = '0';
  137. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  138. $this->aCurrent['sorting'] = 'featured';
  139. break;
  140. case 'recommended':
  141. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  142. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_recommended');
  143. $this->aCurrent['restriction']['featured']['value'] = '0';
  144. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  145. $this->aCurrent['sorting'] = 'recommended';
  146. $this->_setConditionsForRecommended();
  147. break;
  148. case 'top':
  149. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  150. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_top');
  151. $this->aCurrent['sorting'] = 'top';
  152. $this->sBrowseUrl = 'page.php?i=events-top';
  153. break;
  154. case 'upcoming':
  155. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  156. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_upcoming');
  157. $this->aCurrent['restriction']['upcoming']['value'] = time();
  158. if(!empty($aParams['date_start_from']))
  159. $this->aCurrent['restriction']['date_start_from']['value'] = $aParams['date_start_from'];
  160. if(!empty($aParams['date_start_to']))
  161. $this->aCurrent['restriction']['date_start_to']['value'] = $aParams['date_start_to'];
  162. $this->aCurrent['sorting'] = 'upcoming';
  163. if(!empty($aParams['per_page']))
  164. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  165. $this->sBrowseUrl = 'page.php?i=events-upcoming';
  166. break;
  167. case 'upcoming_connected':
  168. if(!$this->_setConnectionsConditions($aParams))
  169. break;
  170. $bProcessConditionsForPrivateContent = false;
  171. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/upcoming';
  172. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_upcoming');
  173. $this->aCurrent['restriction']['upcoming']['value'] = time();
  174. if(!empty($aParams['date_start_from']))
  175. $this->aCurrent['restriction']['date_start_from']['value'] = $aParams['date_start_from'];
  176. if(!empty($aParams['date_start_to']))
  177. $this->aCurrent['restriction']['date_start_to']['value'] = $aParams['date_start_to'];
  178. $this->aCurrent['sorting'] = 'upcoming';
  179. if(!empty($aParams['per_page']))
  180. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  181. $this->sBrowseUrl = 'page.php?i=events-upcoming';
  182. break;
  183. case 'past':
  184. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  185. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_past');
  186. $this->aCurrent['restriction']['past']['value'] = time();
  187. $this->aCurrent['sorting'] = 'past';
  188. $this->sBrowseUrl = 'page.php?i=events-past';
  189. break;
  190. case '': // search results
  191. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  192. $this->aCurrent['title'] = _t('_bx_events');
  193. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  194. break;
  195. default:
  196. $this->isError = true;
  197. }
  198. if ($bProcessConditionsForPrivateContent)
  199. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  200. $this->sCenterContentUnitSelector = false;
  201. }
  202. function getAlterOrder()
  203. {
  204. switch ($this->aCurrent['sorting']) {
  205. case 'featured':
  206. return array('order' => ' ORDER BY `bx_events_data`.`featured` DESC ');
  207. case 'recommended':
  208. return array('order' => ' ORDER BY RAND() ');
  209. case 'none':
  210. return array();
  211. case 'top':
  212. return array('order' => ' ORDER BY `bx_events_data`.`views` DESC ');
  213. case 'upcoming':
  214. return array('order' => ' ORDER BY `bx_events_data`.`date_start` ASC, `bx_events_data`.`date_end` ASC ');
  215. case 'past':
  216. return array('order' => ' ORDER BY `bx_events_data`.`date_start` DESC, `bx_events_data`.`date_end` DESC ');
  217. case 'last':
  218. default:
  219. return array('order' => ' ORDER BY `bx_events_data`.`added` DESC ');
  220. }
  221. }
  222. function _getPseud ()
  223. {
  224. return array(
  225. 'id' => 'id',
  226. 'event_name' => 'event_name',
  227. 'added' => 'added',
  228. 'author' => 'author',
  229. 'picture' => 'picture',
  230. );
  231. }
  232. }
  233. /** @} */