Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/search_helper.php
Show First 20 Lines • Show All 596 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
break; | break; | ||||
case 'date_range': | case 'date_range': | ||||
$from = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'from'); | $from = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'from'); | ||||
$to = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'to'); | $to = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'to'); | ||||
$day_seconds = 23 * 60 * 60 + 59 * 60 + 59; | $day_seconds = 23 * 60 * 60 + 59 * 60 + 59; | ||||
if ($from !== false && $to === false) { | |||||
$from = strtotime(date('Y-m-d', $from) . ' 00:00:00', $from); // reset to morning | if ( is_numeric($from) && $to === null && date('H:i:s', $from) == '00:00:00' ) { | ||||
$to = $from + $day_seconds; | $to = $from + $day_seconds; | ||||
} | } | ||||
elseif ($from === false && $to !== false) { | elseif ( $from === null && is_numeric($to) && date('H:i:s', $to) == '00:00:00' ) { | ||||
$to = strtotime(date('Y-m-d', $to) . ' 23:59:59', $to); // reset to evening | $from = $to; | ||||
$from = $to - $day_seconds; | $to += $day_seconds; | ||||
} | } | ||||
if ($from !== false && $to !== false) { | if ( is_numeric($from) && $to === null || $from === null && is_numeric($to) ) { | ||||
$from = $from === null ? $to : $from; | |||||
$to = $from; | |||||
} | |||||
if ( is_numeric($from) && is_numeric($to) ) { | |||||
$from = strtotime(date('Y-m-d H:i', $from) . ':00', $from); | |||||
$to = strtotime(date('Y-m-d H:i', $to) . ':59', $to); | |||||
$filter_value = $table_name.'`'.$field_name.'` >= '.$from.' AND '.$table_name.'`'.$field_name.'` <= '.$to; | $filter_value = $table_name.'`'.$field_name.'` >= '.$from.' AND '.$table_name.'`'.$field_name.'` <= '.$to; | ||||
} | } | ||||
else { | |||||
$filter_value = 'FALSE'; | |||||
} | |||||
break; | break; | ||||
case 'equals': | case 'equals': | ||||
case 'options': | case 'options': | ||||
$field_value = strlen($field_options['submit_value']) ? $this->Conn->qstr($field_options['submit_value']) : false; | $field_value = strlen($field_options['submit_value']) ? $this->Conn->qstr($field_options['submit_value']) : false; | ||||
if ($field_value) { | if ($field_value) { | ||||
$filter_value = $table_name.'`'.$field_name.'` = '.$field_value; | $filter_value = $table_name.'`'.$field_name.'` = '.$field_value; | ||||
} | } | ||||
Show All 39 Lines | |||||
/** | /** | ||||
* Enter description here... | * Enter description here... | ||||
* | * | ||||
* @param kdbItem $object | * @param kdbItem $object | ||||
* @param string $search_field | * @param string $search_field | ||||
* @param string $value | * @param string $value | ||||
* @param string $type | * @param string $type | ||||
* @param string $format_option_prefix Format option prefix. | |||||
*/ | */ | ||||
function processRangeField(&$object, $search_field, $value, $type) | function processRangeField(&$object, $search_field, $value, $type, $format_option_prefix = '') | ||||
{ | { | ||||
if ( !strlen($value[$type]) ) { | $value_by_type = $value[$type]; | ||||
return false; | |||||
if ( !strlen($value_by_type) ) { | |||||
return null; | |||||
} | } | ||||
$options = $object->GetFieldOptions($search_field); | $options = $object->GetFieldOptions($search_field); | ||||
$dt_separator = array_key_exists('date_time_separator', $options) ? $options['date_time_separator'] : ' '; | $dt_separator = array_key_exists('date_time_separator', $options) ? $options['date_time_separator'] : ' '; | ||||
$value[$type] = trim($value[$type], $dt_separator); // trim any | $value_by_type = trim($value_by_type, $dt_separator); // trim any | ||||
$tmp_value = explode($dt_separator, $value[$type], 2); | $tmp_value = explode($dt_separator, $value_by_type, 2); | ||||
if ( count($tmp_value) == 1 ) { | if ( count($tmp_value) == 1 ) { | ||||
$time_format = $this->_getInputTimeFormat($options); | $time_format = $this->_getInputTimeFormat($options, $format_option_prefix . 'time_format'); | ||||
if ( $time_format ) { | if ( $time_format ) { | ||||
// time is missing, but time format available -> guess time and add to date | // time is missing, but time format available -> guess time and add to date | ||||
$time = ($type == 'from') ? adodb_mktime(0, 0, 0) : adodb_mktime(23, 59, 59); | $time = adodb_mktime(0, 0, 0); | ||||
$time = adodb_date($time_format, $time); | $time = adodb_date($time_format, $time); | ||||
$value[$type] .= $dt_separator . $time; | $value_by_type .= $dt_separator . $time; | ||||
} | } | ||||
} | } | ||||
/** @var kFormatter $formatter */ | /** @var kFormatter $formatter */ | ||||
$formatter = $this->Application->recallObject($options['formatter']); | $formatter = $this->Application->recallObject($options['formatter']); | ||||
$format = $options[$format_option_prefix . 'format']; | |||||
$value_ts = $formatter->Parse($value[$type], $search_field, $object); | $value_ts = $formatter->Parse($value_by_type, $search_field, $object, $format); | ||||
if ( $object->GetErrorPseudo($search_field) ) { | if ( $object->GetErrorPseudo($search_field) ) { | ||||
// invalid format -> ignore this date in search | // invalid format -> ignore this date in search | ||||
$object->RemoveError($search_field); | $object->RemoveError($search_field); | ||||
if ( $format_option_prefix == 'input_' ) { | |||||
return false; | return false; | ||||
} | } | ||||
return $this->processRangeField($object, $search_field, $value, $type, 'input_'); | |||||
} | |||||
return $value_ts; | return $value_ts; | ||||
} | } | ||||
/** | /** | ||||
* Returns InputTimeFormat using given field options | * Returns InputTimeFormat using given field options | ||||
* | * | ||||
* @param Array $field_options | * @param Array $field_options | ||||
* @param string $format_option_name Format option name. | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
function _getInputTimeFormat($field_options) | function _getInputTimeFormat($field_options, $format_option_name = 'input_time_format') | ||||
{ | { | ||||
if ( array_key_exists('input_time_format', $field_options) ) { | if ( array_key_exists($format_option_name, $field_options) ) { | ||||
return $field_options['input_time_format']; | return $field_options[$format_option_name]; | ||||
} | } | ||||
/** @var LanguagesItem $lang_current */ | /** @var LanguagesItem $lang_current */ | ||||
$lang_current = $this->Application->recallObject('lang.current'); | $lang_current = $this->Application->recallObject('lang.current'); | ||||
$field_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $format_option_name))); | |||||
return $lang_current->GetDBField('InputTimeFormat'); | return $lang_current->GetDBField($field_name); | ||||
} | } | ||||
/** | /** | ||||
* Resets current search | * Resets current search | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function resetSearch($event) | function resetSearch($event) | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |