39 $this->
id = $filterId;
41 $this->useCommonPresets =
false;
46 $this->useCommonPresets =
true;
48 $this->options[
"filters"] = $this->commonPresets[
"filters"] ??
null;
49 $this->options[
"deleted_presets"] = $this->commonPresets[
"deleted_presets"] ??
null;
52 if (!isset($this->options[
"use_pin_preset"]))
54 $this->options[
"use_pin_preset"] =
true;
57 if (!isset($this->options[
"deleted_presets"]) || !is_array($this->options[
"deleted_presets"]))
59 $this->options[
"deleted_presets"] = array();
62 if (!empty($filterPresets) && is_array($filterPresets))
64 $this->options[
"default_presets"] = $filterPresets;
68 $this->options[
"default_presets"] = array();
71 if (!isset($this->options[
"default"]) || empty($this->options[
"default"]) ||
72 ($this->options[
"default"] === self::DEFAULT_FILTER && $this->options[
"use_pin_preset"]))
77 if (!isset($this->options[
"filter"]) || empty($this->options[
"filter"]) || !is_string($this->options[
"filter"]))
79 $this->options[
"filter"] = $this->options[
"default"];
82 if (!isset($this->options[
"filters"]) || !is_array($this->options[
"filters"]))
84 $this->options[
"filters"] = $this->options[
"default_presets"];
88 if (is_array($this->options[
"filters"]))
90 foreach ($this->options[
"filters"] as $presetId =>
$options)
95 unset($this->options[
"filters"][$presetId][
"additional"]);
100 if (isset($this->options[
"update_default_presets"]) &&
101 $this->options[
"update_default_presets"] ==
true &&
102 !empty($filterPresets) &&
103 is_array($filterPresets))
105 $this->options[
"update_default_presets"] =
false;
108 foreach ($filterPresets as $key => $defaultPreset)
110 $this->options[
"filters"][$key] = $defaultPreset;
111 $this->options[
"filters"][$key][
"sort"] = $sort;
115 foreach ($this->options[
"filters"] as $key => $preset)
117 if (!array_key_exists($key, $filterPresets))
119 $this->options[
"filters"][$key][
"sort"] = $sort;
706 $resultFields = array();
707 foreach ($filterFields as $key => $field)
709 $isStrictField =
false;
711 foreach ($sourceFields as $sourceKey => $sourceField)
713 if (isset($sourceField[
"id"]) && $key === $sourceField[
"id"] && isset($sourceField[
"strict"]))
715 $isStrictField =
true;
719 if (($field !==
"" && mb_strpos($key, -6) !==
"_label") || $isStrictField)
721 if (self::isDateField($key))
724 $resultFields = array_merge($resultFields, $date);
727 elseif (self::isNumberField($key))
730 $resultFields = array_merge($resultFields, $number);
733 elseif (mb_substr($key, -5) !==
"_from" && mb_substr($key, -3) !==
"_to")
735 if (mb_substr($key, -8) ===
"_isEmpty")
737 $resultFields[substr($key, 0, -8)] =
false;
739 elseif (mb_substr($key, -12) ===
"_hasAnyValue")
742 $resultFields[
'!'.substr($key, 0, -12)] =
false;
746 $resultFields[$key] = $field;
752 return $resultFields;
1265 public static function calcDates($fieldId, $source, &$result)
1267 switch($source[$fieldId.
"_datesel"])
1271 $dateTime = Filter\DateTimeFactory::createToday();
1274 $result[$fieldId.
"_month"] = $dateTime->month();
1275 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1276 $result[$fieldId.
"_year"] = $dateTime->year();
1277 $result[$fieldId.
"_from"] = $dateTime->offset(
"- 1 days");
1278 $result[$fieldId.
"_to"] = $dateTime->offset(
"- 1 second");
1284 $dateTime = Filter\DateTimeFactory::createToday();
1287 $result[$fieldId.
"_month"] = $dateTime->month();
1288 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1289 $result[$fieldId.
"_year"] = $dateTime->year();
1290 $result[$fieldId.
"_from"] = $dateTime->toString();
1291 $result[$fieldId.
"_to"] = $dateTime->offset(
"+ 1 days - 1 second");
1297 $dateTime = Filter\DateTimeFactory::createToday();
1300 $result[$fieldId.
"_month"] = $dateTime->month();
1301 $result[$fieldId.
"_year"] = $dateTime->year();
1302 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1303 $result[$fieldId.
"_from"] = $dateTime->offset(
"+ 1 days");
1304 $result[$fieldId.
"_to"] = $dateTime->offset(
"+ 2 days - 1 second");
1310 $dateTime = Filter\DateTimeFactory::createCurrentWeekMonday();
1313 $result[$fieldId.
"_month"] = $dateTime->month();
1314 $result[$fieldId.
"_year"] = $dateTime->year();
1315 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1316 $result[$fieldId.
"_from"] = $dateTime->toString();
1317 $result[$fieldId.
"_to"] = $dateTime->offset(
"7 days - 1 second");
1323 $dateTime = Filter\DateTimeFactory::createNextWeekMonday();
1326 $result[$fieldId.
"_month"] = $dateTime->month();
1327 $result[$fieldId.
"_year"] = $dateTime->year();
1328 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1329 $result[$fieldId.
"_from"] = $dateTime->toString();
1330 $result[$fieldId.
"_to"] = $dateTime->offset(
"7 days - 1 second");
1336 $dateTime = Filter\DateTimeFactory::createFirstDayOfCurrentMonth();
1339 $result[$fieldId.
"_month"] = $dateTime->month();
1340 $result[$fieldId.
"_year"] = $dateTime->year();
1341 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1342 $result[$fieldId.
"_from"] = $dateTime->toString();
1343 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 month - 1 second");
1349 $dateTime = Filter\DateTimeFactory::createFirstDayOfNextMonth();
1352 $result[$fieldId.
"_month"] = $dateTime->month();
1353 $result[$fieldId.
"_year"] = $dateTime->year();
1354 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1355 $result[$fieldId.
"_from"] = $dateTime->toString();
1356 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 month - 1 second");
1362 $dateTime = Filter\DateTimeFactory::createToday();
1365 $result[$fieldId.
"_month"] = $dateTime->month();
1366 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1367 $result[$fieldId.
"_year"] = $dateTime->year();
1368 $result[$fieldId.
"_from"] = $dateTime->quarterStart();
1369 $result[$fieldId.
"_to"] = $dateTime->quarterEnd();
1375 $dateTime = Filter\DateTimeFactory::createToday();
1378 $result[$fieldId.
"_month"] = $dateTime->month();
1379 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1380 $result[$fieldId.
"_year"] = $dateTime->year();
1381 $result[$fieldId.
"_from"] = $dateTime->offset(
"- 7 days");
1382 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days - 1 second");
1388 $dateTime = Filter\DateTimeFactory::createToday();
1391 $result[$fieldId.
"_month"] = $dateTime->month();
1392 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1393 $result[$fieldId.
"_year"] = $dateTime->year();
1394 $result[$fieldId.
"_from"] = $dateTime->offset(
"- 30 days");
1395 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days - 1 second");
1401 $dateTime = Filter\DateTimeFactory::createToday();
1404 $result[$fieldId.
"_month"] = $dateTime->month();
1405 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1406 $result[$fieldId.
"_year"] = $dateTime->year();
1407 $result[$fieldId.
"_from"] = $dateTime->offset(
"- 60 days");
1408 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days - 1 second");
1414 $dateTime = Filter\DateTimeFactory::createToday();
1417 $result[$fieldId.
"_month"] = $dateTime->month();
1418 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1419 $result[$fieldId.
"_year"] = $dateTime->year();
1420 $result[$fieldId.
"_from"] = $dateTime->offset(
"- 90 days");
1421 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days - 1 second");
1427 $month = $source[$fieldId.
"_month"];
1428 $year = $source[$fieldId.
"_year"];
1430 if (!empty($month) && !empty($year))
1432 $dateTime =
new Filter\DateTime(mktime(0, 0, 0, $month, 1, $year));
1435 $result[$fieldId.
"_month"] = $dateTime->month();
1436 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1437 $result[$fieldId.
"_year"] = $dateTime->year();
1438 $result[$fieldId.
"_from"] = $dateTime->toString();
1439 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 month - 1 second");
1447 if (is_numeric($source[$fieldId.
"_days"]))
1449 $dateTime = Filter\DateTimeFactory::createToday();
1450 $days = (int) $source[$fieldId.
"_days"];
1451 $days = $days > 0 ? ($days + 1) : $days;
1454 $result[$fieldId.
"_month"] = $dateTime->month();
1455 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1456 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1457 $result[$fieldId.
"_year"] = $dateTime->year();
1458 $result[$fieldId.
"_from"] = $dateTime->offset(
"1 days");
1459 $result[$fieldId.
"_to"] = $dateTime->offset($days.
" days - 1 second");
1467 if (is_numeric($source[$fieldId.
"_days"]))
1469 $dateTime = Filter\DateTimeFactory::createToday();
1470 $days = (int) $source[$fieldId.
"_days"];
1471 $days = max($days, 0);
1474 $result[$fieldId.
"_month"] = $dateTime->month();
1475 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1476 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1477 $result[$fieldId.
"_year"] = $dateTime->year();
1478 $result[$fieldId.
"_from"] = $dateTime->offset(
"- ".$days.
" days");
1479 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days -1 second");
1487 if (is_numeric($source[$fieldId.
"_days"]))
1489 $dateTime = Filter\DateTimeFactory::createToday();
1490 $days = (int) $source[$fieldId.
"_days"];
1492 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1493 $result[$fieldId.
"_from"] = $dateTime->offset(-$days.
" days");
1494 $result[$fieldId.
"_to"] = $dateTime->offset(-($days-1).
" days -1 second");
1502 if (is_numeric($source[$fieldId.
"_days"]))
1504 $dateTime = Filter\DateTimeFactory::createToday();
1505 $days = (int) $source[$fieldId.
"_days"];
1507 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1508 $result[$fieldId.
"_from"] = $dateTime->offset($days.
" days");
1509 $result[$fieldId.
"_to"] = $dateTime->offset(($days+1).
" days -1 second");
1517 if (is_numeric($source[$fieldId.
"_days"]))
1519 $dateTime = Filter\DateTimeFactory::createToday();
1520 $days = (int) $source[$fieldId.
"_days"];
1522 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1523 $result[$fieldId.
"_from"] = $dateTime->offset(-($days+1).
" days");
1524 $result[$fieldId.
"_to"] = $dateTime->offset(-$days.
" days -1 second");
1532 if (is_numeric($source[$fieldId.
"_days"]))
1534 $dateTime = Filter\DateTimeFactory::createToday();
1535 $days = (int) $source[$fieldId.
"_days"];
1537 $result[$fieldId.
"_days"] = $source[$fieldId.
"_days"];
1538 $result[$fieldId.
"_from"] = $dateTime->offset($days.
" days");
1539 $result[$fieldId.
"_to"] = $dateTime->offset(($days+1).
" days -1 second");
1548 $quarter = $source[$fieldId.
"_quarter"];
1549 $year = $source[$fieldId.
"_year"];
1551 if (!empty($quarter) && !empty($year))
1556 $result[$fieldId.
"_quarter"] = $dateTime->quarter();
1557 $result[$fieldId.
"_year"] = $dateTime->year();
1558 $result[$fieldId.
"_month"] = $dateTime->month();
1559 $result[$fieldId.
"_from"] = $dateTime->quarterStart();
1560 $result[$fieldId.
"_to"] = $dateTime->quarterEnd();
1568 $year = $source[$fieldId.
"_year"];
1572 $dateTime =
new Filter\DateTime(mktime(0, 0, 0, 1, 1, $year));
1575 $result[$fieldId.
"_year"] = $dateTime->year();
1576 $result[$fieldId.
"_from"] = $dateTime->toString();
1577 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 year - 1 second");
1585 $sourceDate = $source[$fieldId.
"_from"];
1587 if (!empty($sourceDate))
1589 $date =
new Date($sourceDate);
1590 $dateTime =
new Filter\DateTime(MakeTimeStamp($sourceDate));
1594 if ($dateTime->getTimestamp() > $date->getTimestamp())
1596 $result[$fieldId.
"_from"] = $dateTime->toString();
1597 $result[$fieldId.
"_to"] = $dateTime->toString();
1601 $result[$fieldId.
"_from"] = $dateTime->toString();
1602 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 days - 1 second");
1611 $dateTime = Filter\DateTimeFactory::createLastWeekMonday();
1614 $result[$fieldId.
"_from"] = $dateTime->toString();
1615 $result[$fieldId.
"_to"] = $dateTime->offset(
"7 days - 1 second");
1621 $dateTime = Filter\DateTimeFactory::createFirstDayOfLastMonth();
1624 $result[$fieldId.
"_year"] = $dateTime->year();
1625 $result[$fieldId.
"_month"] = $dateTime->month();
1626 $result[$fieldId.
"_from"] = $dateTime->toString();
1627 $result[$fieldId.
"_to"] = $dateTime->offset(
"1 month - 1 second");
1633 $startSourceDate = $source[$fieldId.
"_from"];
1634 $endSourceDate = $source[$fieldId.
"_to"];
1636 $result[$fieldId.
"_from"] =
"";
1637 $result[$fieldId.
"_to"] =
"";
1639 if (!empty($startSourceDate))
1641 $startDateTime =
new Filter\DateTime(MakeTimeStamp($startSourceDate));
1644 $result[$fieldId.
"_from"] = $startDateTime->toString();
1647 if (!empty($endSourceDate))
1649 $endDate = Date::createFromTimestamp(MakeTimeStamp($endSourceDate));
1650 $endDateTime =
new Filter\DateTime(MakeTimeStamp($endSourceDate));
1654 if ($endDateTime->getTimestamp() > $endDate->getTimestamp())
1656 $result[$fieldId.
"_to"] = $endDateTime->toString();
1660 $result[$fieldId.
"_to"] = $endDateTime->offset(
"1 days - 1 second");