/** * @param integer Event's new start (unix timestamp) * @param integer Event's new end (unix timestamp) * @param string Search query (optional) * @param boolean Include virtual events (optional) * @param array Additional parameters to query storage * @return array A list of event records */ public function list_events($start, $end, $search = null, $virtual = 1, $query = array()) { // convert to DateTime for comparisons try { $start_dt = new DateTime('@' . $start); } catch (Exception $e) { $start_dt = new DateTime('@0'); } try { $end_dt = new DateTime('@' . $end); } catch (Exception $e) { $end_dt = new DateTime('today +10 years'); } $limit_changed = null; if (!empty($query)) { foreach ($query as $q) { if ($q[0] == 'changed' && $q[1] == '>=') { try { $limit_changed = new DateTime('@' . $q[2]); } catch (Exception $e) { /* ignore */ } } } } // aggregate all calendar folders the user shares (but are not subscribed) foreach (kolab_storage::list_user_folders($this->userdata, 'event', false) as $foldername) { $cal = new kolab_calendar($foldername, $this->cal); foreach ($cal->list_events($start, $end, $search, 1) as $event) { $this->events[$event['id']] = $event; $this->timeindex[$this->time_key($event)] = $event['id']; } } // get events from the user's free/busy feed (for quickview only) $fbview = $this->cal->rc->config->get('calendar_include_freebusy_data', 1); if ($fbview && ($fbview == 1 || !empty($_REQUEST['_quickview'])) && empty($search)) { $this->fetch_freebusy($limit_changed); } $events = array(); foreach ($this->events as $event) { // list events in requested time window if ($event['start'] <= $end_dt && $event['end'] >= $start_dt && (!$limit_changed || !$event['changed'] || $event['changed'] >= $limit_changed)) { $events[] = $event; } } // avoid session race conditions that will loose temporary subscriptions $this->cal->rc->session->nowrite = true; return $events; }
/** * @param integer Event's new start (unix timestamp) * @param integer Event's new end (unix timestamp) * @param string Search query (optional) * @param boolean Include virtual events (optional) * @param array Additional parameters to query storage * @return array A list of event records */ public function list_events($start, $end, $search = null, $virtual = 1, $query = array()) { // get email addresses of the current user $user_emails = $this->cal->get_user_emails(); $subquery = array(); foreach ($user_emails as $email) { foreach ($this->partstats as $partstat) { $subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)); } } // aggregate events from all calendar folders $events = array(); foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { $cal = new kolab_calendar($foldername, $this->cal); if ($cal->get_namespace() == 'other') { continue; } foreach ($cal->list_events($start, $end, $search, 1, $query, array(array($subquery, 'OR'))) as $event) { $match = false; // post-filter events to match out partstats if (is_array($event['attendees'])) { foreach ($event['attendees'] as $attendee) { if (in_array($attendee['email'], $user_emails) && in_array($attendee['status'], $this->partstats)) { $match = true; break; } } } if ($match) { $events[$event['id']] = $this->_mod_event($event); } } // merge list of event categories (really?) $this->categories += $cal->categories; } return $events; }