Kronolith::listInternalCalendars PHP Method

listInternalCalendars() public static method

This method takes the $conf['share']['hidden'] setting into account. If this setting is enabled, even if requesting permissions different than SHOW, it will only return calendars that the user owns or has SHOW permissions for. For checking individual calendar's permissions, use hasPermission() instead.
public static listInternalCalendars ( boolean $owneronly = false, integer $permission = Horde_Perms::SHOW, string $user = null ) : array
$owneronly boolean Only return calenders that this user owns? Defaults to false.
$permission integer The permission to filter calendars by.
$user string The user to list calendars for, if not the current.
return array The calendar list.
    public static function listInternalCalendars($owneronly = false, $permission = Horde_Perms::SHOW, $user = null)
    {
        if ($owneronly && !$GLOBALS['registry']->getAuth()) {
            return array();
        }
        if (empty($user)) {
            $user = $GLOBALS['registry']->getAuth();
        }
        $kronolith_shares = $GLOBALS['injector']->getInstance('Kronolith_Shares');
        if ($owneronly || empty($GLOBALS['conf']['share']['hidden'])) {
            try {
                $calendars = $kronolith_shares->listShares($user, array('perm' => $permission, 'attributes' => $owneronly ? $user : null, 'sort_by' => 'name'));
            } catch (Horde_Share_Exception $e) {
                Horde::log($e);
                return array();
            }
        } else {
            try {
                $calendars = $kronolith_shares->listShares($GLOBALS['registry']->getAuth(), array('perm' => $permission, 'attributes' => $user, 'sort_by' => 'name'));
            } catch (Horde_Share_Exception $e) {
                Horde::log($e);
                return array();
            }
            $display_calendars = @unserialize($GLOBALS['prefs']->getValue('display_cals'));
            if (is_array($display_calendars)) {
                foreach ($display_calendars as $id) {
                    try {
                        $calendar = $kronolith_shares->getShare($id);
                        if ($calendar->hasPermission($user, $permission)) {
                            $calendars[$id] = $calendar;
                        }
                    } catch (Horde_Exception_NotFound $e) {
                    } catch (Horde_Share_Exception $e) {
                        Horde::log($e);
                        return array();
                    }
                }
            }
        }
        $default_share = $GLOBALS['prefs']->getValue('default_share');
        if (isset($calendars[$default_share])) {
            $calendar = $calendars[$default_share];
            unset($calendars[$default_share]);
            if (!$owneronly || $owneronly && $calendar->get('owner') == $GLOBALS['registry']->getAuth()) {
                $calendars = array($default_share => $calendar) + $calendars;
            }
        }
        return $calendars;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  *
  * @param Horde_Date $date  The day for this view
  * @param array $events     An array of Kronolith_Event objects
  *
  * @return Kronolith_View_Day
  */
 public function __construct(Horde_Date $date, array $events = null)
 {
     parent::__construct($date->month, $date->mday, $date->year);
     $this->sidebyside = $GLOBALS['prefs']->getValue('show_shared_side_by_side');
     if ($this->sidebyside) {
         $allCalendars = Kronolith::listInternalCalendars();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $cid) {
             $this->_currentCalendars[$cid] = $allCalendars[$cid];
             $this->all_day_events[$cid] = array();
         }
     } else {
         $this->_currentCalendars = array(0);
     }
     if ($events === null) {
         try {
             $events = Kronolith::listEvents($this, new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->mday)));
             $this->events = array_shift($events);
         } catch (Exception $e) {
             $GLOBALS['notification']->push($e, 'horde.error');
             $this->events = array();
         }
     } else {
         $this->events = $events;
     }
     if (!is_array($this->events)) {
         $this->events = array();
     }
 }
All Usage Examples Of Kronolith::listInternalCalendars