1 | <?php |
||
2 | |||
3 | namespace LeKoala\FormElements; |
||
4 | |||
5 | use SilverStripe\ORM\DataObjectInterface; |
||
6 | |||
7 | /** |
||
8 | * Format time field |
||
9 | * @link https://robinherbots.github.io/Inputmask/#/documentation/datetime |
||
10 | */ |
||
11 | class InputMaskTimeField extends InputMaskDateTimeField |
||
12 | { |
||
13 | /** |
||
14 | * Set this to true if internal value is seconds |
||
15 | * |
||
16 | * @var boolean |
||
17 | */ |
||
18 | protected $isNumeric = false; |
||
19 | |||
20 | public function __construct($name, $title = null, $value = null) |
||
21 | { |
||
22 | parent::__construct($name, $title, $value); |
||
23 | |||
24 | $this->setAlias(self::ALIAS_DATETIME); |
||
25 | $this->setInputFormat('HH:MM:ss'); |
||
26 | $this->setOutputFormat('HH:MM:ss'); |
||
27 | $this->setPlaceholder('HH:MM:ss'); |
||
28 | } |
||
29 | |||
30 | public function setValue($value, $data = null) |
||
31 | { |
||
32 | if ($this->isNumeric && is_numeric($value)) { |
||
33 | $value = self::secondsToTime($value); |
||
34 | } |
||
35 | // Don't call parent that can set locale formatted date |
||
36 | $this->value = $value; |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | public function dataValue() |
||
41 | { |
||
42 | $value = parent::dataValue(); |
||
43 | // Value is stored in database in seconds |
||
44 | if ($this->isNumeric) { |
||
45 | return self::timeToSeconds($value); |
||
46 | } |
||
47 | return $value; |
||
48 | } |
||
49 | |||
50 | public function saveInto(DataObjectInterface $record) |
||
51 | { |
||
52 | // Replace missing placeholders |
||
53 | $this->value = str_replace([':MM', ':ss'], ':00', $this->value); |
||
54 | return parent::saveInto($record); |
||
0 ignored issues
–
show
|
|||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get the value of isNumeric |
||
59 | * @return mixed |
||
60 | */ |
||
61 | public function getIsNumeric() |
||
62 | { |
||
63 | return $this->isNumeric; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Set the value of isNumeric |
||
68 | * |
||
69 | * @param mixed $isNumeric |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function setIsNumeric($isNumeric) |
||
73 | { |
||
74 | $this->isNumeric = $isNumeric; |
||
75 | return $this; |
||
76 | } |
||
77 | } |
||
78 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.