Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
filter.php
1<?php
3
4abstract class Filter
5{
7 protected $fields = [];
8
9 protected $fieldTypeHandlers = [];
10
15 public function __construct()
16 {
17 $this->initFieldTypeHandlers();
18 }
19
24 public function setFields(array $fields)
25 {
26 $this->fields = $fields;
27 }
28
33 public function create(array $sourceFilter)
34 {
35 $result = [];
36 if (empty($this->fields) || empty($sourceFilter))
37 {
38 return $result;
39 }
40
41 $quickSearchField = $this->getQuickSearchField();
42
43 foreach ($sourceFilter as $row)
44 {
45 if (!BlockFilter::checkPreparedRow($row))
46 {
47 continue;
48 }
49
50 $index = $row['key'];
51 $value = $row['value'];
52
53 if (!isset($this->fields[$index]))
54 {
55 continue;
56 }
57
58 if (
59 $index === $quickSearchField
60 && isset($value['QUICK_SEARCH'])
61 && $value['QUICK_SEARCH'] == 'Y'
62 )
63 {
64 $this->addQuickSearchValue($result, $index, $this->fields[$index], $value);
65 }
66 else
67 {
68 $handler = $this->getFieldHandler($this->fields[$index]);
69 if ($handler !== '' && is_callable([$this, $handler]))
70 {
71 call_user_func_array(
72 [$this, $handler],
73 [&$result, $index, $this->fields[$index], $value]
74 );
75 }
76 }
77 }
78 unset($row);
79
80 return $result;
81 }
82
86 protected function initFieldTypeHandlers()
87 {
88 $this->fieldTypeHandlers = [];
89 }
90
95 protected function getFieldHandler(array $field)
96 {
97 $result = '';
98 if (!isset($field['type']))
99 {
100 $field['type'] = 'string';
101 }
102 if (isset($this->fieldTypeHandlers[$field['type']]))
103 {
104 $result = $this->fieldTypeHandlers[$field['type']];
105 }
106
107 return $result;
108 }
109
113 protected function getQuickSearchField()
114 {
115 $result = null;
116 if (!empty($this->fields))
117 {
118 foreach (array_keys($this->fields) as $index)
119 {
120 $row = $this->fields[$index];
121 if (
122 (!isset($row['quickSearch']) && !isset($row['quickSearchOnly']))
123 || (isset($row['entity']) && $row['entity'] != 'master')
124 )
125 {
126 continue;
127 }
128 $result = $row['id'];
129 }
130 unset($row, $index);
131 }
132 return $result;
133 }
134
142 protected function addQuickSearchValue(array &$result, $fieldId, array $field, array $value) {}
143}
getFieldHandler(array $field)
Definition filter.php:95
addQuickSearchValue(array &$result, $fieldId, array $field, array $value)
Definition filter.php:142
create(array $sourceFilter)
Definition filter.php:33
setFields(array $fields)
Definition filter.php:24