listAlarms() public static method

Returns all the alarms active on a specific date.
public static listAlarms ( Horde_Date $date, array $calendars, boolean $fullevent = false ) : array
$date Horde_Date The date to check for alarms.
$calendars array The calendars to check for events.
$fullevent boolean Whether to return complete alarm objects or only alarm IDs.
return array The alarms active on the date. A hash with calendar names as keys and arrays of events or event ids as values.
Esempio n. 1
0
 /**
  */
 public function listAlarms($time, $user = null)
 {
     $current_user = $GLOBALS['registry']->getAuth();
     if ((empty($user) || $user != $current_user) && !$GLOBALS['registry']->isAdmin()) {
         throw new Horde_Exception_PermissionDenied();
     }
     $group = $GLOBALS['injector']->getInstance('Horde_Group');
     $kronolith_shares = $GLOBALS['injector']->getInstance('Kronolith_Shares');
     $alarm_list = array();
     $time = new Horde_Date($time);
     $calendars = is_null($user) ? array_keys($kronolith_shares->listAllShares()) : $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS);
     $alarms = Kronolith::listAlarms($time, $calendars, true);
     foreach ($alarms as $calendar => $cal_alarms) {
         if (!$cal_alarms) {
             continue;
         }
         try {
             $share = $kronolith_shares->getShare($calendar);
         } catch (Exception $e) {
             continue;
         }
         if (empty($user)) {
             $users = $share->listUsers(Horde_Perms::READ);
             $groups = $share->listGroups(Horde_Perms::READ);
             foreach ($groups as $gid) {
                 try {
                     $users = array_merge($users, $group->listUsers($gid));
                 } catch (Horde_Group_Exception $e) {
                 }
             }
             $users = array_unique($users);
         } else {
             $users = array($user);
         }
         $owner = $share->get('owner');
         foreach ($cal_alarms as $event) {
             foreach ($users as $alarm_user) {
                 if ($alarm_user == $current_user) {
                     $prefs = $GLOBALS['prefs'];
                 } else {
                     $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('kronolith', array('cache' => false, 'user' => $alarm_user));
                 }
                 // Don't show alarms for private events if not the owner.
                 if ($event->isPrivate($alarm_user)) {
                     continue;
                 }
                 $shown_calendars = unserialize($prefs->getValue('display_cals'));
                 $reminder = $prefs->getValue('event_reminder');
                 if ($reminder == 'owner' && $alarm_user == $owner || $reminder == 'show' && in_array($calendar, $shown_calendars) || $reminder == 'read') {
                     $GLOBALS['registry']->setLanguageEnvironment($prefs->getValue('language'));
                     $alarm = $event->toAlarm($time, $alarm_user, $prefs);
                     if ($alarm) {
                         $alarm_list[] = $alarm;
                     }
                 }
             }
         }
     }
     return $alarm_list;
 }