getTimer() public static method

Return a specific timer.
public static getTimer ( $id ) : array
return array The timer hash.
示例#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;
 }
示例#2
0
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @author Chuck Hagenbuch <*****@*****.**>
 * @author Jan Schneider <*****@*****.**>
 */
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('hermes');
if (Hermes::showAjaxView()) {
    Horde::url('', true)->setAnchor('time')->redirect();
}
$vars = Horde_Variables::getDefaultVariables();
if (!$vars->exists('id') && $vars->exists('timer')) {
    $timer_id = $vars->get('timer');
    try {
        $timer = Hermes::getTimer($timer_id);
        $tname = $timer['name'];
        $tformat = $prefs->getValue('twentyFour') ? 'G:i' : 'g:i a';
        $elapsed = (!$timer['paused'] ? time() - $timer['time'] : 0) + $timer['elapsed'];
        $vars->set('hours', round((double) $elapsed / 3600, 2));
        if ($prefs->getValue('add_description')) {
            $vars->set('note', sprintf(_("Using the \"%s\" stop watch from %s to %s"), $tname, date($tformat, $timer_id), date($tformat, time())));
        }
        $notification->push(sprintf(_("The stop watch \"%s\" has been stopped."), $tname), 'horde.success');
        if ($timers = @unserialize($prefs->getValue('running_timers'))) {
            unset($timers[$timer_id]);
            $prefs->setValue('running_timers', serialize($timers));
        }
    } catch (Horde_Exception_NotFound $e) {
    }
}
示例#3
0
 /**
  * Pause a timer.
  *
  * @param  integer $id  The timer id.
  *
  * @return boolean
  */
 public static function pauseTimer($id)
 {
     $timer = Hermes::getTimer($id);
     // Avoid pausing the same timer twice.
     if ($timer['paused'] || $timer['time'] == 0) {
         return true;
     }
     $timer['paused'] = true;
     $timer['elapsed'] += time() - $timer['time'];
     $timer['time'] = 0;
     Hermes::updateTimer($id, $timer);
     return true;
 }