1 | <?php |
||
8 | class Time_Field extends Field { |
||
9 | |||
10 | /** |
||
11 | * Picker type. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $picker_type = 'timepicker'; |
||
16 | |||
17 | /** |
||
18 | * Picker options. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | public $picker_options = array( |
||
23 | 'dateFormat' => 'yy-mm-dd', |
||
24 | 'timeFormat' => 'hh:mm tt', |
||
25 | 'altFormat' => 'yy-mm-dd', |
||
26 | 'altTimeFormat' => 'HH:mm:ss', |
||
27 | 'altFieldTimeOnly' => false, |
||
28 | ); |
||
29 | |||
30 | /** |
||
31 | * Interval step for hours, minutes and seconds. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | public $interval_step = array(); |
||
36 | |||
37 | /** |
||
38 | * Restraints for hours, minutes, seconds and dates. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | public $restraints = array(); |
||
43 | |||
44 | /** |
||
45 | * The storage format in variant that can be used by JavaScript. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $storage_format = 'HH:mm:ss'; |
||
50 | |||
51 | /** |
||
52 | * You can use this method to modify the field properties that are added to the JSON object. |
||
53 | * |
||
54 | * @param bool $load Should the value be loaded from the database or use the value from the current instance. |
||
55 | * @return array |
||
56 | */ |
||
57 | public function to_json( $load ) { |
||
58 | $field_data = parent::to_json( $load ); |
||
59 | |||
60 | $field_data = array_merge( $field_data, array( |
||
61 | 'storage_format' => $this->storage_format, |
||
62 | 'interval_step' => $this->get_interval_step(), |
||
63 | 'restraints' => $this->get_restraints(), |
||
64 | 'picker_type' => $this->picker_type, |
||
65 | 'picker_options' => $this->get_picker_options(), |
||
66 | ) ); |
||
67 | |||
68 | return $field_data; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * This method is called in the admin_enqueue_scripts action. It is called once per field type. |
||
73 | * Enqueues field scripts and styles. |
||
74 | */ |
||
75 | public static function admin_enqueue_scripts() { |
||
82 | |||
83 | /** |
||
84 | * Sets the time format. |
||
85 | */ |
||
86 | public function set_time_format( $time_format ) { |
||
87 | $this->picker_options['timeFormat'] = $time_format; |
||
88 | return $this; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns the time format. |
||
93 | */ |
||
94 | public function get_time_format() { |
||
95 | return isset( $this->picker_options['timeFormat'] ) ? $this->picker_options['timeFormat'] : null; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Sets the interval step. |
||
100 | */ |
||
101 | public function set_interval_step( $interval_steps ) { |
||
102 | $output = array(); |
||
103 | |||
104 | foreach ( $interval_steps as $step_name => $step_value ) { |
||
105 | $name = 'step' . ucwords( $step_name ); |
||
106 | $output[ $name ] = (int) $step_value; |
||
107 | } |
||
108 | |||
109 | $this->interval_step = $output; |
||
110 | |||
111 | return $this; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Returns the interval step. |
||
116 | */ |
||
117 | public function get_interval_step() { |
||
120 | |||
121 | /** |
||
122 | * Sets the restraints. |
||
123 | */ |
||
124 | public function set_restraints( $restraints ) { |
||
129 | |||
130 | /** |
||
131 | * Returns the restraints. |
||
132 | */ |
||
133 | public function get_restraints() { |
||
136 | |||
137 | /** |
||
138 | * Sets other picker options. |
||
139 | */ |
||
140 | public function set_picker_options( $options ) { |
||
144 | |||
145 | /** |
||
146 | * Returns the picker options. |
||
147 | */ |
||
148 | public function get_picker_options() { |
||
151 | } |
||
152 |