Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dataprovider.php
1<?php
9
13
14Loc::loadLanguageFile(__FILE__);
15
21{
22 const EVENT_NAME_LIST = 'OnUserConsentDataProviderList';
23
25 protected $code;
27 protected $name;
29 protected $data;
31 protected $editUrl;
32
39 public static function getByCode($providerCode)
40 {
41 $list = self::getList();
42 foreach ($list as $provider)
43 {
44 if ($provider->getCode() != $providerCode)
45 {
46 continue;
47 }
48
49 return $provider;
50 }
51
52 return null;
53 }
54
64 public function __construct($code, $name, $data, $editUrl)
65 {
66 $this->code = $code;
67 $this->name = $name;
68 $this->data = $data;
69 $this->editUrl = $editUrl;
70 }
71
77 public function getCode()
78 {
79 return $this->code;
80 }
81
87 public function getName()
88 {
89 return $this->name;
90 }
91
97 public function getEditUrl()
98 {
99 return $this->editUrl;
100 }
101
107 public function getData()
108 {
109 if (is_callable($this->data))
110 {
111 $getDataFunc = $this->data;
112 $data = $getDataFunc();
113 }
114 else
115 {
117 }
118
119 $result = array();
120 foreach ($data as $key => $value)
121 {
122 if (!$value)
123 {
124 continue;
125 }
126
127 $result[$key] = $value;
128 }
129
130 return $result;
131 }
132
138 public function toArray()
139 {
140 return array(
141 'CODE' => $this->getCode(),
142 'NAME' => $this->getName(),
143 'DATA' => $this->getData(),
144 'EDIT_URL' => $this->getEditUrl(),
145 );
146 }
147
153 public static function getList()
154 {
155 $data = array();
156 $event = new Event('main', self::EVENT_NAME_LIST, array($data));
157 $event->send();
158
159 $list = array();
160 foreach ($event->getResults() as $eventResult)
161 {
162 if ($eventResult->getType() == EventResult::ERROR)
163 {
164 continue;
165 }
166
167 $params = $eventResult->getParameters();
168 if(!$params || !is_array($params))
169 {
170 continue;
171 }
172
173
174 foreach ($params as $item)
175 {
176 if (!self::checkObligatoryFields($item))
177 {
178 continue;
179 }
180
181 $list[] = new static($item['CODE'], $item['NAME'], $item['DATA'], $item['EDIT_URL']);
182 }
183 }
184
185 return $list;
186 }
187
188 protected static function checkObligatoryFields($params)
189 {
190 if (!isset($params['DATA']) || !$params['DATA'])
191 {
192 return false;
193 }
194
195 if (!is_array($params['DATA']) && !is_callable($params['DATA']))
196 {
197 return false;
198 }
199
200 if (!isset($params['NAME']) || !$params['NAME'] || !is_string($params['NAME']))
201 {
202 return false;
203 }
204
205 if (!isset($params['CODE']) || !$params['CODE'] || !is_string($params['CODE']))
206 {
207 return false;
208 }
209
210 return true;
211 }
212}
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224