Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
9
10use \Bitrix\Sender\Connector;
11
12abstract class Base
13{
14 protected $fieldPrefix;
15 protected $fieldValues;
16 protected $fieldFormName;
17 protected $moduleId;
18 protected $siteId;
19
20 protected $fields;
21 protected $params;
22 protected $isRunForOldData = false;
23 protected $recipient;
24
25
30 public function setModuleId($moduleId)
31 {
32 $this->moduleId = $moduleId;
33 }
34
38 public function getModuleId()
39 {
40 return $this->moduleId;
41 }
42
47 public function setSiteId($siteId)
48 {
49 $this->siteId = $siteId;
50 }
51
55 public function getSiteId()
56 {
57 return $this->siteId;
58 }
59
63 public function getId()
64 {
65 return $this->getModuleId().'_'.$this->getCode();
66 }
67
71 public function requireConfigure()
72 {
73 return false;
74 }
75
79 public static function isClosed()
80 {
81 return false;
82 }
83
87 public static function canBeTarget()
88 {
89 return true;
90 }
91
95 public static function canRunForOldData()
96 {
97 return false;
98 }
99
103 public function setRunForOldData($isRunForOldData)
104 {
105 if(!static::canRunForOldData())
106 {
107 $this->isRunForOldData = false;
108 }
109
110 $this->isRunForOldData = (bool) $isRunForOldData;
111 }
112
116 public function isRunForOldData()
117 {
118 if(!$this->canRunForOldData())
119 {
120 return false;
121 }
122
123 return $this->isRunForOldData;
124 }
125
130 public function setFields(array $fieldValues = null)
131 {
132 $this->fields = $fieldValues;
133 }
134
138 public function getFields()
139 {
140 if(is_array($this->fields))
141 return $this->fields;
142 else
143 return array();
144 }
145
151 public function getFieldValue($name, $defaultValue = null)
152 {
153 if($this->fields && array_key_exists($name, $this->fields))
154 {
155 return $this->fields[$name];
156 }
157 else
158 {
159 return $defaultValue;
160 }
161 }
162
167 public function setParams(array $fieldValues = null)
168 {
169 $this->params = $fieldValues;
170 }
171
175 public function getParams()
176 {
177 if(is_array($this->params))
178 return $this->params;
179 else
180 return array();
181 }
182
188 public function getParam($name, $defaultValue = null)
189 {
190 if($this->params && array_key_exists($name, $this->params))
191 {
192 return $this->params[$name];
193 }
194 else
195 {
196 return $defaultValue;
197 }
198 }
199
205 {
206 $this->fieldFormName = $fieldFormName;
207 }
208
212 public function getFieldFormName()
213 {
215 }
216
222 {
223 $this->fieldPrefix = $fieldPrefix;
224 }
225
229 public function getFieldPrefix()
230 {
231 return $this->fieldPrefix;
232 }
233
238 public function getFieldId($id)
239 {
240 $fieldPrefix = $this->getFieldPrefix();
241 if($fieldPrefix)
242 {
243 return $fieldPrefix . '_' . $id;
244 }
245 else
246 return $id;
247 }
248
253 public function getFieldName($name)
254 {
255 $fieldPrefix = $this->getFieldPrefix();
256 if($fieldPrefix)
257 {
258 $returnName = array();
259 $returnName[] = $fieldPrefix;
260 $nameParsed = explode('[', $name);
261 $returnName[] = '['.$nameParsed[0].']';
262 if(count($nameParsed) > 1)
263 {
264 unset($nameParsed[0]);
265 $returnName[] = '['.implode('[', $nameParsed);
266 }
267
268 return implode('', $returnName);
269 }
270 else
271 return $name;
272 }
273
277 public function getFullEventType()
278 {
279 return $this->getEventModuleId() .'/'. $this->getEventType();
280 }
281
282
284 public function getMailEventToPrevent()
285 {
286 return array(
287 'EVENT_NAME' => '',
288 'FILTER' => array()
289 );
290 }
291
293 public function filter()
294 {
295 return true;
296 }
297
301 public function getForm()
302 {
303 return '';
304 }
305
309 public function getRecipientResult()
310 {
311 $result = new Connector\Result($this->getRecipient());
312
313 // set fields that will be added in each item of result set
314 $personalizeList = array();
315 $personalizeListTmp = $this->getPersonalizeList();
316 foreach($personalizeListTmp as $tag)
317 {
318 if($tag['CODE'] <> '')
319 {
320 $personalizeList[] = $tag['CODE'];
321 }
322 }
323 $result->setFilterFields($personalizeList);
324
325 // set same fields for all items in each item of result set
326 $result->setAdditionalFields($this->getPersonalizeFields());
327
328 return $result;
329 }
330
334 public function getPersonalizeFields()
335 {
336 return array();
337 }
338
342 public static function getPersonalizeList()
343 {
344 return array();
345 }
346
350 public abstract function getName();
351
355 public abstract function getCode();
356
360 public abstract function getEventModuleId();
361
365 public abstract function getEventType();
366
370 public abstract function getRecipient();
371}
setFields(array $fieldValues=null)
Definition base.php:130
static canRunForOldData()
Definition base.php:95
setFieldPrefix($fieldPrefix)
Definition base.php:221
setModuleId($moduleId)
Definition base.php:30
setParams(array $fieldValues=null)
Definition base.php:167
setFieldFormName($fieldFormName)
Definition base.php:204
getParam($name, $defaultValue=null)
Definition base.php:188
static getPersonalizeList()
Definition base.php:342
getFieldValue($name, $defaultValue=null)
Definition base.php:151
setRunForOldData($isRunForOldData)
Definition base.php:103