Hermes::listTimers PHP Method

listTimers() public static method

Return list of current timers.
public static listTimers ( boolean $running_only = false ) : array
$running_only boolean Only return running timers if true.
return array An array of timer hashes.
    public static function listTimers($running_only = false)
    {
        global $registry, $prefs;
        $timers = $prefs->getValue('running_timers');
        if (!empty($timers)) {
            $timers = @unserialize($timers);
        } else {
            $timers = array();
        }
        $return = array();
        foreach ($timers as $id => $timer) {
            if ($running_only && $timer['paused']) {
                continue;
            }
            $elapsed = (!$timer['paused'] ? time() - $timer['time'] : 0) + $timer['elapsed'];
            $timer['elapsed'] = round((double) $elapsed / 3600, 2);
            $timer['id'] = $id;
            try {
                $text = Hermes::getCostObjectByID($timer['deliverable_id'], $registry->getAuth());
                $timer['deliverable_text'] = $text['name'];
            } catch (Horde_Exception_NotFound $e) {
            }
            $return[] = $timer;
        }
        return $return;
    }

Usage Example

示例#1
0
 /**
  */
 public function topbarCreate(Horde_Tree_Renderer_Base $tree, $parent = null, array $params = array())
 {
     switch ($params['id']) {
         case 'menu':
             $tree->addNode(array('id' => $parent . '__add', 'parent' => $parent, 'label' => _("Enter Time"), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('hermes.png'), 'url' => Horde::url('entry.php'))));
             $tree->addNode(array('id' => $parent . '__search', 'parent' => $parent, 'label' => _("Search Time"), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('search.png'), 'url' => Horde::url('search.php'))));
             break;
         case 'stopwatch':
             $tree->addNode(array('id' => $parent . '__start', 'parent' => $parent, 'label' => _("Start Watch"), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('timer-start.png'), 'url' => '#', 'onclick' => Horde::popupJs(Horde::url('start.php'), array('height' => 200, 'width' => 410)))));
             $timers = Hermes::listTimers();
             $entry = Horde::url('entry.php');
             foreach ($timers as $i => $timer) {
                 $tree->addNode(array('id' => $parent . '__timer_' . $i, 'parent' => $parent, 'label' => $timer['name'] . sprintf(" (%s)", $timer['elapsed']), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('timer-stop.png'), 'url' => $entry->add('timer', $timer['id']))));
             }
     }
 }
All Usage Examples Of Hermes::listTimers