示例#1
0
 /**
  * Get a list of available calendars from this source
  *
  * @param integer $filter Bitmask defining filter criterias
  * @param object $tree   Reference to hierarchical folder tree object
  *
  * @return array List of calendars
  */
 public function list_calendars($filter = 0, &$tree = null)
 {
     // attempt to create a default calendar for this user
     if (!$this->has_writeable) {
         if ($this->create_calendar(array('name' => 'Calendar', 'color' => 'cc0000'))) {
             unset($this->calendars);
             $this->_read_calendars();
         }
     }
     $delim = $this->rc->get_storage()->get_hierarchy_delimiter();
     $folders = $this->filter_calendars($filter);
     $calendars = array();
     // include virtual folders for a full folder tree
     if (!is_null($tree)) {
         $folders = kolab_storage::folder_hierarchy($folders, $tree);
     }
     foreach ($folders as $id => $cal) {
         $fullname = $cal->get_name();
         $listname = $cal->get_foldername();
         $imap_path = explode($delim, $cal->name);
         // find parent
         do {
             array_pop($imap_path);
             $parent_id = kolab_storage::folder_id(join($delim, $imap_path));
         } while (count($imap_path) > 1 && !$this->calendars[$parent_id]);
         // restore "real" parent ID
         if ($parent_id && !$this->calendars[$parent_id]) {
             $parent_id = kolab_storage::folder_id($cal->get_parent());
         }
         // turn a kolab_storage_folder object into a kolab_calendar
         if ($cal instanceof kolab_storage_folder) {
             $cal = new kolab_calendar($cal->name, $this->cal);
             $this->calendars[$cal->id] = $cal;
         }
         // special handling for user or virtual folders
         if ($cal instanceof kolab_storage_folder_user) {
             $calendars[$cal->id] = array('id' => $cal->id, 'name' => kolab_storage::object_name($fullname), 'listname' => $listname, 'editname' => $cal->get_foldername(), 'color' => $cal->get_color(), 'active' => $cal->is_active(), 'title' => $cal->get_owner(), 'owner' => $cal->get_owner(), 'history' => false, 'virtual' => false, 'editable' => false, 'group' => 'other', 'class' => 'user', 'removable' => true);
         } else {
             if ($cal->virtual) {
                 $calendars[$cal->id] = array('id' => $cal->id, 'name' => $fullname, 'listname' => $listname, 'editname' => $cal->get_foldername(), 'virtual' => true, 'editable' => false, 'group' => $cal->get_namespace(), 'class' => 'folder');
             } else {
                 $calendars[$cal->id] = array('id' => $cal->id, 'name' => $fullname, 'listname' => $listname, 'editname' => $cal->get_foldername(), 'title' => $cal->get_title(), 'color' => $cal->get_color(), 'editable' => $cal->editable, 'rights' => $cal->rights, 'showalarms' => $cal->alarms, 'history' => !empty($this->bonnie_api), 'group' => $cal->get_namespace(), 'default' => $cal->default, 'active' => $cal->is_active(), 'owner' => $cal->get_owner(), 'children' => true, 'parent' => $parent_id, 'subtype' => $cal->subtype, 'caldavurl' => $cal->get_caldav_url(), 'removable' => !$cal->default);
             }
         }
         if ($cal->subscriptions) {
             $calendars[$cal->id]['subscribed'] = $cal->is_subscribed();
         }
     }
     // list virtual calendars showing invitations
     if ($this->rc->config->get('kolab_invitation_calendars')) {
         foreach (array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED) as $id) {
             $cal = new kolab_invitation_calendar($id, $this->cal);
             $this->calendars[$cal->id] = $cal;
             if (!($filter & self::FILTER_ACTIVE) || $cal->is_active()) {
                 $calendars[$id] = array('id' => $cal->id, 'name' => $cal->get_name(), 'listname' => $cal->get_name(), 'editname' => $cal->get_foldername(), 'title' => $cal->get_title(), 'color' => $cal->get_color(), 'editable' => $cal->editable, 'rights' => $cal->rights, 'showalarms' => $cal->alarms, 'history' => !empty($this->bonnie_api), 'group' => 'x-invitations', 'default' => false, 'active' => $cal->is_active(), 'owner' => $cal->get_owner(), 'children' => false);
                 if ($id == self::INVITATIONS_CALENDAR_PENDING) {
                     $calendars[$id]['counts'] = true;
                 }
                 if (is_object($tree)) {
                     $tree->children[] = $cal;
                 }
             }
         }
     }
     // append the virtual birthdays calendar
     if ($this->rc->config->get('calendar_contact_birthdays', false)) {
         $id = self::BIRTHDAY_CALENDAR_ID;
         $prefs = $this->rc->config->get('kolab_calendars', array());
         // read local prefs
         if (!($filter & self::FILTER_ACTIVE) || $prefs[$id]['active']) {
             $calendars[$id] = array('id' => $id, 'name' => $this->cal->gettext('birthdays'), 'listname' => $this->cal->gettext('birthdays'), 'color' => $prefs[$id]['color'] ?: '87CEFA', 'active' => (bool) $prefs[$id]['active'], 'showalarms' => (bool) $this->rc->config->get('calendar_birthdays_alarm_type'), 'group' => 'x-birthdays', 'editable' => false, 'default' => false, 'children' => false, 'history' => false);
         }
     }
     return $calendars;
 }
 /**
  *
  * @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;
 }