| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Events Events
- * @ingroup UnaModules
- *
- * @{
- */
- class BxEventsSearchResult extends BxBaseModGroupsSearchResult
- {
- function __construct($sMode = '', $aParams = false)
- {
- parent::__construct($sMode, $aParams);
- $this->aCurrent = array(
- 'name' => 'bx_events',
- 'module_name' => 'bx_events',
- 'object_metatags' => 'bx_events',
- 'title' => _t('_bx_events_page_title_browse'),
- 'table' => 'sys_profiles',
- 'tableSearch' => 'bx_events_data',
- 'ownFields' => array(),
- 'searchFields' => array(),
- 'restriction' => array(
- 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
- 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
- 'perofileType' => array('value' => 'bx_events', 'field' => 'type', 'operator' => '='),
- 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_events_data'),
- 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_events_data'),
- 'past' => array('value' => '', 'field' => 'date_end', 'operator' => '<', 'table' => 'bx_events_data'),
- 'date_start_from' => array('value' => '', 'field' => 'date_start', 'operator' => '>=', 'table' => 'bx_events_data'),
- 'date_start_to' => array('value' => '', 'field' => 'date_start', 'operator' => '<=', 'table' => 'bx_events_data'),
- 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_events_data'),
- 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '=', 'table' => 'bx_events_data'),
- ),
- 'join' => array (
- 'profile' => array(
- 'type' => 'INNER',
- 'table' => 'bx_events_data',
- 'mainField' => 'content_id',
- 'onField' => 'id',
- 'joinFields' => array('id', 'event_name', 'event_desc', 'picture', 'cover', 'cover_data', 'added', 'author', 'allow_view_to', 'date_start', 'date_end', 'threshold'),
- ),
- 'account' => array(
- 'type' => 'INNER',
- 'table' => 'sys_accounts',
- 'mainField' => 'account_id',
- 'onField' => 'id',
- 'joinFields' => array(),
- ),
- ),
- 'paginate' => array('perPage' => getParam('bx_events_per_page_browse'), 'start' => 0),
- 'sorting' => 'last',
- 'rss' => array(
- 'title' => '',
- 'link' => '',
- 'image' => '',
- 'profile' => 0,
- 'fields' => array (
- 'Guid' => 'link',
- 'Link' => 'link',
- 'Title' => 'event_name',
- 'DateTimeUTS' => 'added',
- 'Desc' => 'event_name',
- 'Image' => 'picture',
- ),
- ),
- 'ident' => 'id'
- );
- $this->sFilterName = 'bx_events_data_filter';
- $this->oModule = $this->getMain();
- $CNF = &$this->oModule->_oConfig->CNF;
- $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
- $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
- $oJoinedProfile = null;
- $bProcessConditionsForPrivateContent = true;
- if(isset($this->_aParams['by_location_country'], $this->_aParams['by_location_state'], $this->_aParams['by_location_city'])) {
- $aConditions = [];
- if(!empty($this->_aParams['by_location_country']))
- $aConditions['keyword'] = $this->_aParams['by_location_country'];
- if(!empty($this->_aParams['by_location_state']))
- $aConditions['state'] = $this->_aParams['by_location_state'];
- if(!empty($this->_aParams['by_location_city']))
- $aConditions['city'] = $this->_aParams['by_location_city'];
- if(!empty($aConditions)) {
- $this->setMetaType('location_country_city');
- $this->setCustomSearchCondition($aConditions);
- }
- }
- $iDateStart = $iDateEnd = 0;
- if(isset($this->_aParams['by_date'])) {
- $iTimezoneOffset = 0;
- if(!empty($this->_aParams['timezone']) && in_array($this->_aParams['timezone'], timezone_identifiers_list()))
- $iTimezoneOffset = date_offset_get(date_create('now', timezone_open($this->_aParams['timezone'])));
- switch($this->_aParams['by_date']) {
- case 'today':
- $iDateStart = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
- $iDateEnd = $iDateStart + 86399;
- break;
- case 'tomorrow':
- $iDateStart = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
- $iDateEnd = $iDateStart + 86399;
- break;
- case 'weekend':
- $iDayOfWeek = date("w");
- $iDateStart = mktime(0, 0, 0, date("m"), date("d") + ($iDayOfWeek > 0 ? 6 - $iDayOfWeek : -1), date("Y"));
- $iDateEnd = $iDateStart + 2 * 86400 - 1;
- break;
- case 'this_week':
- $iDayOfWeek = date("w");
- $iDateStart = mktime(0, 0, 0, date("m"), date("d") - ($iDayOfWeek > 0 ? $iDayOfWeek - 1 : 6), date("Y"));
- $iDateEnd = $iDateStart + 7 * 86400 - 1;
- break;
- case 'next_week':
- $iDayOfWeek = date("w");
- $iDateStart = mktime(0, 0, 0, date("m"), date("d") + ($iDayOfWeek > 0 ? 8 - $iDayOfWeek : 1), date("Y"));
- $iDateEnd = $iDateStart + 7 * 86400 - 1;
- break;
- case 'this_month':
- $iDateStart = mktime(0, 0, 0, date("m"), 1, date("Y"));
- $iDateEnd = mktime(23, 59, 59, date("m") + 1, 0, date("Y"));
- break;
- case 'date_range':
- if(!empty($this->_aParams['date_start'])) {
- list($iDsy, $iDsm, $iDsd,) = explode('-', $this->_aParams['date_start']);
- $iDateStart = mktime(0, 0, 0, $iDsm, $iDsd, $iDsy);
- }
- else
- $iDateStart = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
- if(!empty($this->_aParams['date_end'])) {
- list($iDey, $iDem, $iDed,) = explode('-', $this->_aParams['date_end']);
- $iDateEnd = mktime(23, 59, 59, $iDem, $iDed, $iDey);
- }
- else
- $iDateEnd = mktime(23, 59, 59, date("m"), date("d"), date("Y"));
- break;
- }
- if($iDateStart != 0 && $iDateEnd != 0) {
- $iDateStart -= $iTimezoneOffset;
- $iDateEnd -= $iTimezoneOffset;
- //--- 1. already started or will start in selected date interval
- $this->aCurrent['restriction']['filter_date_start'] = ['value' => $iDateEnd, 'field' => 'date_start', 'operator' => '<', 'table' => 'bx_events_data'];
- //--- 2. and didn't finished to the beginning of selected date interval
- $this->aCurrent['restriction']['filter_date_end'] = ['value' => $iDateStart, 'field' => 'date_end', 'operator' => '>', 'table' => 'bx_events_data'];
- }
- }
- switch ($sMode) {
- case 'created_entries':
- $this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile);
- break;
- case 'context':
- $oProfileAuthor = null;
- if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor))
- break;
- if(!$this->aCurrent['title'])
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_by_context');
- break;
- case 'joined_entries':
- $oJoinedProfile = null;
- if(!$this->_updateCurrentForJoinedEntries($sMode, $aParams, $oJoinedProfile))
- break;
- $bProcessConditionsForPrivateContent = false;
- if(!$this->aCurrent['title'])
- $this->aCurrent['title'] = _t('_bx_events_page_title_joined_entries');
- break;
- case 'followed_entries':
- $oJoinedProfile = null;
- if(!$this->_updateCurrentForFollowedEntries($sMode, $aParams, $oJoinedProfile))
- break;
- $bProcessConditionsForPrivateContent = false;
- if(!$this->aCurrent['title'])
- $this->aCurrent['title'] = _t('_bx_events_page_title_followed_entries');
- break;
- case 'connections':
- if ($this->_setConnectionsConditions($aParams)) {
- $bProcessConditionsForPrivateContent = false;
- $oProfile = BxDolProfile::getInstance($aParams['profile']);
- $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
- if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
- elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_connections', $oProfile->getDisplayName());
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
- }
- break;
- case 'favorite':
- $this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile);
- break;
- case 'recent':
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_recent');
- $this->aCurrent['sorting'] = 'last';
- $this->sBrowseUrl = 'page.php?i=events-home';
- break;
- case 'featured':
- $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_featured');
- $this->aCurrent['restriction']['featured']['value'] = '0';
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['sorting'] = 'featured';
- break;
- case 'recommended':
- $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_recommended');
- $this->aCurrent['restriction']['featured']['value'] = '0';
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['sorting'] = 'recommended';
- $this->_setConditionsForRecommended();
- break;
-
- case 'top':
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_top');
- $this->aCurrent['sorting'] = 'top';
- $this->sBrowseUrl = 'page.php?i=events-top';
- break;
- case 'upcoming':
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_upcoming');
- // $this->aCurrent['restriction_sql'] = BxDolDb::getInstance()->prepareAsString(" AND `date_max` IS NOT NULL AND (`date_max` = 0 OR `date_max` > ?) ", time());
- // TODO: remake to use date_max (commented line above) in the future
- $this->aCurrent['join']['intervals'] = array (
- 'type' => 'LEFT',
- 'table' => 'bx_events_intervals',
- 'table_alias' => 'ei',
- 'mainField' => 'id',
- 'mainTable' => 'bx_events_data',
- 'onField' => 'event_id',
- 'groupTable' => 'bx_events_data',
- 'groupField' => 'id',
- 'groupHaving' => BxDolDb::getInstance()->prepareAsString(" (`date_end` > ? OR MIN(`repeat_stop`) = 0 OR MAX(`repeat_stop`) > ?) ", time(), time()),
- 'joinFields' => ['MIN(`repeat_stop`) AS `repeat_min`, ', 'MAX(`repeat_stop`) AS `repeat_max`, '],
- );
- if(!empty($aParams['date_start_from']))
- $this->aCurrent['restriction']['date_start_from']['value'] = $aParams['date_start_from'];
- if(!empty($aParams['date_start_to']))
- $this->aCurrent['restriction']['date_start_to']['value'] = $aParams['date_start_to'];
- $this->aCurrent['sorting'] = 'upcoming';
- if(!empty($aParams['per_page']))
- $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
- $this->sBrowseUrl = 'page.php?i=events-upcoming';
- break;
- case 'upcoming_connected':
- if(!$this->_setConnectionsConditions($aParams))
- break;
- $bProcessConditionsForPrivateContent = false;
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/upcoming';
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_upcoming');
- // $this->aCurrent['restriction_sql'] = BxDolDb::getInstance()->prepareAsString(" AND `date_max` IS NOT NULL AND (`date_max` = 0 OR `date_max` > ?) ", time());
- // TODO: remake to use date_max (commented line above) in the future
- $this->aCurrent['join']['intervals'] = array (
- 'type' => 'LEFT',
- 'table' => 'bx_events_intervals',
- 'table_alias' => 'ei',
- 'mainField' => 'id',
- 'mainTable' => 'bx_events_data',
- 'onField' => 'event_id',
- 'groupTable' => 'bx_events_data',
- 'groupField' => 'id',
- 'groupHaving' => BxDolDb::getInstance()->prepareAsString(" (`date_end` > ? OR MIN(`repeat_stop`) = 0 OR MAX(`repeat_stop`) > ?) ", time(), time()),
- 'joinFields' => ['MIN(`repeat_stop`) AS `repeat_min`, ', 'MAX(`repeat_stop`) AS `repeat_max`, '],
- );
- if(!empty($aParams['date_start_from']))
- $this->aCurrent['restriction']['date_start_from']['value'] = $aParams['date_start_from'];
- if(!empty($aParams['date_start_to']))
- $this->aCurrent['restriction']['date_start_to']['value'] = $aParams['date_start_to'];
- $this->aCurrent['sorting'] = 'upcoming';
- if(!empty($aParams['per_page']))
- $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
- $this->sBrowseUrl = 'page.php?i=events-upcoming';
- break;
- case 'past':
- $this->aCurrent['rss']['link'] = 'modules/?r=events/rss/' . $sMode;
- $this->aCurrent['title'] = _t('_bx_events_page_title_browse_past');
- $this->aCurrent['restriction']['past']['value'] = time();
- $this->aCurrent['sorting'] = 'past';
- $this->sBrowseUrl = 'page.php?i=events-past';
- break;
- case '': // search results
- $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
- $this->aCurrent['title'] = _t('_bx_events');
- unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
- break;
- default:
- $this->isError = true;
- }
- if ($bProcessConditionsForPrivateContent) {
- $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
-
- $this->addCustomConditions($CNF, $oJoinedProfile, $sMode, $aParams);
- }
- $this->sCenterContentUnitSelector = false;
- }
- function getAlterOrder()
- {
- switch ($this->aCurrent['sorting']) {
- case 'featured':
- return array('order' => ' ORDER BY `bx_events_data`.`featured` DESC ');
- case 'recommended':
- return array('order' => ' ORDER BY RAND() ');
- case 'none':
- return array();
- case 'top':
- return array('order' => ' ORDER BY `bx_events_data`.`views` DESC ');
- case 'upcoming':
- return array('order' => ' ORDER BY `bx_events_data`.`date_start` ASC, `bx_events_data`.`date_end` ASC ');
- case 'past':
- return array('order' => ' ORDER BY `bx_events_data`.`date_start` DESC, `bx_events_data`.`date_end` DESC ');
- case 'last':
- default:
- return array('order' => ' ORDER BY `bx_events_data`.`added` DESC ');
- }
- }
- function _getPseud ()
- {
- return array(
- 'id' => 'id',
- 'event_name' => 'event_name',
- 'added' => 'added',
- 'author' => 'author',
- 'picture' => 'picture',
- );
- }
- function setFieldUnit ($sFieldName, $sTableName, $sOperator = '', $bRenameMode = true)
- {
- if (0 === mb_strpos($sFieldName, 'MIN') || 0 === mb_strpos($sFieldName, 'MAX'))
- return $sFieldName;
- return parent::setFieldUnit ($sFieldName, $sTableName, $sOperator, $bRenameMode);
- }
- }
- /** @} */
|