Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
options.php
1<?
2
4
5
11
12
18{
19 protected $id;
20 protected $options;
21 protected $commonPresets;
24 protected $request;
25 protected ?string $currentFilterPresetId = null;
26
27 const DEFAULT_FILTER = "default_filter";
28 const TMP_FILTER = "tmp_filter";
29
30
37 public function __construct($filterId, $filterPresets = array(), $commonPresetsId = null)
38 {
39 $this->id = $filterId;
40 $this->options = $this->fetchOptions($this->id);
41 $this->useCommonPresets = false;
42
43 if (!empty($commonPresetsId) && is_string($commonPresetsId))
44 {
45 $this->commonPresets = static::fetchCommonPresets($commonPresetsId);
46 $this->useCommonPresets = true;
47 $this->commonPresetsId = $commonPresetsId;
48 $this->options["filters"] = $this->commonPresets["filters"] ?? null;
49 $this->options["deleted_presets"] = $this->commonPresets["deleted_presets"] ?? null;
50 }
51
52 if (!isset($this->options["use_pin_preset"]))
53 {
54 $this->options["use_pin_preset"] = true;
55 }
56
57 if (!isset($this->options["deleted_presets"]) || !is_array($this->options["deleted_presets"]))
58 {
59 $this->options["deleted_presets"] = array();
60 }
61
62 if (!empty($filterPresets) && is_array($filterPresets))
63 {
64 $this->options["default_presets"] = $filterPresets;
65 }
66 else
67 {
68 $this->options["default_presets"] = array();
69 }
70
71 if (!isset($this->options["default"]) || empty($this->options["default"]) ||
72 ($this->options["default"] === self::DEFAULT_FILTER && $this->options["use_pin_preset"]))
73 {
74 $this->options["default"] = self::findDefaultPresetId($this->options["default_presets"]);
75 }
76
77 if (!isset($this->options["filter"]) || empty($this->options["filter"]) || !is_string($this->options["filter"]))
78 {
79 $this->options["filter"] = $this->options["default"];
80 }
81
82 if (!isset($this->options["filters"]) || !is_array($this->options["filters"]))
83 {
84 $this->options["filters"] = $this->options["default_presets"];
85 }
86
87 // Move additional fields from options to session
88 if (is_array($this->options["filters"]))
89 {
90 foreach ($this->options["filters"] as $presetId => $options)
91 {
92 if (isset($options["additional"]) && is_array($options["additional"]))
93 {
94 $this->setAdditionalPresetFields($presetId, $options["additional"]);
95 unset($this->options["filters"][$presetId]["additional"]);
96 }
97 }
98 }
99
100 if (isset($this->options["update_default_presets"]) &&
101 $this->options["update_default_presets"] == true &&
102 !empty($filterPresets) &&
103 is_array($filterPresets))
104 {
105 $this->options["update_default_presets"] = false;
106 $sort = 0;
107
108 foreach ($filterPresets as $key => $defaultPreset)
109 {
110 $this->options["filters"][$key] = $defaultPreset;
111 $this->options["filters"][$key]["sort"] = $sort;
112 $sort++;
113 }
114
115 foreach ($this->options["filters"] as $key => $preset)
116 {
117 if (!array_key_exists($key, $filterPresets))
118 {
119 $this->options["filters"][$key]["sort"] = $sort;
120 $sort++;
121 }
122 }
123 }
124 }
125
126
130 public function getCommonPresetsId()
131 {
133 }
134
135
139 public function isUseCommonPresets()
140 {
142 }
143
144
149 public function getId()
150 {
151 return $this->id;
152 }
153
154
159 public function setPresets($presets = array())
160 {
161 $this->options["filters"] = $presets;
162 }
163
164
169 public function setCurrentPreset($presetId = "default_filter")
170 {
171 $this->options["filter"] = $presetId;
172 }
173
174
179 public function getDefaultPresets()
180 {
181 return $this->options["default_presets"];
182 }
183
184
189 public function getPresets()
190 {
191 return $this->options["filters"];
192 }
193
194
199 public function setDefaultPreset($presetId = "default_filter")
200 {
201 $this->options["default"] = $presetId;
202 }
203
204
209 public function isUsePinPreset()
210 {
211 return $this->options["use_pin_preset"];
212 }
213
214
219 public function setDefaultPresets($presets = array())
220 {
221 $this->options["default_presets"] = $presets;
222 }
223
224
229 public function setDeletedPresets($deletedPresets = array())
230 {
231 $this->options["deleted_presets"] = $deletedPresets;
232 }
233
234
239 public function setUsePinPreset($value = true)
240 {
241 $this->options["use_pin_preset"] = $value;
242 }
243
244
250 public static function fetchCommonPresets($id)
251 {
252 global $USER;
253
254 if ($USER->isAuthorized() ||
255 (!$USER->isAuthorized() && !isset(Application::getInstance()->getSession()["main.ui.filter.presets"][$id])))
256 {
257 $options = \CUserOptions::getOption("main.ui.filter.presets", $id, array(), self::getUserId());
258 }
259 else
260 {
261 $options = Application::getInstance()->getSession()["main.ui.filter.presets"][$id];
262 }
263
264 return $options;
265
266 }
267
268
274 public function fetchOptions($id)
275 {
276 global $USER;
277
278 if ($USER->isAuthorized() ||
279 (!$USER->isAuthorized() && !isset(Application::getInstance()->getSession()["main.ui.filter"][$this->getId()]["options"])))
280 {
281 $options = \CUserOptions::getOption("main.ui.filter", $id, array(), self::getUserId());
282
283 if (empty($options))
284 {
285 $options = \CUserOptions::getOption("main.ui.filter.common", $id, array(), 0);
286 }
287 }
288 else
289 {
290 $options = Application::getInstance()->getSession()["main.ui.filter"][$this->getId()]["options"];
291 }
292
293 return $options;
294 }
295
296
297 protected static function getUserId()
298 {
299 global $USER;
300 $userId = 0;
301
302 if ($USER->isAuthorized())
303 {
304 $userId = $USER->getID();
305 }
306
307 return $userId;
308 }
309
310
311 protected function getRequest()
312 {
313 return Context::getCurrent()->getRequest();
314 }
315
316
322 public static function findDefaultPresetId($presets = array())
323 {
324 $result = "default_filter";
325
326 if (!empty($presets) && is_array($presets))
327 {
328 foreach ($presets as $presetId => $preset)
329 {
330 if (isset($preset["default"]) && $preset["default"])
331 {
332 $result = $presetId;
333 }
334 }
335 }
336
337 return $result;
338 }
339
340
345 public function getOptions()
346 {
347 return $this->options;
348 }
349
350
355 public function pinPreset($presetId = "default_filter")
356 {
357 if ($presetId === "default_filter")
358 {
359 $this->options["use_pin_preset"] = false;
360 }
361 else
362 {
363 $this->options["use_pin_preset"] = true;
364 }
365
366 $this->options["default"] = $presetId;
367 }
368
369
376 public static function isSetFromRequest(HttpRequest $request)
377 {
378 $applyFilter = $request->get("apply_filter");
379 $isAjaxRequest = $request->get("ajax_request");
380
381 return $applyFilter !== null && $isAjaxRequest === null && !$request->isAjaxRequest();
382 }
383
384
392 public static function fetchSettingsFromQuery($fields, HttpRequest $request)
393 {
394 $result = array("fields" => array(), "rows" => array());
395
396 foreach ($fields as $key => $field)
397 {
398 $id = $field["id"];
399 $fromId = $id."_from";
400 $toId = $id."_to";
401 $quarterId = $id."_quarter";
402 $yearId = $id."_year";
403 $monthId = $id."_month";
404 $daysId = $id."_days";
405 $nameId = $id."_name";
406 $labelId = $id."_label";
407 $valueId = $id."_value";
408 $dateselId = $id."_datesel";
409 $numselId = $id."_numsel";
410 $type = $field["type"] ?? null;
411 $isEmpty = $id."_isEmpty";
412 $hasAnyValue = $id."_hasAnyValue";
413
414 if ($type == "date")
415 {
416 if ($request[$dateselId] !== null && ($request[$fromId] !== null ||
417 $request[$toId] !== null ||
418 $request[$quarterId] !== null ||
419 $request[$yearId] !== null ||
420 $request[$daysId] !== null ||
421 $request[$monthId] !== null))
422 {
423 $result["fields"][$dateselId] = $request[$dateselId];
424 $result["fields"][$fromId] = $request[$fromId] !== null ? $request[$fromId] : "";
425 $result["fields"][$toId] = $request[$toId] !== null ? $request[$toId] : "";
426 $result["fields"][$yearId] = $request[$yearId] !== null ? $request[$yearId] : "";
427 $result["fields"][$monthId] = $request[$monthId] !== null ? $request[$monthId] : "";
428 $result["fields"][$daysId] = $request[$daysId] !== null ? $request[$daysId] : "";
429 $result["rows"][] = $id;
430 }
431 }
432 else if ($type == "number")
433 {
434 if ($request[$numselId] !== null && ($request[$fromId] !== null || $request[$toId]))
435 {
436 $result["fields"][$numselId] = $request[$numselId];
437 $result["fields"][$fromId] = $request[$fromId] !== null ? $request[$fromId] : "";
438 $result["fields"][$toId] = $request[$toId] !== null ? $request[$toId] : "";
439 $result["rows"][] = $id;
440 }
441 }
442 else if ($type == "custom_entity")
443 {
444 if ($request[$id] !== null)
445 {
446 if ($request[$id] !== null || $request[$labelId] !== null)
447 {
448 $result["fields"][$labelId] = ($request[$nameId] !== null ?
449 $request[$nameId] : $request[$labelId]);
450 }
451 $result["fields"][$id] = $request[$id];
452 $result["rows"][] = $id;
453 }
454 }
455 else if ($type == "dest_selector" || $type == "entity_selector")
456 {
457 if ($request[$id] !== null)
458 {
459 $result["fields"][$id] = $request[$id];
460 $result["rows"][] = $id;
461 }
462 }
463 else
464 {
465 if ($request[$id] !== null)
466 {
467 $result["fields"][$id] = $request[$id];
468 $result["rows"][] = $id;
469 }
470 }
471
472 if (isset($request[$isEmpty]))
473 {
474 $result['fields'][$isEmpty] = $request[$isEmpty];
475 $result["rows"][] = $id;
476 }
477
478 if (isset($request[$hasAnyValue]))
479 {
480 $result['fields'][$hasAnyValue] = $request[$hasAnyValue];
481 $result["rows"][] = $id;
482 }
483 }
484
485 if ($request["FIND"] !== null)
486 {
487 $result["fields"]["FIND"] = $request["FIND"];
488 }
489
490 if (empty($result["fields"]) && empty($result["rows"]))
491 {
492 $result = null;
493 }
494
495 return $result;
496 }
497
498
503 public function getSessionFilterId()
504 {
505 $session = Application::getInstance()->getSession();
506
507 return $session["main.ui.filter"][$this->getId()]["filter"] ?? null;
508 }
509
510 public function isSetOutside(): bool
511 {
512 $session = Application::getInstance()->getSession();
513
514 return filter_var(
515 $session["main.ui.filter"][$this->getId()]["isSetOutside"] ?? false,
516 FILTER_VALIDATE_BOOLEAN
517 );
518 }
519
520
526 public function getAdditionalPresetFields($presetId)
527 {
528 $session = Application::getInstance()->getSession();
529 $additional = $session["main.ui.filter"][$this->getId()]["filters"][$presetId]["additional"] ?? [];
530
531 return is_array($additional) ? $additional : [];
532 }
533
534
540 public function setAdditionalPresetFields($presetId, $additional = array())
541 {
542 Application::getInstance()->getSession()["main.ui.filter"][$this->getId()]["filters"][$presetId]["additional"] = $additional;
543 }
544
545
550 public function getDefaultFilterId()
551 {
552 return $this->options["default"];
553 }
554
555
560 public function getCurrentFilterId()
561 {
562 $sessionFilterId = ($this->getCurrentFilterPresetId() ?? $this->getSessionFilterId());
563 $defaultFilterId = $this->getDefaultFilterId();
564 return !empty($sessionFilterId) ? $sessionFilterId : $defaultFilterId;
565 }
566
567
568 protected function trySetFilterFromRequest($fields = array())
569 {
570 $request = $this->getRequest();
571
572 if (self::isSetFromRequest($request))
573 {
574 $settings = self::fetchSettingsFromQuery($fields, $this->getRequest());
575 $clear = mb_strtoupper($request->get("clear_filter")) == "Y";
576
577 if ($settings !== null || $clear)
578 {
579 $presetId = $clear ? self::DEFAULT_FILTER : self::TMP_FILTER;
580
581 $this->setFilterSettings($presetId, $settings);
582 $this->save();
583 }
584 }
585 }
586
587
593 public function getFilterSettings($presetId)
594 {
595 return $this->options["filters"][$presetId] ?? null;
596 }
597
598
605 protected static function fetchFieldsFromFilterSettings($filterSettings = array(), $additionalFields = array())
606 {
607 $filterFields = array();
608
609 if (is_array($filterSettings))
610 {
611 if (is_array($filterSettings["fields"]))
612 {
613 $filterFields = $filterSettings["fields"];
614 }
615
616 if (is_array($additionalFields))
617 {
618 $filterFields = array_merge($filterFields, $additionalFields);
619 }
620 }
621
622 return $filterFields;
623 }
624
625
630 public static function isDateField($key = "")
631 {
632 return is_string($key) && mb_substr($key, -8) === "_datesel";
633 }
634
635
643 public static function fetchDateFieldValue($key = "", $filterFields = array())
644 {
645 $date = array();
646 $date[$key] = $filterFields[$key];
647
648 $cleanKey = str_replace("_datesel", "", $key);
649
650 self::calcDates($cleanKey, $filterFields, $date);
651
652 if (!isset($date[$cleanKey . "_from"]) && !isset($date[$cleanKey . "_to"]))
653 {
654 unset($date[$cleanKey . "_datesel"]);
655 unset($date[$cleanKey . "_to"]);
656 unset($date[$cleanKey . "_from"]);
657 }
658
659 return $date;
660 }
661
662
670 public static function fetchNumberFieldValue($key = "", $filterFields = array())
671 {
672 $number = array();
673 $number[$key] = $filterFields[$key];
674 $cleanKey = str_replace("_numsel", "", $key);
675
676 if (array_key_exists($cleanKey . "_from", $filterFields))
677 {
678 $number[$cleanKey . "_from"] = $filterFields[$cleanKey . "_from"];
679 }
680
681 if (array_key_exists($cleanKey . "_to", $filterFields))
682 {
683 $number[$cleanKey . "_to"] = $filterFields[$cleanKey . "_to"];
684 }
685
686 if ($number[$cleanKey . "_from"] === "" && $number[$cleanKey . "_to"] === "")
687 {
688 unset($number[$cleanKey . "_from"]);
689 unset($number[$cleanKey . "_to"]);
690 unset($number[$cleanKey . "_numsel"]);
691 }
692
693 return $number;
694 }
695
696
697 public static function isNumberField($key = "")
698 {
699 return is_string($key) && mb_substr($key, -7) === "_numsel";
700 }
701
702
703 public static function fetchFieldValuesFromFilterSettings($filterSettings = array(), $additionalFields = array(), $sourceFields = array())
704 {
705 $filterFields = self::fetchFieldsFromFilterSettings($filterSettings, $additionalFields);
706 $resultFields = array();
707 foreach ($filterFields as $key => $field)
708 {
709 $isStrictField = false;
710
711 foreach ($sourceFields as $sourceKey => $sourceField)
712 {
713 if (isset($sourceField["id"]) && $key === $sourceField["id"] && isset($sourceField["strict"]))
714 {
715 $isStrictField = true;
716 }
717 }
718
719 if (($field !== "" && mb_strpos($key, -6) !== "_label") || $isStrictField)
720 {
721 if (self::isDateField($key))
722 {
723 $date = self::fetchDateFieldValue($key, $filterFields);
724 $resultFields = array_merge($resultFields, $date);
725 }
726
727 elseif (self::isNumberField($key))
728 {
729 $number = self::fetchNumberFieldValue($key, $filterFields);
730 $resultFields = array_merge($resultFields, $number);
731 }
732
733 elseif (mb_substr($key, -5) !== "_from" && mb_substr($key, -3) !== "_to")
734 {
735 if (mb_substr($key, -8) === "_isEmpty")
736 {
737 $resultFields[substr($key, 0, -8)] = false;
738 }
739 elseif (mb_substr($key, -12) === "_hasAnyValue")
740 {
741
742 $resultFields['!'.substr($key, 0, -12)] = false;
743 }
744 else
745 {
746 $resultFields[$key] = $field;
747 }
748 }
749 }
750 }
751
752 return $resultFields;
753 }
754
755
760 public static function isDefaultFilter($presetId = "")
761 {
762 return $presetId === self::DEFAULT_FILTER;
763 }
764
770 public function getFilter($sourceFields = array())
771 {
772 $result = array();
773 $this->trySetFilterFromRequest($sourceFields);
774 $currentPresetId = $this->getCurrentFilterId();
775
776 if (!self::isDefaultFilter($currentPresetId))
777 {
778 $filterSettings = $this->getFilterSettings($currentPresetId);
779 $additionalFields = $this->getAdditionalPresetFields($currentPresetId);
780 $fieldsValues = self::fetchFieldValuesFromFilterSettings($filterSettings, $additionalFields, $sourceFields);
781
782 $result = $fieldsValues;
783 $searchString = $this->getSearchString();
784
785 if (!empty($result) || $searchString !== "")
786 {
787 $result["PRESET_ID"] = $currentPresetId;
788 $result["FILTER_ID"] = $currentPresetId;
789 $result["FILTER_APPLIED"] = true;
790 $result["FIND"] = $this->getSearchString();
791 }
792 }
793 return $result;
794 }
795
801 public function getFilterLogic($sourceFields = array())
802 {
803 $filter = $this->getFilter($sourceFields);
804 $applied = ($filter["FILTER_APPLIED"] ?? false);
805 if ($applied === true)
806 {
807 return Type::getLogicFilter($filter, $sourceFields);
808 }
809 return [];
810 }
811
816 public function getSearchString()
817 {
818 $session = Application::getInstance()->getSession();
819 $search = $session["main.ui.filter"][$this->id]["filter_search"] ?? '';
820
821 return is_string($search) ? $search : "";
822 }
823
824
828 public function save()
829 {
830 global $USER;
831
832 if ($this->isUseCommonPresets())
833 {
834 $presets = array(
835 "filters" => $this->options["filters"],
836 "deleted_presets" => $this->options["deleted_presets"]
837 );
838
839 if ($USER->isAuthorized())
840 {
841 \CUserOptions::setOption("main.ui.filter.presets", $this->getCommonPresetsId(), $presets);
842 }
843 else
844 {
845 Application::getInstance()->getSession()["main.ui.filter.presets"][$this->getCommonPresetsId()] = $presets;
846 }
847 }
848
849
850 if ($USER->isAuthorized())
851 {
852 \CUserOptions::setOption("main.ui.filter", $this->getId(), $this->options);
853 }
854 else
855 {
856 Application::getInstance()->getSession()["main.ui.filter"][$this->getId()]["options"] = $this->options;
857 }
858 }
859
860
867 public function getAllUserOptions()
868 {
869 return \CUserOptions::getList(null, array("CATEGORY" => "main.ui.filter", "NAME" => $this->getId()));
870 }
871
872
876 public static function isCurrentUserEditOtherSettings()
877 {
878 global $USER;
879 return $USER->CanDoOperation("edit_other_settings");
880 }
881
882
886 public function saveForAll()
887 {
888 global $USER;
889
890 if (self::isCurrentUserEditOtherSettings())
891 {
892 $allUserOptions = $this->getAllUserOptions();
893
894 if ($allUserOptions)
895 {
896 $currentOptions = $this->options;
897
898 $forAllPresets = array();
899
900 foreach ($currentOptions["filters"] as $key => $preset)
901 {
902 if ($preset["for_all"])
903 {
904 $forAllPresets[$key] = $preset;
905 }
906 }
907
908 while ($userOptions = $allUserOptions->fetch())
909 {
910 $currentUserOptions = unserialize($userOptions["VALUE"], ['allowed_classes' => false]);
911
912 if (is_array($currentUserOptions))
913 {
914 if (!self::isCommon($userOptions))
915 {
916 $currentUserOptions["deleted_presets"] = $currentOptions["deleted_presets"];
917 $currentUserOptions["filters"] = $forAllPresets;
918
919 if (!$USER->CanDoOperation("edit_other_settings", $userOptions["USER_ID"]))
920 {
921 $currentUserOptions["default_presets"] = $forAllPresets;
922 }
923 }
924
925 $this->saveOptionsForUser($currentUserOptions, $userOptions["USER_ID"]);
926 }
927 }
928
929 $this->saveCommon();
930 }
931
932 }
933 }
934
935
941 public static function isCommon($options)
942 {
943 return isset($options["USER_ID"]) && $options["USER_ID"] == 0;
944 }
945
946
952 public function saveOptionsForUser($options, $userId)
953 {
954 if ($this->isUseCommonPresets())
955 {
956 $presets = array(
957 "filters" => $options["filters"],
958 "deleted_presets" => $options["deleted_presets"]
959 );
960
961 \CUserOptions::SetOption("main.ui.filter.presets", $this->getCommonPresetsId(), $presets, null, $userId);
962 }
963
964 $userOptions = \CUserOptions::GetOption("main.ui.filter", $this->getId(), array("filters" => array(), "default_presets" => array()), $userId);
965
966 if (is_array($options["deleted_presets"]))
967 {
968 foreach ($options["deleted_presets"] as $key => $isDeleted)
969 {
970 if (array_key_exists($key, $userOptions["filters"]))
971 {
972 unset($userOptions["filters"][$key]);
973 }
974 }
975 }
976
977 $options["filters"] = array_merge($userOptions["filters"], $options["filters"]);
978 \CUserOptions::SetOption("main.ui.filter", $this->getId(), $options, null, $userId);
979 }
980
981
985 public function saveCommon()
986 {
987 $presets = array();
988 $options = $this->getOptions();
989
990 foreach ($options["filters"] as $key => $preset)
991 {
992 if ($preset["for_all"])
993 {
994 $presets[$key] = $preset;
995 }
996 }
997
998 $options["filters"] = $presets;
999
1000 \CUserOptions::setOption("main.ui.filter.common", $this->id, $options, true);
1001 }
1002
1003
1009 public function setFilterRows($presetId, $rows)
1010 {
1011 $aColsTmp = explode(",", $rows);
1012 $aCols = array();
1013 foreach($aColsTmp as $col)
1014 if(($col = trim($col)) <> "")
1015 $aCols[] = $col;
1016 if($presetId <> '')
1017 $this->options["filters"][$presetId]["filter_rows"] = implode(",", $aCols);
1018 else
1019 $this->options["filter_rows"] = implode(",", $aCols);
1020 }
1021
1022 public function removeRowFromPreset(string $presetId, string $rowName): bool
1023 {
1024 $rowsString = $this->options["filters"][$presetId]["filter_rows"] ?? '';
1025 if ($rowsString === '')
1026 {
1027 return false;
1028 }
1029 $rows = explode(",", $rowsString);
1030 $pos = array_search($rowName, $rows,true);
1031 if ($pos !== false)
1032 {
1033 unset($rows[$pos]);
1034 $this->options["filters"][$presetId]["filter_rows"] = implode(",", $rows);
1035
1036 return true;
1037 }
1038
1039 return false;
1040 }
1041
1046 public function restore($settings = array())
1047 {
1048 if (!empty($settings))
1049 {
1050 foreach ($settings as $key => $preset)
1051 {
1052 $this->setFilterSettings($key, $preset, false);
1053
1054 if (array_key_exists($key, $this->options["deleted_presets"]))
1055 {
1056 unset($this->options["deleted_presets"][$key]);
1057 }
1058 }
1059
1060 $this->options["default"] = self::findDefaultPresetId($this->options["default_presets"]);
1061 $this->options["use_pin_preset"] = true;
1062 $this->options["filter"] = $this->options["default"];
1063 unset(Application::getInstance()->getSession()["main.ui.filter"][$this->id]["filter"]);
1064 }
1065 }
1066
1067
1071 public function setFilterSettingsArray($settings = array())
1072 {
1073 if (!empty($settings))
1074 {
1075 foreach ($settings as $key => $preset)
1076 {
1077 if ($key !== "current_preset" && $key !== "common_presets_id")
1078 {
1079 $this->setFilterSettings($key, $preset, false);
1080 }
1081 }
1082
1083 $this->options["filter"] = $settings["current_preset"];
1084 $request = $this->getRequest();
1085
1086 if (
1087 isset($request["params"]["forAll"])
1088 && (
1089 $request["params"]["forAll"] === "true"
1090 || $request["params"]["forAll"] === true
1091 )
1092 )
1093 {
1094 $this->saveForAll();
1095 }
1096 }
1097 }
1098
1099
1106 public function setFilterSettings($presetId, $settings, $currentPreset = true, $useRequest = true)
1107 {
1108 if (!empty($presetId))
1109 {
1110 if ($currentPreset)
1111 {
1112 $request = $this->getRequest();
1113 $params = $request->getPost('params');
1114 $params = is_array($params) ? $params : [];
1115
1116 $isApplyFilter = (
1117 (mb_strtoupper($request->get("apply_filter")) == "Y") ||
1118 (isset($params["apply_filter"]) && mb_strtoupper($params["apply_filter"]) == "Y")
1119 );
1120 $isClearFilter = (
1121 (mb_strtoupper($request->get("clear_filter")) == "Y") ||
1122 (isset($params["clear_filter"]) && mb_strtoupper($params["clear_filter"]) == "Y")
1123 );
1124 $isWithPreset = (
1125 (mb_strtoupper($request->get("with_preset")) == "Y") ||
1126 (isset($params["with_preset"]) && mb_strtoupper($params["with_preset"]) == "Y")
1127 );
1128 $currentPresetId = $this->getCurrentFilterId();
1129
1130 if (
1131 ($useRequest
1132 && ($isApplyFilter || $isClearFilter)
1133 && (!$isWithPreset || $currentPresetId === static::DEFAULT_FILTER)
1134 )
1135 || $useRequest === false
1136 )
1137 {
1138 Application::getInstance()->getSession()["main.ui.filter"][$this->id]["filter"] = $presetId;
1139 Application::getInstance()->getSession()["main.ui.filter"][$this->id]["isSetOutside"] = $params["isSetOutside"] ?? false;
1140 }
1141
1142 }
1143
1144 if (!isset($this->options["filters"][$presetId]) || !is_array($this->options["filters"][$presetId]))
1145 {
1146 $this->options["filters"][$presetId] = array();
1147 }
1148
1149 if (isset($settings["name"]) && !empty($settings["name"]))
1150 {
1151 $this->options["filters"][$presetId]["name"] = $settings["name"];
1152 }
1153
1154 if (isset($settings["for_all"]))
1155 {
1156 $this->options["filters"][$presetId]["for_all"] = $settings["for_all"] === "true";
1157 }
1158
1159 if (isset($settings["sort"]) && is_numeric($settings["sort"]))
1160 {
1161 $this->options["filters"][$presetId]["sort"] = $settings["sort"];
1162 }
1163
1164 if (isset($settings["fields"]) && is_array($settings["fields"]))
1165 {
1166 if (array_key_exists("FIND", $settings["fields"]))
1167 {
1168 Application::getInstance()->getSession()["main.ui.filter"][$this->id]["filter_search"] = $settings["fields"]["FIND"];
1169 unset($settings["fields"]["FIND"]);
1170 }
1171
1172 if ($presetId == "default_filter")
1173 {
1174 $this->options["filters"][$presetId]["fields"] = array();
1175 }
1176 else
1177 {
1178 $this->options["filters"][$presetId]["fields"] = $settings["fields"];
1179
1180 $additionalFields = isset($settings["additional"]) && is_array($settings["additional"]) ? $settings["additional"] : array();
1181 $this->setAdditionalPresetFields($presetId, $additionalFields);
1182 }
1183 }
1184
1185 if (!isset($settings["fields"]) && isset($settings["clear_filter"]) && $settings["clear_filter"] === 'Y')
1186 {
1187 $this->options["filters"][$presetId]["fields"] = array();
1188 }
1189
1190 if (isset($settings["name"]) && !empty($settings["name"]))
1191 {
1192 $this->options["filters"][$presetId]["name"] = $settings["name"];
1193 }
1194
1195 if (isset($settings["rows"]))
1196 {
1197 $rows = $settings["rows"];
1198 if (is_array($rows))
1199 {
1200 $result = array();
1201 foreach($rows as $id)
1202 {
1203 $id = trim($id);
1204 if($id !== "")
1205 {
1206 $result[] = $id;
1207 }
1208 }
1209 $this->options["filters"][$presetId]["filter_rows"] = implode(",", $result);
1210 }
1211 elseif (is_string($settings["rows"]))
1212 {
1213 $this->options["filters"][$presetId]["filter_rows"] = $settings["rows"];
1214 }
1215 }
1216 }
1217 }
1218
1219
1225 public function deleteFilter($presetId, $isDefault = false)
1226 {
1227 if ($isDefault)
1228 {
1229 $this->options["deleted_presets"][$presetId] = true;
1230 }
1231
1232 unset($this->options["filters"][$presetId]);
1233 }
1234
1235
1241 public function isDeletedPreset($presetId)
1242 {
1243 return array_key_exists($presetId, $this->options["deleted_presets"]);
1244 }
1245
1251 public function setupDefaultFilter(array $fields, array $rows)
1252 {
1253 $this->setFilterSettings("tmp_filter", array("fields" => $fields, "rows" => $rows), true, false);
1254 $this->save();
1255 }
1256
1265 public static function calcDates($fieldId, $source, &$result)
1266 {
1267 switch($source[$fieldId."_datesel"])
1268 {
1269 case DateType::YESTERDAY :
1270 {
1271 $dateTime = Filter\DateTimeFactory::createToday();
1272
1273 $result[$fieldId."_datesel"] = DateType::YESTERDAY;
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");
1279 break;
1280 }
1281
1283 {
1284 $dateTime = Filter\DateTimeFactory::createToday();
1285
1286 $result[$fieldId."_datesel"] = DateType::CURRENT_DAY;
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");
1292 break;
1293 }
1294
1295 case DateType::TOMORROW :
1296 {
1297 $dateTime = Filter\DateTimeFactory::createToday();
1298
1299 $result[$fieldId."_datesel"] = DateType::TOMORROW;
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");
1305 break;
1306 }
1307
1309 {
1310 $dateTime = Filter\DateTimeFactory::createCurrentWeekMonday();
1311
1312 $result[$fieldId."_datesel"] = DateType::CURRENT_WEEK;
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");
1318 break;
1319 }
1320
1321 case DateType::NEXT_WEEK :
1322 {
1323 $dateTime = Filter\DateTimeFactory::createNextWeekMonday();
1324
1325 $result[$fieldId."_datesel"] = DateType::NEXT_WEEK;
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");
1331 break;
1332 }
1333
1335 {
1336 $dateTime = Filter\DateTimeFactory::createFirstDayOfCurrentMonth();
1337
1338 $result[$fieldId."_datesel"] = DateType::CURRENT_MONTH;
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");
1344 break;
1345 }
1346
1348 {
1349 $dateTime = Filter\DateTimeFactory::createFirstDayOfNextMonth();
1350
1351 $result[$fieldId."_datesel"] = DateType::NEXT_MONTH;
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");
1357 break;
1358 }
1359
1361 {
1362 $dateTime = Filter\DateTimeFactory::createToday();
1363
1364 $result[$fieldId."_datesel"] = DateType::QUARTER;
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();
1370 break;
1371 }
1372
1374 {
1375 $dateTime = Filter\DateTimeFactory::createToday();
1376
1377 $result[$fieldId."_datesel"] = DateType::LAST_7_DAYS;
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");
1383 break;
1384 }
1385
1387 {
1388 $dateTime = Filter\DateTimeFactory::createToday();
1389
1390 $result[$fieldId."_datesel"] = DateType::LAST_30_DAYS;
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");
1396 break;
1397 }
1398
1400 {
1401 $dateTime = Filter\DateTimeFactory::createToday();
1402
1403 $result[$fieldId."_datesel"] = DateType::LAST_60_DAYS;
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");
1409 break;
1410 }
1411
1413 {
1414 $dateTime = Filter\DateTimeFactory::createToday();
1415
1416 $result[$fieldId."_datesel"] = DateType::LAST_90_DAYS;
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");
1422 break;
1423 }
1424
1425 case DateType::MONTH :
1426 {
1427 $month = $source[$fieldId."_month"];
1428 $year = $source[$fieldId."_year"];
1429
1430 if (!empty($month) && !empty($year))
1431 {
1432 $dateTime = new Filter\DateTime(mktime(0, 0, 0, $month, 1, $year));
1433
1434 $result[$fieldId."_datesel"] = DateType::MONTH;
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");
1440 }
1441
1442 break;
1443 }
1444
1445 case DateType::NEXT_DAYS :
1446 {
1447 if (is_numeric($source[$fieldId."_days"]))
1448 {
1449 $dateTime = Filter\DateTimeFactory::createToday();
1450 $days = (int) $source[$fieldId."_days"];
1451 $days = $days > 0 ? ($days + 1) : $days;
1452
1453 $result[$fieldId."_datesel"] = DateType::NEXT_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");
1460 }
1461
1462 break;
1463 }
1464
1465 case DateType::PREV_DAYS :
1466 {
1467 if (is_numeric($source[$fieldId."_days"]))
1468 {
1469 $dateTime = Filter\DateTimeFactory::createToday();
1470 $days = (int) $source[$fieldId."_days"];
1471 $days = max($days, 0);
1472
1473 $result[$fieldId."_datesel"] = DateType::PREV_DAYS;
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");
1480 }
1481
1482 break;
1483 }
1484
1486 {
1487 if (is_numeric($source[$fieldId."_days"]))
1488 {
1489 $dateTime = Filter\DateTimeFactory::createToday();
1490 $days = (int) $source[$fieldId."_days"];
1491
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");
1495 }
1496
1497 break;
1498 }
1499
1501 {
1502 if (is_numeric($source[$fieldId."_days"]))
1503 {
1504 $dateTime = Filter\DateTimeFactory::createToday();
1505 $days = (int) $source[$fieldId."_days"];
1506
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");
1510 }
1511
1512 break;
1513 }
1514
1516 {
1517 if (is_numeric($source[$fieldId."_days"]))
1518 {
1519 $dateTime = Filter\DateTimeFactory::createToday();
1520 $days = (int) $source[$fieldId."_days"];
1521
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");
1525 }
1526
1527 break;
1528 }
1529
1531 {
1532 if (is_numeric($source[$fieldId."_days"]))
1533 {
1534 $dateTime = Filter\DateTimeFactory::createToday();
1535 $days = (int) $source[$fieldId."_days"];
1536
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");
1540 }
1541
1542 break;
1543 }
1544
1545
1546 case DateType::QUARTER :
1547 {
1548 $quarter = $source[$fieldId."_quarter"];
1549 $year = $source[$fieldId."_year"];
1550
1551 if (!empty($quarter) && !empty($year))
1552 {
1553 $dateTime = new Filter\DateTime(MakeTimeStamp(Quarter::getStartDate($quarter, $year)));
1554
1555 $result[$fieldId."_datesel"] = DateType::QUARTER;
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();
1561 }
1562
1563 break;
1564 }
1565
1566 case DateType::YEAR :
1567 {
1568 $year = $source[$fieldId."_year"];
1569
1570 if (!empty($year))
1571 {
1572 $dateTime = new Filter\DateTime(mktime(0, 0, 0, 1, 1, $year));
1573
1574 $result[$fieldId."_datesel"] = DateType::YEAR;
1575 $result[$fieldId."_year"] = $dateTime->year();
1576 $result[$fieldId."_from"] = $dateTime->toString();
1577 $result[$fieldId."_to"] = $dateTime->offset("1 year - 1 second");
1578 }
1579
1580 break;
1581 }
1582
1583 case DateType::EXACT :
1584 {
1585 $sourceDate = $source[$fieldId."_from"];
1586
1587 if (!empty($sourceDate))
1588 {
1589 $date = new Date($sourceDate);
1590 $dateTime = new Filter\DateTime(MakeTimeStamp($sourceDate));
1591
1592 $result[$fieldId."_datesel"] = DateType::EXACT;
1593
1594 if ($dateTime->getTimestamp() > $date->getTimestamp())
1595 {
1596 $result[$fieldId."_from"] = $dateTime->toString();
1597 $result[$fieldId."_to"] = $dateTime->toString();
1598 }
1599 else
1600 {
1601 $result[$fieldId."_from"] = $dateTime->toString();
1602 $result[$fieldId."_to"] = $dateTime->offset("1 days - 1 second");
1603 }
1604 }
1605
1606 break;
1607 }
1608
1609 case DateType::LAST_WEEK :
1610 {
1611 $dateTime = Filter\DateTimeFactory::createLastWeekMonday();
1612
1613 $result[$fieldId."_datesel"] = DateType::LAST_WEEK;
1614 $result[$fieldId."_from"] = $dateTime->toString();
1615 $result[$fieldId."_to"] = $dateTime->offset("7 days - 1 second");
1616 break;
1617 }
1618
1620 {
1621 $dateTime = Filter\DateTimeFactory::createFirstDayOfLastMonth();
1622
1623 $result[$fieldId."_datesel"] = DateType::LAST_MONTH;
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");
1628 break;
1629 }
1630
1631 case DateType::RANGE :
1632 {
1633 $startSourceDate = $source[$fieldId."_from"];
1634 $endSourceDate = $source[$fieldId."_to"];
1635
1636 $result[$fieldId."_from"] = "";
1637 $result[$fieldId."_to"] = "";
1638
1639 if (!empty($startSourceDate))
1640 {
1641 $startDateTime = new Filter\DateTime(MakeTimeStamp($startSourceDate));
1642
1643 $result[$fieldId."_datesel"] = DateType::RANGE;
1644 $result[$fieldId."_from"] = $startDateTime->toString();
1645 }
1646
1647 if (!empty($endSourceDate))
1648 {
1649 $endDate = Date::createFromTimestamp(MakeTimeStamp($endSourceDate));
1650 $endDateTime = new Filter\DateTime(MakeTimeStamp($endSourceDate));
1651
1652 $result[$fieldId."_datesel"] = DateType::RANGE;
1653
1654 if ($endDateTime->getTimestamp() > $endDate->getTimestamp())
1655 {
1656 $result[$fieldId."_to"] = $endDateTime->toString();
1657 }
1658 else
1659 {
1660 $result[$fieldId."_to"] = $endDateTime->offset("1 days - 1 second");
1661 }
1662 }
1663
1664 break;
1665 }
1666 }
1667 }
1668
1669
1673 public function reset()
1674 {
1675 Application::getInstance()->getSession()["main.ui.filter"][$this->id] = null;
1676 }
1677
1678
1682 public function destroy()
1683 {
1684 static::destroyById($this->getId());
1685 }
1686
1687
1692 public static function destroyById($filterId)
1693 {
1694 \CUserOptions::deleteOption("main.ui.filter", $filterId);
1695 \CUserOptions::deleteOption("main.ui.filter.presets", $filterId);
1696 unset(Application::getInstance()->getSession()["main.ui.filter"][$filterId]);
1697 unset(Application::getInstance()->getSession()["main.ui.filter.presets"][$filterId]);
1698 }
1699
1700
1701 public static function getRowsFromFields($fields = array())
1702 {
1703 $rows = array();
1704
1705 foreach ($fields as $key => $field)
1706 {
1707 $rows[] = str_replace(
1708 array(
1709 "_datesel",
1710 "_numsel",
1711 "_from",
1712 "_to",
1713 "_days",
1714 "_month",
1715 "_quarter",
1716 "_id",
1717 "_year",
1718 "_name",
1719 "_label",
1720 "_value",
1721 "_days",
1722 "_months",
1723 "_years",
1724 "_isEmpty",
1725 "_hasAnyValue",
1726 ),
1727 "",
1728 $key
1729 );
1730 }
1731
1732 return array_unique($rows);
1733 }
1734
1735
1741 public static function fetchPresetFields($preset)
1742 {
1743 if (isset($preset["filter_rows"]) && is_string($preset["filter_rows"]))
1744 {
1745 $fields = explode(",", $preset["filter_rows"]);
1746 return array_unique($fields);
1747 }
1748
1749 return static::getRowsFromFields($preset["fields"]);
1750 }
1751
1752
1757 public function getUsedFields()
1758 {
1759 $fields = array();
1760
1761 // Fetch fields from user presets
1762 foreach ($this->getPresets() as $key => $preset)
1763 {
1764 $presetFields = static::fetchPresetFields($preset);
1765 $fields = array_merge($fields, $presetFields);
1766 }
1767
1768 $defaultPresetFieldsOrder = [];
1769 // Fetch fields from default presets
1770 foreach ($this->getDefaultPresets() as $key => $preset)
1771 {
1772 $presetFields = static::fetchPresetFields($preset);
1773 $fields = array_merge($fields, $presetFields);
1774 if (isset($preset['default']))
1775 {
1776 $defaultPresetFieldsOrder = $presetFields;
1777 }
1778 }
1779
1780 $fields = array_unique($fields);
1781
1782 if (!empty($defaultPresetFieldsOrder))
1783 {
1784 // fields order should be defined by default filter preset
1785 $fields = array_unique(array_merge($defaultPresetFieldsOrder, $fields));
1786 }
1787
1788 return $fields;
1789 }
1790
1794 public function getCurrentFilterPresetId(): ?string
1795 {
1797 }
1798
1803 public function setCurrentFilterPresetId(?string $presetId): Options
1804 {
1805 $this->currentFilterPresetId = $presetId;
1806 return $this;
1807 }
1808}
static getCurrent()
Definition context.php:241
static fetchDateFieldValue($key="", $filterFields=array())
Definition options.php:643
getAdditionalPresetFields($presetId)
Definition options.php:526
getFilter($sourceFields=array())
Definition options.php:770
setDefaultPresets($presets=array())
Definition options.php:219
setPresets($presets=array())
Definition options.php:159
static isSetFromRequest(HttpRequest $request)
Definition options.php:376
pinPreset($presetId="default_filter")
Definition options.php:355
static fetchFieldValuesFromFilterSettings($filterSettings=array(), $additionalFields=array(), $sourceFields=array())
Definition options.php:703
static isCommon($options)
Definition options.php:941
static destroyById($filterId)
Definition options.php:1692
removeRowFromPreset(string $presetId, string $rowName)
Definition options.php:1022
trySetFilterFromRequest($fields=array())
Definition options.php:568
setupDefaultFilter(array $fields, array $rows)
Definition options.php:1251
setFilterRows($presetId, $rows)
Definition options.php:1009
static findDefaultPresetId($presets=array())
Definition options.php:322
setDefaultPreset($presetId="default_filter")
Definition options.php:199
setCurrentPreset($presetId="default_filter")
Definition options.php:169
saveOptionsForUser($options, $userId)
Definition options.php:952
deleteFilter($presetId, $isDefault=false)
Definition options.php:1225
static fetchSettingsFromQuery($fields, HttpRequest $request)
Definition options.php:392
static getRowsFromFields($fields=array())
Definition options.php:1701
static isDefaultFilter($presetId="")
Definition options.php:760
setDeletedPresets($deletedPresets=array())
Definition options.php:229
getFilterLogic($sourceFields=array())
Definition options.php:801
static isCurrentUserEditOtherSettings()
Definition options.php:876
setFilterSettings($presetId, $settings, $currentPreset=true, $useRequest=true)
Definition options.php:1106
setFilterSettingsArray($settings=array())
Definition options.php:1071
static fetchFieldsFromFilterSettings($filterSettings=array(), $additionalFields=array())
Definition options.php:605
__construct($filterId, $filterPresets=array(), $commonPresetsId=null)
Definition options.php:37
setAdditionalPresetFields($presetId, $additional=array())
Definition options.php:540
setCurrentFilterPresetId(?string $presetId)
Definition options.php:1803
restore($settings=array())
Definition options.php:1046
static isDateField($key="")
Definition options.php:630
static fetchPresetFields($preset)
Definition options.php:1741
static fetchNumberFieldValue($key="", $filterFields=array())
Definition options.php:670
static isNumberField($key="")
Definition options.php:697
static calcDates($fieldId, $source, &$result)
Definition options.php:1265
static getStartDate($quarter, $year)
Definition quarter.php:74