Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
filterentity.php
1<?php
3
4use \Bitrix\Landing\Internals\FilterEntityTable;
5
7{
12 public static $internalClass = 'FilterEntityTable';
13
18 protected static function getSourceSelector()
19 {
20 static $sourceList = null;
21
22 if ($sourceList === null)
23 {
24 $sourceList = new Selector();
25 }
26
27 return $sourceList;
28 }
29
35 public static function getFilter($filterId)
36 {
37 $filter = [];
38 $filterId = intval($filterId);
39
40 if ($filterId)
41 {
42 $select = ['SOURCE_ID', 'FILTER', 'FILTER_HASH'];
43 $res = self::getList([
44 'select' => $select,
45 'filter' => [
46 'ID' => $filterId
47 ]
48 ]);
49 if ($row = $res->fetch())
50 {
51 $filter = $row;
52 }
53 unset($res, $row);
54 $filter = array_merge(
55 array_fill_keys($select, null),
56 $filter
57 );
58 }
59
60 return $filter;
61 }
62
69 public static function setFilter($blockId, array &$sourceParams = [])
70 {
71 $sourceList = self::getSourceSelector();
72
73 foreach ($sourceParams as $selector => &$item)
74 {
75 $item['filterId'] = 0;
76 if (isset($item['source']))
77 {
78 $sourceId = trim($item['source']);
79 $sourceFilter = isset($item['settings']['source']['filter'])
80 ? $item['settings']['source']['filter']
81 : [];
82 // build source by id
83 $source = $sourceList->getDataLoader(
84 $sourceId,
85 []
86 );
87 if (!is_object($source))
88 {
89 return;
90 }
91 // normalize and hash the filter
92 $sourceFilter = $source->normalizeFilter(
93 $sourceFilter
94 );
95 $hashFilter = $source->getFilterHash(
96 $sourceFilter
97 );
98 // add new entity if not exist
99 $filterId = 0;
100 $res = self::getList([
101 'select' => [
102 'ID'
103 ],
104 'filter' => [
105 '=FILTER_HASH' => $hashFilter
106 ]
107 ]);
108 if ($row = $res->fetch())
109 {
110 $filterId = $row['ID'];
111 }
112 else
113 {
114 $res = self::add([
115 'SOURCE_ID' => $sourceId,
116 'FILTER_HASH' => $hashFilter,
117 'FILTER' => $sourceFilter
118 ]);
119 if ($res->isSuccess())
120 {
121 $filterId = $res->getId();
122 }
123 }
124 if ($filterId)
125 {
126 FilterEntityTable::applyBlock($filterId, $blockId);
127 $item['filterId'] = $filterId;
128 }
129 unset($sourceFilter, $hashFilter, $res, $row);
130 }
131 }
132 unset($sourceList, $selector, $item);
133
134 if (!$sourceParams)
135 {
136 self::removeBlock($blockId);
137 }
138 }
139
145 public static function removeBlock($blockId)
146 {
148 }
149}
static applyBlock($filterId, $blockId)
static setFilter($blockId, array &$sourceParams=[])