public static function get_time_display_value($replace_with, $atts, $field) { $time_clock = isset($field->field_options['clock']) ? $field->field_options['clock'] : 12; $defaults = array('format' => $time_clock == 24 ? 'H:i' : 'g:i A'); $atts = wp_parse_args($atts, $defaults); if (strpos($replace_with, ',')) { $replace_with = explode(',', $replace_with); } if (is_array($replace_with)) { foreach ($replace_with as $k => $v) { $replace_with[$k] = FrmProAppHelper::format_time($replace_with[$k], $atts['format']); } } else { $replace_with = FrmProAppHelper::format_time($replace_with, $atts['format']); } return $replace_with; }
/** * Reorder entries if 12 hour time field is selected for first ordering field. * If the $time_field variable is set, this means the first ordering field is a time field. */ private static function reorder_time_entries(&$entry_ids, $time_field) { if (!$time_field || !is_array($entry_ids) || empty($entry_ids)) { return; } if (isset($time_field->field_options['clock']) && $time_field->field_options['clock'] != 12) { // only reorder with 12 hour times return; } global $wpdb; //Reorder entries $new_order = array(); $empty_times = array(); $times = $wpdb->get_results($wpdb->prepare('SELECT item_id, meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $time_field->id), OBJECT_K); foreach ($entry_ids as $e_key) { if (!isset($times[$e_key])) { $empty_times[$e_key] = ''; continue; } $time = $times[$e_key]->meta_value; $new_order[$e_key] = FrmProAppHelper::format_time($time, 'Hi'); unset($e_key, $entry); } //array with sorted times asort($new_order); $new_order = $new_order + $empty_times; $final_order = array_keys($new_order); $entry_ids = $final_order; }