示例#1
0
 /**
  * Get the kolab_calendar instance for the given calendar ID
  *
  * @param string Calendar identifier (encoded imap folder name)
  * @return object kolab_calendar Object nor null if calendar doesn't exist
  */
 public function get_calendar($id)
 {
     // create calendar object if necesary
     if (!$this->calendars[$id] && in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
         $this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal);
     } else {
         if (!$this->calendars[$id] && $id !== self::BIRTHDAY_CALENDAR_ID) {
             $calendar = kolab_calendar::factory($id, $this->cal);
             if ($calendar->ready) {
                 $this->calendars[$calendar->id] = $calendar;
             }
         }
     }
     return $this->calendars[$id];
 }
 /**
  * @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 Date range start (unix timestamp)
  * @param  integer Date range end (unix timestamp)
  * @return integer Count
  */
 public function count_events($start, $end = null)
 {
     // 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 counts from all calendar folders
     $count = 0;
     foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
         $cal = new kolab_calendar($foldername, $this->cal);
         if ($cal->get_namespace() == 'other') {
             continue;
         }
         $count += $cal->count_events($start, $end, array(array($subquery, 'OR')));
     }
     return $count;
 }