Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Time.php
Go to the documentation of this file.
1 <?php
13 
15 
16 class Time extends AbstractElement
17 {
24  public function __construct(
25  Factory $factoryElement,
26  CollectionFactory $factoryCollection,
27  Escaper $escaper,
28  $data = []
29  ) {
30  parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
31  $this->setType('time');
32  }
33 
37  public function getName()
38  {
39  $name = parent::getName();
40  if (strpos($name, '[]') === false) {
41  $name .= '[]';
42  }
43  return $name;
44  }
45 
51  public function getElementHtml()
52  {
53  $this->addClass('select admin__control-select');
54 
55  $valueHrs = 0;
56  $valueMin = 0;
57  $valueSec = 0;
58 
59  if ($value = $this->getValue()) {
60  $values = explode(',', $value);
61  if (is_array($values) && count($values) == 3) {
62  $valueHrs = $values[0];
63  $valueMin = $values[1];
64  $valueSec = $values[2];
65  }
66  }
67 
68  $html = '<input type="hidden" id="' . $this->getHtmlId() . '" ' . $this->_getUiId() . '/>';
69  $html .= '<select name="' . $this->getName() . '" style="width:80px" '
70  . $this->serialize($this->getHtmlAttributes())
71  . $this->_getUiId('hour') . '>' . "\n";
72  for ($i = 0; $i < 24; $i++) {
73  $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
74  $html .= '<option value="' . $hour . '" ' . ($valueHrs ==
75  $i ? 'selected="selected"' : '') . '>' . $hour . '</option>';
76  }
77  $html .= '</select>' . "\n";
78 
79  $html .= ':&nbsp;<select name="' . $this->getName() . '" style="width:80px" '
80  . $this->serialize($this->getHtmlAttributes())
81  . $this->_getUiId('minute') . '>' . "\n";
82  for ($i = 0; $i < 60; $i++) {
83  $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
84  $html .= '<option value="' . $hour . '" ' . ($valueMin ==
85  $i ? 'selected="selected"' : '') . '>' . $hour . '</option>';
86  }
87  $html .= '</select>' . "\n";
88 
89  $html .= ':&nbsp;<select name="' . $this->getName() . '" style="width:80px" '
90  . $this->serialize($this->getHtmlAttributes())
91  . $this->_getUiId('second') . '>' . "\n";
92  for ($i = 0; $i < 60; $i++) {
93  $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
94  $html .= '<option value="' . $hour . '" ' . ($valueSec ==
95  $i ? 'selected="selected"' : '') . '>' . $hour . '</option>';
96  }
97  $html .= '</select>' . "\n";
98  $html .= $this->getAfterElementHtml();
99  return $html;
100  }
101 }
__construct(Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, $data=[])
Definition: Time.php:24
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16
serialize($attributes=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
$i
Definition: gallery.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14