From eac0883cbc61e4d4f0fff17f817a207b46e237f0 Mon Sep 17 00:00:00 2001 From: rMalie Date: Tue, 6 Dec 2011 15:59:23 +0000 Subject: [PATCH] // Can add / delete element from Collection --- classes/Collection.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/classes/Collection.php b/classes/Collection.php index 8f5c7944d..9450ab586 100644 --- a/classes/Collection.php +++ b/classes/Collection.php @@ -229,13 +229,31 @@ class CollectionCore implements Iterator, ArrayAccess, Countable return $this->results[$offset]; } + /** + * Add an element in the collection + * + * @param $offset + * @param $value + */ public function offsetSet($offset, $value) { - throw new PrestashopException('It is forbidden to override a result in a collection'); + if (!$value instanceof $this->classname) + throw new PrestashopException('You cannot add an element which is not an instance of '.$this->classname); + + $this->getAll(); + if (is_null($offset)) + $this->results[] = $value; + else + $this->results[$offset] = $value; } + /** + * Delete an element from the collection + * + * @param $offset + */ public function offsetUnset($offset) { - throw new PrestashopException('It is forbidden to unset a result in a collection'); + unset($this->results[$offset]); } } \ No newline at end of file