/** * Format datetime to UNIX timestamp for storage. * * @param Ai1ec_Date_Time $end Datetime object to compact. * * @return int UNIX timestamp. */ protected function _handle_property_destruct_end(Ai1ec_Date_Time $end) { return $end->format_to_gmt(); }
/** * Return events falling within some time range. * * Return all events starting after the given start time and before the * given end time that the currently logged in user has permission to view. * If $spanning is true, then also include events that span this * period. All-day events are returned first. * * @param Ai1ec_Date_Time $start Limit to events starting after this. * @param Ai1ec_Date_Time $end Limit to events starting before this. * @param array $filter Array of filters for the events returned: * ['cat_ids'] => list of category IDs; * ['tag_ids'] => list of tag IDs; * ['post_ids'] => list of post IDs; * ['auth_ids'] => list of author IDs. * @param bool $spanning Also include events that span this period. * * @return array List of matching event objects. */ public function get_events_between(Ai1ec_Date_Time $start, Ai1ec_Date_Time $end, array $filter = array(), $spanning = false) { // Query arguments $args = array($start->format_to_gmt(), $end->format_to_gmt()); // Get post status Where snippet and associated SQL arguments $where_parameters = $this->_get_post_status_sql(); $post_status_where = $where_parameters['post_status_where']; $args = array_merge($args, $where_parameters['args']); // Get the Join (filter_join) and Where (filter_where) statements based // on $filter elements specified $filter = $this->_get_filter_sql($filter); $ai1ec_localization_helper = $this->_registry->get('p28n.wpml'); $wpml_join_particle = $ai1ec_localization_helper->get_wpml_table_join('p.ID'); $wpml_where_particle = $ai1ec_localization_helper->get_wpml_table_where(); if ($spanning) { $spanning_string = 'i.end > %d AND i.start < %d '; } else { $spanning_string = 'i.start BETWEEN %d AND %d '; } $sql = ' SELECT `p`.*, `e`.`post_id`, `i`.`id` AS `instance_id`, `i`.`start` AS `start`, `i`.`end` AS `end`, `e`.`timezone_name` AS `timezone_name`, `e`.`allday` AS `event_allday`, `e`.`recurrence_rules`, `e`.`exception_rules`, `e`.`recurrence_dates`, `e`.`exception_dates`, `e`.`venue`, `e`.`country`, `e`.`address`, `e`.`city`, `e`.`province`, `e`.`postal_code`, `e`.`instant_event`, `e`.`show_map`, `e`.`contact_name`, `e`.`contact_phone`, `e`.`contact_email`, `e`.`contact_url`, `e`.`cost`, `e`.`ticket_url`, `e`.`ical_feed_url`, `e`.`ical_source_url`, `e`.`ical_organizer`, `e`.`ical_contact`, `e`.`ical_uid` FROM ' . $this->_dbi->get_table_name('ai1ec_events') . ' e INNER JOIN ' . $this->_dbi->get_table_name('posts') . ' p ON ( `p`.`ID` = `e`.`post_id` ) ' . $wpml_join_particle . ' INNER JOIN ' . $this->_dbi->get_table_name('ai1ec_event_instances') . ' i ON ( `e`.`post_id` = `i`.`post_id` ) ' . $filter['filter_join'] . ' WHERE post_type = \'' . AI1EC_POST_TYPE . '\' ' . $wpml_where_particle . ' AND ' . $spanning_string . ' ' . $filter['filter_where'] . ' ' . $post_status_where . ' GROUP BY `i`.`id` ORDER BY `e` . `allday` DESC, `i` . `start` ASC, `p` . `post_title` ASC'; $query = $this->_dbi->prepare($sql, $args); $events = $this->_dbi->get_results($query, ARRAY_A); $id_list = array(); foreach ($events as $event) { $id_list[] = $event['post_id']; } if (!empty($id_list)) { update_meta_cache('post', $id_list); } foreach ($events as &$event) { $event['allday'] = $this->_is_all_day($event); $event = $this->_registry->get('model.event', $event); } return $events; }
/** * Returns an associative array of two links for any agenda-like view of the * calendar: * previous page (if previous events exist), * next page (if next events exist). * Each element is an associative array containing the link's enabled status * ['enabled'], CSS class ['class'], text ['text'] and value to assign to * link's href ['href']. * * @param array $args Current request arguments * * @param bool $prev Whether there are more events before * the current page * @param bool $next Whether there are more events after * the current page * @param Ai1ec_Date_Time|null $date_first * @param Ai1ec_Date_Time|null $date_last * @param string $title Title to display in datepicker button * @param string $title_short Short month names. * @param int|null $default_time_limit The default time limit in the case of pagination ends. * @return array Array of links */ protected function _get_pagination_links($args, $prev = false, $next = false, $date_first = null, $date_last = null, $title = '', $title_short = '', $prev_offset = -1, $next_offset = 1) { $links = array(); if ($this->_registry->get('model.settings')->get('ai1ec_use_frontend_rendering')) { $args['request_format'] = 'json'; } $args['page_offset'] = $prev_offset; $href = $this->_registry->get('html.element.href', $args); $links[] = array('class' => 'ai1ec-prev-page', 'text' => '<i class="ai1ec-fa ai1ec-fa-chevron-left"></i>', 'href' => $href->generate_href(), 'enabled' => $prev); // Minical datepicker. $factory = $this->_registry->get('factory.html'); $links[] = $factory->create_datepicker_link($args, $date_first->format_to_gmt(), $title, $title_short); $args['page_offset'] = $next_offset; $href = $this->_registry->get('html.element.href', $args); $links[] = array('class' => 'ai1ec-next-page', 'text' => '<i class="ai1ec-fa ai1ec-fa-chevron-right"></i>', 'href' => $href->generate_href(), 'enabled' => $next); return $links; }