57 public function deleteItem($index)
59 if (!isset($this->collection[$index]))
64 $oldItem = $this->collection[$index];
67 $eventsList =
$eventManager->findEventHandlers(
'sale',
'OnBeforeCollectionDeleteItem');
68 if (!empty($eventsList))
72 'COLLECTION' => $this->collection,
78 unset($this->collection[$index]);
79 $this->setAnyItemDeleted(
true);
88 protected function addItem(CollectableEntity $item)
90 $item = $this->bindItem($item);
92 $this->setAnyItemAdded(
true);
95 $eventsList =
$eventManager->findEventHandlers(
'sale',
'OnCollectionAddItem');
96 if (!empty($eventsList))
99 $event =
new Main\Event(
'sale',
'OnCollectionAddItem',
array(
100 'COLLECTION' => $this->collection,
113 $this->collection[$index] = $item;
131 public function clearCollection()
133 $this->callEventOnBeforeCollectionClear();
136 foreach ($this->getDeletableItems() as $item)
147 return $this->collection;
154 protected function callEventOnBeforeCollectionClear()
158 $eventsList =
$eventManager->findEventHandlers(
'sale',
'OnBeforeCollectionClear');
159 if (!empty($eventsList))
163 'COLLECTION' => $this->collection,
177 if (intval($id) <= 0)
182 $index = $this->getIndexById($id);
188 if (isset($this->collection[$index]))
190 return $this->collection[$index];
203 public function getIndexById($id)
205 if (intval($id) <= 0)
211 foreach ($this->collection as $item)
213 if ($item->getId() > 0 && $id == $item->getId())
215 return $item->getInternalIndex();
227 public function getItemByIndex($index)
229 if (intval($index) < 0)
231 throw new Main\ArgumentNullException(
'id');
235 foreach ($this->collection as $item)
237 if ($item->getInternalIndex() == $index)
257 if ($parent ===
null)
262 return $parent->isStartField($isMeaningfulField);
271 if ($parent ===
null)
276 return $parent->clearStartField();
285 if ($parent ===
null)
290 return $parent->hasMeaningfulField();
300 if ($parent ===
null)
305 return $parent->doFinalAction($hasMeaningfulField);
314 if ($parent ===
null)
319 return $parent->isMathActionOnly();
334 return $parent->setMathActionOnly($value);
340 public function isChanged()
342 if (
count($this->collection) > 0)
345 foreach ($this->collection as $item)
347 if ($item->isChanged())
354 return $this->isAnyItemDeleted() || $this->isAnyItemAdded();
370 return $this->isClone;
379 return $this->anyItemDeleted;
389 return $this->anyItemDeleted = ($value ===
true);
397 return $this->anyItemAdded;
407 return $this->anyItemAdded = ($value ===
true);
415 if (!empty($this->collection))
417 foreach ($this->collection as $entityItem)
419 if ($entityItem instanceof
Entity)
421 $entityItem->clearChanged();
433 public function createClone(\SplObjectStorage $cloneEntity)
435 if ($this->isClone() && $cloneEntity->contains($this))
437 return $cloneEntity[$this];
440 $entityClone = clone $this;
441 $entityClone->isClone =
true;
443 if (!$cloneEntity->contains($this))
445 $cloneEntity[$this] = $entityClone;
452 foreach ($entityClone->collection as
$key =>
$entity)
454 if (!$cloneEntity->contains(
$entity))
459 $entityClone->collection[
$key] = $cloneEntity[
$entity];