listAlarms() public static method

Returns all the alarms active right on $date.
public static listAlarms ( integer $date, array $tasklists = null ) : array
$date integer The unix epoch time to check for alarms.
$tasklists array An array of tasklists
return array An array of Nag_Task objects with alarms active on $date.
Esempio n. 1
0
 /**
  */
 protected function _content()
 {
     global $conf, $prefs, $registry;
     $html = '';
     if (!empty($this->_params['show_alarms'])) {
         $messages = array();
         try {
             $alarmList = Nag::listAlarms($_SERVER['REQUEST_TIME']);
         } catch (Nag_Exception $e) {
             return '<em>' . htmlspecialchars($e->getMessage()) . '</em>';
         }
         foreach ($alarmList as $task) {
             $differential = $task->getNextDue()->timestamp() - $_SERVER['REQUEST_TIME'];
             $key = $differential;
             while (isset($messages[$key])) {
                 $key++;
             }
             $viewurl = Horde::url('view.php', true)->add(array('task' => $task->id, 'tasklist' => $task->tasklist));
             $link = $viewurl->link() . (!empty($task->name) ? htmlspecialchars($task->name) : _("[none]")) . '</a>';
             if ($differential >= -60 && $differential < 60) {
                 $messages[$key] = sprintf(_("%s is due now."), $link);
             } elseif ($differential >= 60) {
                 $messages[$key] = sprintf(_("%s is due in %s"), $link, Nag::secondsToString($differential));
             }
         }
         ksort($messages);
         foreach ($messages as $message) {
             $html .= '<tr><td class="control">' . Horde::img('alarm_small.png') . '&nbsp;&nbsp;<strong>' . $message . '</strong></td></tr>';
         }
         if (!empty($messages)) {
             $html .= '</table><br /><table cellspacing="0" width="100%" class="linedRow">';
         }
     }
     $i = 0;
     try {
         $tasks = Nag::listTasks(array('tasklists' => isset($this->_params['show_tasklists']) ? $this->_params['show_tasklists'] : array_keys(Nag::listTasklists(false, Horde_Perms::READ)), 'completed' => empty($this->_params['show_completed']) ? Nag::VIEW_INCOMPLETE : Nag::VIEW_ALL, 'include_history' => false));
     } catch (Nag_Exception $e) {
         return '<em>' . htmlspecialchars($e->getMessage()) . '</em>';
     }
     $tasks->reset();
     while ($task = $tasks->each()) {
         $due = $task->due ? $task->getNextDue() : null;
         // Only print tasks due in the past if the show_overdue flag is on.
         if ($due && $due->before($_SERVER['REQUEST_TIME']) && empty($this->_params['show_overdue'])) {
             continue;
         }
         if ($task->completed) {
             $class = 'closed';
         } elseif ($due && $due->before($_SERVER['REQUEST_TIME'])) {
             $class = 'overdue';
         } else {
             $class = '';
         }
         $style = ' style="background-color:' . $task->backgroundColor() . ';color:' . $task->foregroundColor() . '"';
         $html .= '<tr class="' . $class . '">';
         if (!empty($this->_params['show_actions'])) {
             $taskurl = Horde::url('task.php', true)->add(array('task' => $task->id, 'tasklist' => $task->tasklist, 'url' => Horde::selfUrl(true)));
             $label = sprintf(_("Edit \"%s\""), $task->name);
             $html .= '<td width="1%"' . $style . '>' . $taskurl->copy()->add('actionID', 'modify_task')->link() . Horde::img('edit-sidebar-' . substr($task->foregroundColor(), 1) . '.png', $label) . '</a></td>';
             if ($task->completed) {
                 $html .= '<td width="1%">' . $style . '' . Horde::img('checked.png', _("Completed")) . '</td>';
             } else {
                 $label = sprintf(_("Complete \"%s\""), $task->name);
                 $html .= '<td width="1%"' . $style . '>' . Horde::url($conf['urls']['pretty'] == 'rewrite' ? 't/complete' : 'task/complete.php')->add(array('task' => $task->id, 'tasklist' => $task->tasklist, 'url' => Horde::selfUrl(true)))->link() . Horde::img('unchecked.png', $label) . '</a></td>';
             }
         }
         if (!empty($this->_params['show_pri'])) {
             $html .= '<td align="center"' . $style . '>&nbsp;' . Nag::formatPriority($task->priority) . '&nbsp;</td>';
         }
         if (!empty($this->_params['show_tasklist'])) {
             $html .= '<td width="1%" class="nowrap"' . $style . '>' . htmlspecialchars(Nag::getLabel($GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create()->getShare($task->tasklist))) . '&nbsp;</td>';
         }
         $html .= '<td' . $style . '>';
         $viewurl = Horde::url('view.php', true)->add(array('task' => $task->id, 'tasklist' => $task->tasklist));
         $html .= $task->treeIcons() . $viewurl->link(array('title' => $task->desc, 'style' => 'color:' . $task->foregroundColor())) . (!empty($task->name) ? htmlspecialchars($task->name) : _("[none]")) . '</a>';
         if ($due && empty($task->completed) && !empty($this->_params['show_due'])) {
             $html .= ' (' . $due->strftime($prefs->getValue('date_format')) . ')';
         }
         $html .= '</td>';
         $html .= "</tr>\n";
     }
     if (empty($html)) {
         return '<em>' . _("No tasks to display") . '</em>';
     }
     return '<table cellspacing="0" width="100%" class="linedRow">' . $html . '</table>';
 }
Esempio n. 2
0
 /**
  */
 public function listAlarms($time, $user = null)
 {
     if ((empty($user) || $user != $GLOBALS['registry']->getAuth()) && !$GLOBALS['registry']->isAdmin()) {
         throw new Horde_Exception_PermissionDenied();
     }
     $group = $GLOBALS['injector']->getInstance('Horde_Group');
     $alarm_list = array();
     $tasklists = is_null($user) ? array_keys($GLOBALS['nag_shares']->listAllShares()) : $GLOBALS['display_tasklists'];
     $alarms = Nag::listAlarms($time, $tasklists);
     foreach ($alarms as $alarm) {
         try {
             $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist);
         } catch (Horde_Share_Exception $e) {
             continue;
         }
         if (empty($user)) {
             $users = $share->listUsers(Horde_Perms::READ);
             $groups = $share->listGroups(Horde_Perms::READ);
             foreach ($groups as $gid) {
                 $users = array_merge($users, $group->listUsers($gid));
             }
             $users = array_unique($users);
         } else {
             $users = array($user);
         }
         foreach ($users as $alarm_user) {
             $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('nag', array('cache' => false, 'user' => $alarm_user));
             $GLOBALS['registry']->setLanguageEnvironment($prefs->getValue('language'));
             $alarm_list[] = $alarm->toAlarm($alarm_user, $prefs);
         }
     }
     return $alarm_list;
 }