Hermes::getTimer PHP Method

getTimer() public static method

Return a specific timer.
public static getTimer ( $id ) : array
return array The timer hash.
    public static function getTimer($id)
    {
        global $registry, $prefs;
        $timers = $prefs->getValue('running_timers');
        if (!empty($timers)) {
            $timers = @unserialize($timers);
        }
        if (empty($timers[$id])) {
            throw new Horde_Exception_NotFound(_("The requested timer was not found."));
        }
        $timers[$id]['id'] = $id;
        try {
            $text = Hermes::getCostObjectByID($timers[$id]['deliverable_id'], $registry->getAuth());
            $timers[$id]['deliverable_text'] = $text['name'];
        } catch (Horde_Exception_NotFound $e) {
        }
        return $timers[$id];
    }

Usage Example

示例#1
0
 /**
  * Stop a timer. Expects the following in $this->vars:
  *   - t:  The timer id.
  *   - restart:
  *
  * @return array  An array describing the current timer state. Contains:
  *  - h: The total number of hours elapsed so far.
  *  - n: A note to apply to the description field of a time slice.
  *  - t: The new timer title, if restarting.
  */
 public function stopTimer()
 {
     global $prefs, $notification;
     try {
         $timer = Hermes::getTimer($this->vars->t);
     } catch (Horde_Exception_NotFound $e) {
         $notification->push(_("Invalid timer requested"), 'horde.error');
         return false;
     }
     $results = $timer;
     $tname = $timer['name'];
     $elapsed = (!$timer['paused'] ? time() - $timer['time'] : 0) + $timer['elapsed'];
     $results['h'] = round((double) $elapsed / 3600, 2);
     $started = new Horde_Date($this->vars->t, 'UTC');
     $started->setTimezone(date_default_timezone_get());
     $now = new Horde_Date(time(), 'UTC');
     $now->setTimezone(date_default_timezone_get());
     if ($prefs->getValue('add_description')) {
         $results['n'] = sprintf(_("Using the \"%s\" stop watch from %s %s to %s %s"), $tname, $started->strftime($prefs->getValue('date_format_mini')), $started->strftime($prefs->getValue('time_format')), $now->strftime($prefs->getValue('date_format_mini')), $now->strftime($prefs->getValue('time_format')));
     } else {
         $results['n'] = '';
     }
     $notification->push(sprintf(_("The stop watch \"%s\" has been stopped."), $tname), 'horde.success');
     Hermes::clearTimer($this->vars->t);
     if ($this->vars->restart == 'true') {
         $now = time();
         $timer['elapsed'] = 0;
         $timer['paused'] = $results['paused'] = true;
         $timer['time'] = $now;
         Hermes::updateTimer($this->vars->t, $timer);
     }
     return $results;
 }
All Usage Examples Of Hermes::getTimer