BxEventsSearchResult.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. ),
  32. 'join' => array (
  33. 'profile' => array(
  34. 'type' => 'INNER',
  35. 'table' => 'bx_events_data',
  36. 'mainField' => 'content_id',
  37. 'onField' => 'id',
  38. 'joinFields' => array('id', 'event_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_events_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' => 'event_name',
  59. 'DateTimeUTS' => 'added',
  60. 'Desc' => 'event_name',
  61. 'Picture' => 'picture',
  62. ),
  63. ),
  64. 'ident' => 'id'
  65. );
  66. $this->sFilterName = 'bx_events_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 'joined_entries':
  74. $oJoinedProfile = BxDolProfile::getInstance((int)$aParams['joined_profile']);
  75. if (!$oJoinedProfile) {
  76. $this->isError = true;
  77. break;
  78. }
  79. $bProcessConditionsForPrivateContent = false;
  80. $this->aCurrent['join']['fans'] = array(
  81. 'type' => 'INNER',
  82. 'table' => 'bx_events_fans',
  83. 'mainField' => 'id',
  84. 'onField' => 'content',
  85. 'joinFields' => array('initiator'),
  86. );
  87. $this->aCurrent['restriction']['fans'] = array('value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'bx_events_fans');
  88. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  89. $this->aCurrent['title'] = _t('_bx_events_page_title_joined_entries');
  90. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode . '/' . $oJoinedProfile->id();
  91. break;
  92. case 'connections':
  93. if ($this->_setConnectionsConditions($aParams)) {
  94. $bProcessConditionsForPrivateContent = false;
  95. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  96. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  97. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  98. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  99. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  100. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections', $oProfile->getDisplayName());
  101. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  102. }
  103. break;
  104. case 'favorite':
  105. if(!$this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile)) {
  106. $this->isError = true;
  107. break;
  108. }
  109. break;
  110. case 'recent':
  111. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  112. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_recent');
  113. $this->aCurrent['sorting'] = 'last';
  114. $this->sBrowseUrl = 'page.php?i=events-home';
  115. break;
  116. case 'featured':
  117. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  118. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_featured');
  119. $this->aCurrent['restriction']['featured']['value'] = '0';
  120. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  121. $this->aCurrent['sorting'] = 'featured';
  122. break;
  123. case 'top':
  124. $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
  125. $this->aCurrent['title'] = _t('_bx_events_page_title_browse_top');
  126. $this->aCurrent['sorting'] = 'top';
  127. $this->sBrowseUrl = 'page.php?i=events-top';
  128. break;
  129. case '': // search results
  130. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  131. $this->aCurrent['title'] = _t('_bx_events');
  132. $this->aCurrent['paginate']['perPage'] = 5;
  133. unset($this->aCurrent['rss']);
  134. break;
  135. default:
  136. $this->isError = true;
  137. }
  138. if ($bProcessConditionsForPrivateContent)
  139. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  140. $this->sCenterContentUnitSelector = false;
  141. }
  142. protected function addConditionsForPrivateContent($CNF, $oJoinedProfile)
  143. {
  144. // add conditions for private content
  145. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  146. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oJoinedProfile ? $oJoinedProfile->id() : 0, $oPrivacy->getPartiallyVisiblePrivacyGroups()) : array();
  147. if (isset($a['restriction']))
  148. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  149. if (isset($a['join']))
  150. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  151. $this->setProcessPrivateContent(false);
  152. }
  153. function getAlterOrder()
  154. {
  155. switch ($this->aCurrent['sorting']) {
  156. case 'featured':
  157. return array('order' => ' ORDER BY `bx_events_data`.`featured` DESC ');
  158. case 'none':
  159. return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
  160. case 'top':
  161. return array('order' => ' ORDER BY `bx_events_data`.`views` DESC ');
  162. case 'last':
  163. default:
  164. return array('order' => ' ORDER BY `bx_events_data`.`added` DESC ');
  165. }
  166. }
  167. function _getPseud ()
  168. {
  169. return array(
  170. 'id' => 'id',
  171. 'event_name' => 'event_name',
  172. 'added' => 'added',
  173. 'author' => 'author',
  174. 'picture' => 'picture',
  175. );
  176. }
  177. }
  178. /** @} */