-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathClockTimePickerField.php
More file actions
71 lines (62 loc) · 2.77 KB
/
Copy pathClockTimePickerField.php
File metadata and controls
71 lines (62 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Copyright 2015 Open Infrastructure Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class ClockTimePickerField extends TimeField
{
public function Field($properties = array())
{
JQueryClockPickerDependencies::renderRequirements();
Requirements::javascript('openstack/code/utils/CustomHTMLFields/js/ClockTimePickerField.js');
Requirements::css('openstack/code/utils/CustomHTMLFields/css/ClockTimePickerField.css');
$this->addExtraClass('ss-timeclock-field');
$this->locale = 'en_US';
return $this
->customise($properties)
->renderWith(array("ClockTimePickerField"));
}
public function setValue($val) {
// Fuzzy matching through strtotime() to support a wider range of times,
// e.g. 11am. This means that validate() might not fire.
// Note: Time formats are assumed to be less ambiguous than dates across locales.
if($this->getConfig('use_strtotime') && !empty($val)) {
if($parsedTimestamp = strtotime($val)) {
$parsedObj = new Zend_Date($parsedTimestamp, Zend_Date::TIMESTAMP, $this->locale);
$val = $parsedObj->get($this->getConfig('timeformat'));
unset($parsedObj);
}
}
if(empty($val)) {
$this->value = null;
$this->valueObj = null;
}
// load ISO time from database (usually through Form->loadDataForm())
// Requires exact format to prevent false positives from locale specific times
else if($this->valueObj = $this->parseTime($val, $this->getConfig('datavalueformat'), $this->locale, true)) {
$this->value = $this->valueObj->get($this->getConfig('timeformat'));
}
// Set in current locale (as string)
else if($this->valueObj = $this->parseTime($val, $this->getConfig('timeformat'), $this->locale)) {
$this->value = $this->valueObj->get($this->getConfig('timeformat'));
}
// Fallback: Set incorrect value so validate() can pick it up
elseif(is_string($val)) {
$this->value = $val;
$this->valueObj = null;
}
else {
$this->value = null;
$this->valueObj = null;
}
return $this;
}
}