Example #1
0
 /**
  * Add a selection drop down for the hour, minute and second to be selected.
  * @param string $name The name of the selection element
  * @param I2CE_Date $default The default I2CE_Date object to use to preset the value.
  * @param boolean $showError A flag if this field is currently invalid to mark it as such.
  * @param DOMNode $node The node to append the element to.
  * @param boolean $hidden Set to true if the form element should be hidden.
  */
 public static function addTimeElement($template, $name, $default, $showError, $node, $hidden = false)
 {
     if ($hidden) {
         $hour = $template->createElement("input", array("name" => $name . "[hour]", "type" => "hidden", "value" => $default->hour()));
         $minute = $template->createElement("input", array("name" => $name . "[minute]", "type" => "hidden", "value" => $default->minute()));
         $second = $template->createElement("input", array("name" => $name . "[second]", "type" => "hidden", "value" => $default->second()));
     } else {
         $hour = $template->createElement("select", array("name" => $name . "[hour]", "class" => "date_hour" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 23; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isHour($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $hour->appendChild($opt);
         }
         $minute = $template->createElement("select", array("name" => $name . "[minute]", "class" => "date_minute" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 59; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isMinute($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $minute->appendChild($opt);
         }
         $second = $template->createElement("select", array("name" => $name . "[second]", "class" => "date_second" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 59; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isSecond($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $second->appendChild($opt);
         }
     }
     $node->appendChild($hour);
     $node->appendChild($minute);
     $node->appendChild($second);
 }