1 | <?php |
||
11 | class GravityView_Field_Time extends GravityView_Field { |
||
12 | |||
13 | var $name = 'time'; |
||
14 | |||
15 | var $is_searchable = true; |
||
16 | |||
17 | var $search_operators = array( 'is', 'isnot', 'greater_than', 'less_than' ); |
||
18 | |||
19 | /** @see GF_Field_Time */ |
||
20 | var $_gf_field_class_name = 'GF_Field_Time'; |
||
21 | |||
22 | var $group = 'advanced'; |
||
23 | |||
24 | /** |
||
25 | * @internal Do not define. This is overridden by the class using a filter. |
||
26 | * @todo Fix using variable for time field |
||
27 | */ |
||
28 | var $is_numeric; |
||
29 | |||
30 | /** |
||
31 | * @var string The part of the Gravity Forms query that's modified to enable sorting by time. `value` gets replaced. |
||
32 | * @since 1.14 |
||
33 | */ |
||
34 | const GF_SORTING_SQL = 'SELECT 0 as query, lead_id as id, value'; |
||
35 | |||
36 | /** |
||
37 | * @var string Used to implode and explode the custom sort key for query modification. |
||
38 | * @since 1.14 |
||
39 | */ |
||
40 | private $_sort_divider = '|:time:|'; |
||
41 | |||
42 | /** |
||
43 | * @var string Used to store the time format for the field ("12" or "24") so it can be used in the query filter |
||
44 | * @since 1.14 |
||
45 | */ |
||
46 | private $_time_format = null; |
||
47 | |||
48 | /** |
||
49 | * @var string Used to store the date format for the field, based on the input being displayed, so it can be used in the query filter |
||
50 | * @since 1.14 |
||
51 | */ |
||
52 | private $_date_format = null; |
||
53 | |||
54 | /** |
||
55 | * GravityView_Field_Time constructor. |
||
56 | */ |
||
57 | public function __construct() { |
||
67 | |||
68 | /** |
||
69 | * Modify the sort key for the time field so it can be parsed by the query filter |
||
70 | * |
||
71 | * @see _modify_query_sort_by_time_hack |
||
72 | * |
||
73 | * @since 1.14 |
||
74 | * @param string $sort_field_id Existing sort field ID (like "5") |
||
75 | * @param int $form_id Gravity Forms Form ID being sorted |
||
76 | * |
||
77 | * @return string Modified sort key imploded with $_sort_divider, like `5|:time:|12|:time:|h:i A` |
||
78 | */ |
||
79 | 1 | public function modify_sort_id( $sort_field_id, $form_id ) { |
|
90 | |||
91 | /** |
||
92 | * If the sorting key matches the key set in modify_sort_id(), then modify the Gravity Forms query SQL |
||
93 | * |
||
94 | * @since 1.14 |
||
95 | * @see modify_sort_id() |
||
96 | * |
||
97 | * @param array $criteria Search criteria used by GravityView |
||
98 | * @param array $form_ids Forms to search |
||
99 | * @param int $view_id ID of the view being used to search |
||
100 | * |
||
101 | * @return array $criteria If a match, the sorting will be updated to set `is_numeric` to true and make sure the field ID is an int |
||
102 | */ |
||
103 | 74 | public function _maybe_filter_gravity_forms_query( $criteria, $form_ids, $view_id ) { |
|
138 | |||
139 | /** |
||
140 | * Modify Gravity Forms query SQL to convert times to numbers |
||
141 | * Gravity Forms couldn't sort by time...until NOW |
||
142 | * |
||
143 | * @since 1.14 |
||
144 | * @param string $query MySQL query |
||
145 | * |
||
146 | * @return string Modified query, if the query matches the expected Gravity Forms SQL string used for sorting time fields. Otherwise, original query. |
||
147 | */ |
||
148 | 2 | function _modify_query_sort_by_time_hack( $query ) { |
|
196 | |||
197 | |||
198 | public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
||
218 | |||
219 | /** |
||
220 | * Return the field's time format by fetching the form ID and checking the field settings |
||
221 | * |
||
222 | * @since 1.14 |
||
223 | * |
||
224 | * @return string Either "12" or "24". "12" is default. |
||
225 | */ |
||
226 | private function _get_time_format() { |
||
233 | |||
234 | /** |
||
235 | * Return the field's time format by fetching the form ID and checking the field settings |
||
236 | * |
||
237 | * @since 1.14 |
||
238 | * |
||
239 | * @param string $field_id ID for Gravity Forms time field |
||
240 | * @param int $form_id ID for Gravity Forms form |
||
241 | * @return string Either "12" or "24". "12" is default. |
||
242 | */ |
||
243 | 1 | static public function _get_time_format_for_field( $field_id, $form_id = 0 ) { |
|
262 | |||
263 | /** |
||
264 | * Modify the default PHP date formats used by the time field based on the field IDs and the field settings |
||
265 | * |
||
266 | * @since 1.14 |
||
267 | * |
||
268 | * @return string PHP date() format text to to display the correctly formatted time value for the newly created field |
||
269 | */ |
||
270 | public function _filter_date_display_date_format() { |
||
277 | |||
278 | /** |
||
279 | * Get the default date format for a field based on the field ID and the time format setting |
||
280 | * |
||
281 | * @since 1.14 |
||
282 | |||
283 | * @param string $time_format The time format ("12" or "24"). Default: "12" {@since 1.14} |
||
284 | * @param int $field_id The ID of the field. Used to figure out full time/hours/minutes/am/pm {@since 1.14} |
||
285 | * |
||
286 | * @return string PHP date format for the time |
||
287 | */ |
||
288 | 2 | static public function date_format( $time_format = '12', $field_id = 0 ) { |
|
316 | |||
317 | } |
||
318 | |||
320 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.