31 $this->
getId() .
'_datesel',
35 $allowYearName = $this->getAllowYearName();
36 if (!isset($result[$allowYearName]) && isset($filterFields[$allowYearName]))
38 $result[$allowYearName] = $filterFields[$allowYearName];
46 if (!$this->isCustomDate())
52 foreach([
'days',
'month',
'year'] as $key)
54 $fieldKey = $this->
getId() .
'_' . $key;
55 if (empty($filterFields[$fieldKey]))
60 $result[$fieldKey] = $filterFields[$fieldKey];
75 $from = $this->isMoreThanDaysAgo() ? null : $this->
getFrom();
76 $to = $this->isAfterDays() ? null : $this->
getTo();
80 if ($this->isAllowYears())
82 $filter[
">=$filterKey"] = $from;
86 $filter[] = $this->getFilterYearLess(
'FROM', $from,
">=");
91 if ($this->isAllowYears())
93 $filter[
"<=$filterKey"] = $to;
97 $filter[] = $this->getFilterYearLess(
'TO', $to,
"<=", $from);
102 $fieldId = $this->
getId();
103 $filterKey = $this->
getId() .
'_EXPR_DAYS';
110 'name' => $filterKey,
111 'expression' =>
"EXTRACT(DAY from %s)",
112 'buildFrom' => [$fieldId],
118 $fieldId = $this->
getId();
119 $filterKey = $this->
getId() .
'_EXPR_MONTHS';
126 'name' => $filterKey,
127 'expression' =>
"EXTRACT(MONTH from %s)",
128 'buildFrom' => [$fieldId],
134 $fieldId = $this->
getId();
135 $filterKey = $this->
getId() .
'_EXPR_YEARS';
142 'name' => $filterKey,
143 'expression' =>
"EXTRACT(YEAR from %s)",
144 'buildFrom' => [$fieldId],
158 return $this->getDate($defaultValue,
true);
167 public function getTo($defaultValue =
null)
169 return $this->getDate($defaultValue,
false);
179 return $this->getCustomDateData(
'days');
189 return $this->getCustomDateData(
'month');
199 return $this->getCustomDateData(
'year');
202 private function getCustomDateData($key)
204 $value = $this->getDateDataByKey($key);
205 if (!$value || !is_array($value))
219 private function isMoreThanDaysAgo()
224 private function isAfterDays()
229 private function getDateDataByKey($key)
231 $key = $this->
getId() .
'_' . $key;
233 if (!is_array($value) || count($value) === 0)
238 if (empty($value[$key]))
246 private function getDate($defaultValue =
null, $isFrom =
true)
248 $name = $this->
getId();
250 if (!is_array($value) || count($value) === 0)
252 return $defaultValue;
260 return isset($calcData[$name .
'_from']) ? $calcData[$name .
'_from'] : $defaultValue;
264 return isset($calcData[$name .
'_to']) ? $calcData[$name .
'_to'] : $defaultValue;
268 private function isCustomDate()
273 private function isAllowYears()
275 if (!isset($this->data[
'allow_years_switcher']) || !$this->data[
'allow_years_switcher'])
280 return !empty($this->data[
'value'][$this->getAllowYearName()]);
283 private function getAllowYearName()
285 return $this->
getId() .
'_allow_year';
288 private function getFilterYearLess($tag, $value, $operation =
"=", $fromValue =
null)
291 $date =
new Date($value);
294 $dateFrom =
new Date($fromValue);
295 if ($dateFrom->getTimestamp() > $date->getTimestamp())
301 $fieldId = $this->
getId();
302 $expressionFieldName = $fieldId .
"_YEAR_LESS_" . $tag;
306 $uf = explode(
'.', $filterKey);
307 foreach ($uf as $item)
309 if (mb_strpos($item,
'UF_') !== 0)
314 $userField = UserFieldTable::getRow([
315 'select' => [
'USER_TYPE_ID',
'MULTIPLE'],
316 'filter' => [
'=FIELD_NAME' => $item]
318 if (!$userField || $userField[
'USER_TYPE_ID'] !=
'date')
322 if ($userField[
'MULTIPLE'] !=
'Y')
327 $filterKey .=
'_SINGLE';
333 $charDate = $sqlHelper->getConcatFunction(
334 "(EXTRACT(YEAR from %s) $addOneYear)",
335 "'-{$date->format('m')}-{$date->format('d')}'"
337 $sqlDate = $sqlHelper->getDatetimeToDateFunction($charDate);
339 return (
new RuntimeFilter())
341 "=$expressionFieldName",
345 'name' => $expressionFieldName,
346 'expression' =>
"case when %s $operation $sqlDate then 1 else 0 end",
static getConnection($name="")
static fetchDateFieldValue($key="", $filterFields=array())
static calcDates($fieldId, $source, &$result)