56 public function deleteItem($index)
58 if (!isset($this->collection[$index]))
63 $oldItem = $this->collection[$index];
65 $eventManager = Main\EventManager::getInstance();
66 $eventsList = $eventManager->findEventHandlers(
'sale',
'OnBeforeCollectionDeleteItem');
67 if (!empty($eventsList))
70 $event =
new Main\Event(
'sale',
'OnBeforeCollectionDeleteItem', array(
71 'COLLECTION' => $this->collection,
77 unset($this->collection[$index]);
88 protected function addItem(CollectableEntity $item)
91 $item->setInternalIndex($index);
93 $this->collection[$index] = $item;
96 $eventManager = Main\EventManager::getInstance();
97 $eventsList = $eventManager->findEventHandlers(
'sale',
'OnCollectionAddItem');
98 if (!empty($eventsList))
101 $event =
new Main\Event(
'sale',
'OnCollectionAddItem', array(
102 'COLLECTION' => $this->collection,
124 public function clearCollection()
126 $this->callEventOnBeforeCollectionClear();
147 protected function callEventOnBeforeCollectionClear()
149 $eventManager = Main\EventManager::getInstance();
151 $eventsList = $eventManager->findEventHandlers(
'sale',
'OnBeforeCollectionClear');
152 if (!empty($eventsList))
155 $event =
new Main\Event(
'sale',
'OnBeforeCollectionClear', array(
156 'COLLECTION' => $this->collection,
170 if (intval($id) <= 0)
175 $index = $this->getIndexById($id);
181 if (isset($this->collection[$index]))
183 return $this->collection[$index];
196 public function getIndexById($id)
198 if (intval($id) <= 0)
204 foreach ($this->collection as $item)
206 if ($item->getId() > 0 && $id == $item->getId())
208 return $item->getInternalIndex();
220 public function getItemByIndex($index)
222 if (intval($index) < 0)
224 throw new Main\ArgumentNullException(
'id');
228 foreach ($this->collection as $item)
230 if ($item->getInternalIndex() == $index)
250 if ($parent ===
null)
255 return $parent->isStartField($isMeaningfulField);
264 if ($parent ===
null)
269 return $parent->clearStartField();
278 if ($parent ===
null)
283 return $parent->hasMeaningfulField();
293 if ($parent ===
null)
298 return $parent->doFinalAction($hasMeaningfulField);
307 if ($parent ===
null)
312 return $parent->isMathActionOnly();
327 return $parent->setMathActionOnly($value);
333 public function isChanged()
335 if (
count($this->collection) > 0)
338 foreach ($this->collection as $item)
340 if ($item->isChanged())
382 return $this->anyItemDeleted = ($value ===
true);
400 return $this->anyItemAdded = ($value ===
true);
408 if (!empty($this->collection))
410 foreach ($this->collection as $entityItem)
412 if ($entityItem instanceof
Entity)
414 $entityItem->clearChanged();
426 public function createClone(\SplObjectStorage $cloneEntity)
428 if ($this->
isClone() && $cloneEntity->contains($this))
430 return $cloneEntity[$this];
433 $entityClone = clone $this;
434 $entityClone->isClone =
true;
436 if (!$cloneEntity->contains($this))
438 $cloneEntity[$this] = $entityClone;
445 foreach ($entityClone->collection as $key => $entity)
447 if (!$cloneEntity->contains($entity))
449 $cloneEntity[$entity] = $entity->createClone($cloneEntity);
452 $entityClone->collection[$key] = $cloneEntity[$entity];