/** * 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); }
/** * 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); }
/** * 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); }