Kronolith::search PHP Метод

    public static function search($query, $calendar = null)
    {
        if ($calendar) {
            $driver = explode('|', $calendar, 2);
            $calendars = array($driver[0] => array($driver[1]));
        } elseif (!empty($query->calendars)) {
            $calendars = $query->calendars;
        } else {
            $calendars = array(Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS), 'Horde' => $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS), 'Ical' => $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_REMOTE_CALENDARS), 'Holidays' => $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_HOLIDAYS));
        }
        $events = array();
        foreach ($calendars as $type => $list) {
            if (!empty($list)) {
                $kronolith_driver = self::getDriver($type);
            }
            foreach ($list as $cal) {
                $kronolith_driver->open($cal);
                $retevents = $kronolith_driver->search($query);
                self::mergeEvents($events, $retevents);
            }
        }
        return $events;
    }

Usage Example

Пример #1
0
 /**
  * Purge old events.
  *
  * @throws Kronolith_Exception
  * @throws Horde_Exception_NotFound
  */
 public function execute()
 {
     /* Get the current time minus the number of days specified in
      * 'purge_events_keep'.  An event will be deleted if it has an end
      * time prior to this time. */
     $del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
     $del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
     /* Need to have Horde_Perms::DELETE on a calendar to delete events
      * from it */
     $calendars = Kronolith::listInternalCalendars(true, Horde_Perms::DELETE);
     /* Start building the search */
     $kronolith_driver = Kronolith::getDriver();
     $query = new StdClass();
     $query->start = null;
     $query->end = $del_time;
     $query->status = null;
     $query->calendars = array(Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => array_keys($calendars));
     $query->creator = $GLOBALS['registry']->getAuth();
     /* Perform the search */
     $days = Kronolith::search($query);
     $count = 0;
     foreach ($days as $events) {
         foreach ($events as $event) {
             /* Delete if no recurrence, or if we are past the last occurence */
             if (!$event->recurs() || $event->recurrence->nextRecurrence($del_time) == false) {
                 if ($event->calendar != $kronolith_driver->calendar) {
                     $kronolith_driver->open($event->calendar);
                 }
                 try {
                     $kronolith_driver->deleteEvent($event->id, true);
                     ++$count;
                 } catch (Exception $e) {
                     Horde::log($e, 'ERR');
                     throw $e;
                 }
             }
         }
     }
     $GLOBALS['notification']->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $GLOBALS['prefs']->getValue('purge_events_keep')));
 }
All Usage Examples Of Kronolith::search