Kronolith::displayedCalendars PHP Метод

displayedCalendars() публичный статический Метод

Returns a list of currently displayed calendars.
public static displayedCalendars ( ) : array
Результат array Currently displayed calendars.
    public static function displayedCalendars()
    {
        $calendars = array();
        foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $calendarId) {
            $calendars[] = $GLOBALS['calendar_manager']->getEntry(Kronolith::ALL_CALENDARS, $calendarId);
        }
        if (count($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS))) {
            $r_driver = self::getDriver('Resource');
            foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS) as $c) {
                try {
                    $resource = $r_driver->getResource($r_driver->getResourceIdByCalendar($c));
                    $calendars[] = new Kronolith_Calendar_Resource(array('resource' => $resource));
                } catch (Horde_Exception_NotFound $e) {
                }
            }
        }
        return $calendars;
    }

Usage Example

Пример #1
0
 /**
  * Adds additional items to the sidebar.
  *
  * This is for the traditional view. For the dynamic view, see
  * Kronolith_View_Sidebar.
  *
  * @param Horde_View_Sidebar $sidebar  The sidebar object.
  */
 public function sidebar($sidebar)
 {
     global $calendar_manager, $conf, $injector, $prefs, $registry, $session;
     $admin = $registry->isAdmin();
     $perms = $injector->getInstance('Horde_Core_Perms');
     if (Kronolith::getDefaultCalendar(Horde_Perms::EDIT) && ($perms->hasAppPermission('max_events') === true || $perms->hasAppPermission('max_events') > Kronolith::countEvents())) {
         $sidebar->addNewButton(_("_New Event"), Horde::url('new.php')->add('url', Horde::selfUrl(true, false, true)));
     }
     if (strlen($session->get('kronolith', 'display_cal'))) {
         $calendars = Kronolith::displayedCalendars();
         $sidebar->containers['calendars'] = array('header' => array('id' => 'kronolith-toggle-calendars', 'label' => ngettext("Showing calendar:", "Showing calendars:", count($calendars)), 'collapsed' => false));
         foreach ($calendars as $calendar) {
             $row = array('label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
             $sidebar->addRow($row, 'calendars');
         }
         return;
     }
     $user = $registry->getAuth();
     $url = Horde::selfUrl();
     $edit = Horde::url('calendars/edit.php');
     $sidebar->containers['my'] = array('header' => array('id' => 'kronolith-toggle-my', 'label' => _("My Calendars"), 'collapsed' => false));
     if (!$prefs->isLocked('default_share')) {
         $sidebar->containers['my']['header']['add'] = array('url' => Horde::url('calendars/create.php'), 'label' => _("Create a new Local Calendar"));
     }
     if ($admin) {
         $sidebar->containers['system'] = array('header' => array('id' => 'kronolith-toggle-system', 'label' => _("System Calendars"), 'collapsed' => true));
         $sidebar->containers['system']['header']['add'] = array('url' => Horde::url('calendars/create.php')->add('system', 1), 'label' => _("Create a new System Calendar"));
     }
     $sidebar->containers['shared'] = array('header' => array('id' => 'kronolith-toggle-shared', 'label' => _("Shared Calendars"), 'collapsed' => true));
     foreach (Kronolith::listInternalCalendars() as $id => $calendar) {
         $owner = $calendar->get('owner');
         if ($admin && empty($owner)) {
             continue;
         }
         $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', $id), 'label' => Kronolith::getLabel($calendar), 'color' => Kronolith::backgroundColor($calendar), 'edit' => $edit->add('c', $calendar->getName()), 'type' => 'checkbox');
         if ($calendar->get('owner') && $calendar->get('owner') == $user) {
             $sidebar->addRow($row, 'my');
         } else {
             $sidebar->addRow($row, 'shared');
         }
     }
     if ($admin) {
         foreach ($injector->getInstance('Kronolith_Shares')->listSystemShares() as $id => $calendar) {
             $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', $id), 'label' => $calendar->get('name'), 'color' => Kronolith::backgroundColor($calendar), 'edit' => $edit->add('c', $calendar->getName()), 'type' => 'checkbox');
             $sidebar->addRow($row, 'system');
         }
     }
     if (!empty($conf['resources']['enabled']) && ($admin || $perms->hasAppPermission('resource_management'))) {
         $sidebar->containers['groups'] = array('header' => array('id' => 'kronolith-toggle-groups', 'label' => _("Resource Groups"), 'collapsed' => true, 'add' => array('url' => Horde::url('resources/groups/create.php'), 'label' => _("Create a new Resource Group"))));
         $editGroups = Horde::url('resources/groups/edit.php');
         $sidebar->containers['resources'] = array('header' => array('id' => 'kronolith-toggle-resources', 'label' => _("Resources"), 'collapsed' => true, 'add' => array('url' => Horde::url('resources/create.php'), 'label' => _("Create a new Resource"))));
         $edit = Horde::url('resources/edit.php');
         foreach (Kronolith::getDriver('Resource')->listResources() as $resource) {
             if ($resource->get('isgroup')) {
                 $row = array('label' => $resource->get('name'), 'color' => '#dddddd', 'edit' => $editGroups->add('c', $resource->getId()), 'type' => 'radiobox');
                 $sidebar->addRow($row, 'groups');
             } else {
                 $calendar = new Kronolith_Calendar_Resource(array('resource' => $resource));
                 $row = array('selected' => in_array($resource->get('calendar'), $calendar_manager->get(Kronolith::DISPLAY_RESOURCE_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'resource_' . $resource->get('calendar')), 'label' => $calendar->name(), 'color' => $calendar->background(), 'edit' => $edit->add('c', $resource->getId()), 'type' => 'checkbox');
                 $sidebar->addRow($row, 'resources');
             }
         }
     }
     foreach ($calendar_manager->get(Kronolith::ALL_EXTERNAL_CALENDARS) as $id => $calendar) {
         if (!$calendar->display()) {
             continue;
         }
         $app = $registry->get('name', $registry->hasInterface($calendar->api()));
         if (!strlen($app)) {
             $app = _("Other events");
         }
         $container = 'external_' . $app;
         if (!isset($sidebar->containers[$container])) {
             $sidebar->containers[$container] = array('header' => array('id' => 'kronolith-toggle-external-' . $calendar->api(), 'label' => $app, 'collapsed' => true));
         }
         $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'external_' . $id), 'label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
         $sidebar->addRow($row, $container);
     }
     $sidebar->containers['remote'] = array('header' => array('id' => 'kronolith-toggle-remote', 'label' => _("Remote Calendars"), 'collapsed' => true, 'add' => array('url' => Horde::url('calendars/remote_subscribe.php'), 'label' => _("Subscribe to a Remote Calendar"))));
     $edit = Horde::url('calendars/remote_edit.php');
     foreach ($calendar_manager->get(Kronolith::ALL_REMOTE_CALENDARS) as $calendar) {
         $row = array('selected' => in_array($calendar->url(), $calendar_manager->get(Kronolith::DISPLAY_REMOTE_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'remote_' . $calendar->url()), 'label' => $calendar->name(), 'color' => $calendar->background(), 'edit' => $edit->add('url', $calendar->url()), 'type' => 'checkbox');
         $sidebar->addRow($row, 'remote');
     }
     if (!empty($conf['holidays']['enable'])) {
         $sidebar->containers['holidays'] = array('header' => array('id' => 'kronolith-toggle-holidays', 'label' => _("Holidays"), 'collapsed' => true));
         foreach ($calendar_manager->get(Kronolith::ALL_HOLIDAYS) as $id => $calendar) {
             $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_HOLIDAYS)), 'url' => $url->copy()->add('toggle_calendar', 'holiday_' . $id), 'label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
             $sidebar->addRow($row, 'holidays');
         }
     }
 }