Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
dataprovider.php
1
<?php
8
namespace
Bitrix\Main\UserConsent
;
9
10
use
Bitrix\Main\Event
;
11
use
Bitrix\Main\EventResult
;
12
use
Bitrix\Main\Localization\Loc
;
13
14
Loc::loadLanguageFile
(__FILE__);
15
20
class
DataProvider
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
{
116
$data
=
$this->data
;
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
}
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadLanguageFile
static loadLanguageFile($file, $language=null, $normalize=true)
Definition
loc.php:224
Bitrix\Main\UserConsent\DataProvider
Definition
dataprovider.php:21
Bitrix\Main\UserConsent\DataProvider\getEditUrl
getEditUrl()
Definition
dataprovider.php:97
Bitrix\Main\UserConsent\DataProvider\$editUrl
$editUrl
Definition
dataprovider.php:31
Bitrix\Main\UserConsent\DataProvider\getName
getName()
Definition
dataprovider.php:87
Bitrix\Main\UserConsent\DataProvider\getByCode
static getByCode($providerCode)
Definition
dataprovider.php:39
Bitrix\Main\UserConsent\DataProvider\toArray
toArray()
Definition
dataprovider.php:138
Bitrix\Main\UserConsent\DataProvider\$data
$data
Definition
dataprovider.php:29
Bitrix\Main\UserConsent\DataProvider\$code
$code
Definition
dataprovider.php:25
Bitrix\Main\UserConsent\DataProvider\getData
getData()
Definition
dataprovider.php:107
Bitrix\Main\UserConsent\DataProvider\EVENT_NAME_LIST
const EVENT_NAME_LIST
Definition
dataprovider.php:22
Bitrix\Main\UserConsent\DataProvider\$name
$name
Definition
dataprovider.php:27
Bitrix\Main\UserConsent\DataProvider\getCode
getCode()
Definition
dataprovider.php:77
Bitrix\Main\UserConsent\DataProvider\checkObligatoryFields
static checkObligatoryFields($params)
Definition
dataprovider.php:188
Bitrix\Main\UserConsent\DataProvider\__construct
__construct($code, $name, $data, $editUrl)
Definition
dataprovider.php:64
Bitrix\Main\UserConsent\DataProvider\getList
static getList()
Definition
dataprovider.php:153
Bitrix\Main\UserConsent
Definition
agreement.php:8
modules
main
lib
userconsent
dataprovider.php
Создано системой
1.10.0