/** * 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; }