示例#1
0
 /**
  * Format a short-form time for use in compressed (e.g. month) views.
  *
  * @param Ai1ec_Date_Time $time   Object to format.
  *
  * @return string Formatted date time [default: `g:i a`].
  */
 public function get_short_time(Ai1ec_Date_Time $time)
 {
     $time_format = $this->_registry->get('model.option')->get('time_format', 'g:i a');
     return $time->format_i18n($time_format);
 }
 /**
  * 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();
 }
示例#3
0
    /**
     * 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;
    }
示例#4
0
 /**
  * add_exception_date method
  *
  * Add exception (date) to event.
  *
  * @param int   $post_id Event edited post ID
  * @param mixed $date    Parseable date representation to exclude
  *
  * @return bool Success
  */
 public function add_exception_date($post_id, Ai1ec_Date_Time $date)
 {
     $event = $this->_registry->get('model.event', $post_id);
     $dates_list = explode(',', $event->get('exception_dates'));
     if (empty($dates_list[0])) {
         unset($dates_list[0]);
     }
     $date->set_time(0, 0, 0);
     $dates_list[] = $date->format('Ymd\\THis\\Z');
     $event->set('exception_dates', implode(',', $dates_list));
     return $event->save(true);
 }
 /**
  * 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_agenda_like_pagination_links($args, $prev = false, $next = false, $date_first = null, $date_last = null, $title = '', $title_short = '', $default_time_limit = 0)
 {
     $links = array();
     if ($this->_registry->get('model.settings')->get('ai1ec_use_frontend_rendering')) {
         $args['request_format'] = 'json';
     }
     $args['page_offset'] = -1;
     if (null === $date_first || $date_first->is_empty()) {
         $args['time_limit'] = $default_time_limit;
     } else {
         $args['time_limit'] = $this->_registry->get('date.time', $date_first)->set_time($date_first->format('H'), $date_first->format('i'), $date_first->format('s') - 1)->format_to_gmt();
     }
     $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'] = 1;
     if (null === $date_last || $date_last->is_empty()) {
         $args['time_limit'] = $default_time_limit;
     } else {
         $args['time_limit'] = $this->_registry->get('date.time', $date_last)->set_time($date_last->format('H'), $date_last->format('i'), $date_last->format('s') + 1)->format_to_gmt();
     }
     $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;
 }
 /**
  * get_events_for_month function
  *
  * Return an array of all dates for the given month as an associative
  * array, with each element's value being another array of event objects
  * representing the events occuring on that date.
  *
  * @param int $time         the UNIX timestamp of a date within the desired month
  * @param array $filter     Array of filters for the events returned:
  *                          ['cat_ids']   => non-associatative array of category IDs
  *                          ['tag_ids']   => non-associatative array of tag IDs
  *                          ['post_ids']  => non-associatative array of post IDs
  *                          ['auth_ids']  => non-associatative array of author IDs
  *
  * @return array            array of arrays as per function's description
  */
 protected function get_events_for_month(Ai1ec_Date_Time $time, $filter = array())
 {
     $last_day = $time->format('t');
     $day_entry = array('multi' => array(), 'allday' => array(), 'other' => array());
     $days_events = array_fill(1, $last_day, $day_entry);
     unset($day_entry);
     $start_time = clone $time;
     $start_time->set_date($time->format('Y'), $time->format('m'), 1)->set_time(0, 0, 0);
     $end_time = clone $start_time;
     $end_time->adjust_month(1);
     $search = $this->_registry->get('model.search');
     $month_events = $search->get_events_between($start_time, $end_time, $filter, true);
     $start_time = $start_time->format();
     $end_time = $end_time->format();
     $this->_update_meta($month_events);
     $this->_registry->get('controller.content-filter')->clear_the_content_filters();
     foreach ($month_events as $event) {
         $event_start = $event->get('start')->format();
         $event_end = $event->get('end')->format();
         /**
          * REASONING: we assume, that event spans multiple periods, one of
          * which happens to be current (month). Thus we mark, that current
          * event starts at the very first day of current month and further
          * we will mark it as having truncated beginning (unless it is not
          * overlapping period boundaries).
          * Although, if event starts after the first second of this period
          * it's start day will be decoded as time 'j' format (`int`-casted
          * to increase map access time), of it's actual start time.
          */
         $day = 1;
         if ($event_start > $start_time) {
             $day = (int) $event->get('start')->format('j');
         }
         // Set multiday properties. TODO: Should these be made event object
         // properties? They probably shouldn't be saved to the DB, so I'm
         // not sure. Just creating properties dynamically for now.
         if ($event_start < $start_time) {
             $event->set('start_truncated', true);
         }
         if ($event_end >= $end_time) {
             $event->set('end_truncated', true);
         }
         // Categorize event.
         $priority = 'other';
         if ($event->is_allday()) {
             $priority = 'allday';
         } elseif ($event->is_multiday()) {
             $priority = 'multi';
         }
         $this->_add_runtime_properties($event);
         $days_events[$day][$priority][] = $event;
     }
     $this->_registry->get('controller.content-filter')->restore_the_content_filters();
     for ($day = 1; $day <= $last_day; $day++) {
         $days_events[$day] = array_merge($days_events[$day]['multi'], $days_events[$day]['allday'], $days_events[$day]['other']);
     }
     return apply_filters('ai1ec_get_events_for_month', $days_events, $time, $filter);
 }
示例#7
0
 /**
  * Similar to {@see format_date_for_url} just using new DateTime interface.
  *
  * @param Ai1ec_Date_Time $datetime Instance of datetime to format.
  * @param string          $pattern  Target format to use.
  *
  * @return string Formatted datetime string.
  */
 public function format_datetime_for_url(Ai1ec_Date_Time $datetime, $pattern = 'def')
 {
     $date = $datetime->format($this->get_date_format_patter($pattern));
     return str_replace('/', '-', $date);
 }
示例#8
0
 /**
  * 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;
 }