61 $this->label = esc_html__(
'Time',
'gk-gravityview' );
63 parent::__construct();
65 add_filter(
'gravityview/sorting/time', array( $this,
'modify_sort_id' ), 10, 2 );
67 add_filter(
'gravityview_search_criteria', array( $this,
'_maybe_filter_gravity_forms_query' ), 10, 4 );
83 $time_format = self::_get_time_format_for_field( $sort_field_id,
$form_id );
85 $date_format = self::date_format( $time_format, $sort_field_id );
88 $new_sort_field_id = implode( $this->_sort_divider, array( $sort_field_id, $time_format, $date_format ) );
90 return $new_sort_field_id;
108 if( empty(
$criteria[
'sorting'][
'key'] ) ) {
112 $pieces = explode( $this->_sort_divider,
$criteria[
'sorting'][
'key'] );
118 if( empty( $pieces[1] ) ) {
123 $this->_time_format = $pieces[1];
124 $this->_date_format = $pieces[2];
127 $criteria[
'sorting'][
'key'] = floor( $pieces[0] );
133 $criteria[
'sorting'][
'is_numeric'] =
true;
136 add_filter(
'query', array( $this,
'_modify_query_sort_by_time_hack' ) );
157 if( strpos( $query, self::GF_SORTING_SQL ) > 0 ) {
159 if( $this->_time_format ===
'24' ) {
160 $sql_str_to_date =
"STR_TO_DATE( `value`, '%H:%i' )";
162 $sql_str_to_date =
"STR_TO_DATE( `value`, '%h:%i %p' )";
165 switch ( $this->_date_format ) {
168 $modification =
"TIME_FORMAT( {$sql_str_to_date}, '%H' )";
171 $modification =
"TIME_FORMAT( {$sql_str_to_date}, '%i' )";
176 $modification =
"TIME_TO_SEC( {$sql_str_to_date} )";
183 $replacement_query = str_replace(
'value',
"{$modification} as value", self::GF_SORTING_SQL );
188 $query = str_replace( self::GF_SORTING_SQL, $replacement_query, $query );
193 remove_filter(
'query', array( $this,
'_modify_query_sort_by_time_hack' ) );
203 parent::field_options( $field_options, $template_id,
$field_id, $context, $input_type,
$form_id );
205 if(
'edit' === $context ) {
206 return $field_options;
212 add_filter(
'gravityview_date_format', array( $this,
'_filter_date_display_date_format' ) );
216 remove_filter(
'gravityview_date_format', array( $this,
'_filter_date_display_date_format' ) );
218 return $field_options;
233 return self::_get_time_format_for_field( $this->_field_id,
$current_form );
256 $field->sanitize_settings();
257 $time_format =
$field->timeFormat;
277 return self::date_format( $time_format,
$field_id );
297 switch( $field_input_id ) {
300 return ( $time_format ===
'12' ) ?
'h' :
'H';
312 return ( $time_format ===
'12' ) ? $default :
'H:i';
Modify field settings by extending this class.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
add_field_support( $key, &$field_options)
_maybe_filter_gravity_forms_query( $criteria, $form_ids, $view_id)
If the sorting key matches the key set in modify_sort_id(), then modify the Gravity Forms query SQL...
if(gravityview() ->plugin->is_GF_25()) $form
gravityview_get_input_id_from_id( $field_id='')
Very commonly needed: get the # of the input based on a full field ID.
$criteria['paging']
Modify the search parameters before the entries are fetched.
_filter_date_display_date_format()
Modify the default PHP date formats used by the time field based on the field IDs and the field setti...
modify_sort_id( $sort_field_id, $form_id)
Modify the sort key for the time field so it can be parsed by the query filter.
static _get_time_format_for_field( $field_id, $form_id=0)
Return the field's time format by fetching the form ID and checking the field settings.
gravityview_get_form_id( $view_id)
Get the connected form ID from a View ID.
if(empty( $created_by)) $form_id
new GravityView_Field_Time
__construct()
GravityView_Field_Time constructor.
Add custom options for date fields.
_modify_query_sort_by_time_hack( $query)
Modify Gravity Forms query SQL to convert times to numbers Gravity Forms couldn't sort by time...
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
_get_time_format()
Return the field's time format by fetching the form ID and checking the field settings.
static date_format( $time_format='12', $field_id=0)
Get the default date format for a field based on the field ID and the time format setting...