1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entitycollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Internals;
4
5use Bitrix\Sale;
6use Bitrix\Main;
7
12abstract class EntityCollection
13 extends CollectionBase
14{
15 private $index = -1;
16
17 protected $isClone = false;
18
19 protected $anyItemDeleted = false;
20 protected $anyItemAdded = false;
21
25 protected function __construct() {}
26
36 public function onItemModify(CollectableEntity $item, $name = null, $oldValue = null, $value = null)
37 {
38 return new Sale\Result();
39 }
40
45 public static function getRegistryType()
46 {
48 }
49
57 public function deleteItem($index)
58 {
59 if (!isset($this->collection[$index]))
60 {
61 throw new Main\ArgumentOutOfRangeException("collection item index wrong");
62 }
63
64 $oldItem = $this->collection[$index];
65
67 $eventsList = $eventManager->findEventHandlers('sale', 'OnBeforeCollectionDeleteItem');
68 if (!empty($eventsList))
69 {
71 $event = new Main\Event('sale', 'OnBeforeCollectionDeleteItem', array(
72 'COLLECTION' => $this->collection,
73 'ENTITY' => $oldItem,
74 ));
75 $event->send();
76 }
77
78 unset($this->collection[$index]);
79 $this->setAnyItemDeleted(true);
80
81 return $oldItem;
82 }
83
88 protected function addItem(CollectableEntity $item)
89 {
90 $item = $this->bindItem($item);
91
92 $this->setAnyItemAdded(true);
93
94 $eventManager = Main\EventManager::getInstance();
95 $eventsList = $eventManager->findEventHandlers('sale', 'OnCollectionAddItem');
96 if (!empty($eventsList))
97 {
99 $event = new Main\Event('sale', 'OnCollectionAddItem', array(
100 'COLLECTION' => $this->collection,
101 'ENTITY' => $item,
102 ));
103 $event->send();
104 }
105
106 return $item;
107 }
108
110 {
111 $index = $this->createIndex();
112 $item->setInternalIndex($index);
113 $this->collection[$index] = $item;
114
115 return $item;
116 }
117
121 protected function createIndex()
122 {
123 $this->index++;
124 return $this->index;
125 }
126
131 public function clearCollection()
132 {
133 $this->callEventOnBeforeCollectionClear();
134
136 foreach ($this->getDeletableItems() as $item)
137 {
138 $item->delete();
139 }
140 }
141
145 protected function getDeletableItems()
146 {
147 return $this->collection;
148 }
149
150
154 protected function callEventOnBeforeCollectionClear()
155 {
157
158 $eventsList = $eventManager->findEventHandlers('sale', 'OnBeforeCollectionClear');
159 if (!empty($eventsList))
160 {
162 $event = new Main\Event('sale', 'OnBeforeCollectionClear', array(
163 'COLLECTION' => $this->collection,
164 ));
165 $event->send();
166 }
167 }
168
175 public function getItemById($id)
176 {
177 if (intval($id) <= 0)
178 {
179 throw new Main\ArgumentNullException('id');
180 }
181
182 $index = $this->getIndexById($id);
183 if ($index === null)
184 {
185 return null;
186 }
187
188 if (isset($this->collection[$index]))
189 {
190 return $this->collection[$index];
191 }
192
193 return null;
194 }
195
196
203 public function getIndexById($id)
204 {
205 if (intval($id) <= 0)
206 {
207 throw new Main\ArgumentNullException('id');
208 }
209
211 foreach ($this->collection as $item)
212 {
213 if ($item->getId() > 0 && $id == $item->getId())
214 {
215 return $item->getInternalIndex();
216 }
217 }
218 return null;
219 }
220
227 public function getItemByIndex($index)
228 {
229 if (intval($index) < 0)
230 {
231 throw new Main\ArgumentNullException('id');
232 }
233
235 foreach ($this->collection as $item)
236 {
237 if ($item->getInternalIndex() == $index)
238 {
239 return $item;
240 }
241 }
242 return null;
243 }
244
248 abstract protected function getEntityParent();
249
254 public function isStartField($isMeaningfulField = false)
255 {
256 $parent = $this->getEntityParent();
257 if ($parent === null)
258 {
259 return false;
260 }
261
262 return $parent->isStartField($isMeaningfulField);
263 }
264
268 public function clearStartField()
269 {
270 $parent = $this->getEntityParent();
271 if ($parent === null)
272 {
273 return false;
274 }
275
276 return $parent->clearStartField();
277 }
278
282 public function hasMeaningfulField()
283 {
284 $parent = $this->getEntityParent();
285 if ($parent === null)
286 {
287 return false;
288 }
289
290 return $parent->hasMeaningfulField();
291 }
292
297 public function doFinalAction($hasMeaningfulField = false)
298 {
299 $parent = $this->getEntityParent();
300 if ($parent === null)
301 {
302 return new Sale\Result();
303 }
304
305 return $parent->doFinalAction($hasMeaningfulField);
306 }
307
311 public function isMathActionOnly()
312 {
313 $parent = $this->getEntityParent();
314 if ($parent === null)
315 {
316 return false;
317 }
318
319 return $parent->isMathActionOnly();
320 }
321
326 public function setMathActionOnly($value = false)
327 {
328 $parent = $this->getEntityParent();
329 if ($parent == null)
330 {
331 return false;
332 }
333
334 return $parent->setMathActionOnly($value);
335 }
336
340 public function isChanged()
341 {
342 if (count($this->collection) > 0)
343 {
345 foreach ($this->collection as $item)
346 {
347 if ($item->isChanged())
348 {
349 return true;
350 }
351 }
352 }
353
354 return $this->isAnyItemDeleted() || $this->isAnyItemAdded();
355 }
356
360 public function verify()
361 {
362 return new Sale\Result();
363 }
364
368 public function isClone()
369 {
370 return $this->isClone;
371 }
372
373
377 public function isAnyItemDeleted()
378 {
379 return $this->anyItemDeleted;
380 }
381
387 protected function setAnyItemDeleted($value)
388 {
389 return $this->anyItemDeleted = ($value === true);
390 }
391
395 public function isAnyItemAdded()
396 {
397 return $this->anyItemAdded;
398 }
399
405 protected function setAnyItemAdded($value)
406 {
407 return $this->anyItemAdded = ($value === true);
408 }
409
413 public function clearChanged()
414 {
415 if (!empty($this->collection))
416 {
417 foreach ($this->collection as $entityItem)
418 {
419 if ($entityItem instanceof Entity)
420 {
421 $entityItem->clearChanged();
422 }
423 }
424 }
425 }
426
433 public function createClone(\SplObjectStorage $cloneEntity)
434 {
435 if ($this->isClone() && $cloneEntity->contains($this))
436 {
437 return $cloneEntity[$this];
438 }
439
440 $entityClone = clone $this;
441 $entityClone->isClone = true;
442
443 if (!$cloneEntity->contains($this))
444 {
445 $cloneEntity[$this] = $entityClone;
446 }
447
452 foreach ($entityClone->collection as $key => $entity)
453 {
454 if (!$cloneEntity->contains($entity))
455 {
456 $cloneEntity[$entity] = $entity->createClone($cloneEntity);
457 }
458
459 $entityClone->collection[$key] = $cloneEntity[$entity];
460 }
461
462 return $entityClone;
463 }
464}
Определения event.php:5
static getInstance()
Определения eventmanager.php:31
setMathActionOnly($value=false)
Определения entitycollection.php:326
doFinalAction($hasMeaningfulField=false)
Определения entitycollection.php:297
isStartField($isMeaningfulField=false)
Определения entitycollection.php:254
bindItem(CollectableEntity $item)
Определения entitycollection.php:109
onItemModify(CollectableEntity $item, $name=null, $oldValue=null, $value=null)
Определения entitycollection.php:36
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entity
$name
Определения menu_edit.php:35
Определения ufield.php:9
$event
Определения prolog_after.php:141
if(empty($signedUserToken)) $key
Определения quickway.php:257
$eventManager
Определения include.php:412