Dropdown::showHours PHP Метод

showHours() статический публичный Метод

Print a select named $name with hours options and selected value $value
С версии: 0.85 update prototype
static public showHours ( $name, $options = [] ) : Nothing
$name string HTML select name
$options array of options : - value default value (default '') - limit_planning limit planning to the configuration range (default false) - display boolean if false get string - width specific width needed (default auto adaptive) - step step time (defaut config GLPI)
Результат Nothing (display)
    static function showHours($name, $options = array())
    {
        global $CFG_GLPI;
        $p['value'] = '';
        $p['limit_planning'] = false;
        $p['display'] = true;
        $p['width'] = '';
        $p['step'] = $CFG_GLPI["time_step"];
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $p[$key] = $val;
            }
        }
        $begin = 0;
        $end = 24;
        // Check if the $step is Ok for the $value field
        $split = explode(":", $p['value']);
        // Valid value XX:YY ou XX:YY:ZZ
        if (count($split) == 2 || count($split) == 3) {
            $min = $split[1];
            // Problem
            if ($min % $p['step'] != 0) {
                // set minimum step
                $p['step'] = 5;
            }
        }
        if ($p['limit_planning']) {
            $plan_begin = explode(":", $CFG_GLPI["planning_begin"]);
            $plan_end = explode(":", $CFG_GLPI["planning_end"]);
            $begin = (int) $plan_begin[0];
            $end = (int) $plan_end[0];
        }
        $values = array();
        $selected = '';
        for ($i = $begin; $i < $end; $i++) {
            if ($i < 10) {
                $tmp = "0" . $i;
            } else {
                $tmp = $i;
            }
            for ($j = 0; $j < 60; $j += $p['step']) {
                if ($j < 10) {
                    $val = $tmp . ":0{$j}";
                } else {
                    $val = $tmp . ":{$j}";
                }
                $values[$val] = $val;
                if ($p['value'] == $val . ":00" || $p['value'] == $val) {
                    $selected = $val;
                }
            }
        }
        // Last item
        $val = $end . ":00";
        $values[$val] = $val;
        if ($p['value'] == $val . ":00" || $p['value'] == $val) {
            $selected = $val;
        }
        $p['value'] = $selected;
        return Dropdown::showFromArray($name, $values, $p);
    }

Usage Example

 function displayCriteria()
 {
     $this->getReport()->startColumn();
     printf(__('Start at %s'), __('Number pending', 'reports'));
     echo "&nbsp;&nbsp;";
     $this->getReport()->endColumn();
     $this->getReport()->startColumn();
     Dropdown::showHours("starttime", $this->getParameter('starttime'));
     $this->getReport()->endColumn();
     $this->getReport()->startColumn();
     printf(__('End at %s'), __('Number pending', 'reports'));
     echo "&nbsp;&nbsp;";
     $this->getReport()->endColumn();
     $this->getReport()->startColumn();
     Dropdown::showHours("endtime", $this->getParameter('endtime'));
     $this->getReport()->endColumn();
 }
All Usage Examples Of Dropdown::showHours