Ejemplo n.º 1
0
 /**
  * Remove a product from the basket.
  *
  * @param Product $product
  * @param int     $nb
  *
  * @return $this
  */
 public function removeProduct(Product $product, $nb = 1)
 {
     if ($this->products->containsKey($product->getId())) {
         $this->decreaseNbProduct($product, $nb);
         $nbLeft = $this->getNbProduct($product);
         if (0 >= $nbLeft) {
             $this->products->remove($product->getId());
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * This function performs a kind of "intersection union" operation, and is useful especially when dealing
  * with dynamic forms. For instance, if a collection contains existing elements and a form remove one of those
  * elements, this function will return a Collection that contains all the elements from $collection1, minus ones
  * that are not present in $collection2. This is used internally in the DoctrineModule hydrator, so that the
  * work is done for you automatically
  *
  * @param  Collection $collection1
  * @param  Collection $collection2
  * @return Collection
  */
 public static function intersectUnion(Collection $collection1, Collection $collection2)
 {
     // Don't make the work both
     if ($collection1 === $collection2) {
         return $collection1;
     }
     $toRemove = array();
     foreach ($collection1 as $key1 => $value1) {
         $elementFound = false;
         foreach ($collection2 as $key2 => $value2) {
             if ($value1 === $value2) {
                 $elementFound = true;
                 unset($collection2[$key2]);
                 break;
             }
         }
         if (!$elementFound) {
             $toRemove[] = $key1;
         }
     }
     // Remove elements that are in $collection1 but not in $collection2
     foreach ($toRemove as $key) {
         $collection1->remove($key);
     }
     // Add elements that are in $collection2 but not in $collection1
     foreach ($collection2 as $value) {
         $collection1->add($value);
     }
     return $collection1;
 }
Ejemplo n.º 3
0
 /**
  * Removes the element at the specified index from the collection.
  *
  * @param string|integer $key The kex/index of the element to remove.
  *
  * @return mixed The removed element or NULL, if the collection did not contain the element.
  */
 function remove($key)
 {
     $this->initialize();
     $element = $this->collection->remove($key);
     if ($element) {
         $this->setDirty(true);
     }
     return $element;
 }
 public function testRemove()
 {
     $this->_coll[] = 'one';
     $this->_coll[] = 'two';
     $el = $this->_coll->remove(0);
     $this->assertEquals('one', $el);
     $this->assertEquals($this->_coll->contains('one'), false);
     $this->assertNull($this->_coll->remove(0));
 }
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     $this->initialize();
     $removed = $this->coll->remove($key);
     if (!$removed) {
         return $removed;
     }
     $this->changed();
     return $removed;
 }
 /**
  * Actual logic for removing element by its key.
  *
  * @param mixed $offset
  * @param bool $arrayAccess
  * @return mixed|void
  */
 private function doRemove($offset, $arrayAccess)
 {
     $this->initialize();
     $removed = $arrayAccess ? $this->coll->offsetUnset($offset) : $this->coll->remove($offset);
     if (!$removed && !$arrayAccess) {
         return $removed;
     }
     $this->changed();
     return $removed;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     $this->initialize();
     $removed = $this->coll->remove($key);
     if ($removed) {
         $this->changed();
         if ($this->isOrphanRemovalEnabled()) {
             $this->uow->scheduleOrphanRemoval($removed);
         }
     }
     return $removed;
 }
Ejemplo n.º 8
0
 public function removeModifier(string $name)
 {
     $this->modifiers->remove($name);
 }
Ejemplo n.º 9
0
 public function remove($key)
 {
     $this->initialize();
     $this->changed = true;
     return $this->col->remove($key);
 }
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     // TODO: If the keys are persistent as well (not yet implemented)
     //       and the collection is not initialized and orphanRemoval is
     //       not used we can issue a straight SQL delete/update on the
     //       association (table). Without initializing the collection.
     $this->initialize();
     $removed = $this->coll->remove($key);
     if ($removed) {
         $this->changed();
         if ($this->association !== null && $this->association['type'] == ClassMetadata::ONE_TO_MANY && $this->association['orphanRemoval']) {
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($removed);
         }
     }
     return $removed;
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function removeChild($name)
 {
     $name = $name instanceof ItemInterface ? $name->getName() : $name;
     $child = $this->getChild($name);
     if ($child !== null) {
         $child->setParent(null);
         $this->children->remove($name);
     }
     return $this;
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function removeReview(ReviewInterface $review)
 {
     $this->reviews->remove($review);
 }
Ejemplo n.º 13
0
Archivo: Role.php Proyecto: sulu/sulu
 /**
  * Remove setting.
  *
  * @param RoleSettingInterface $setting
  */
 public function removeSetting(RoleSettingInterface $setting)
 {
     $this->settings->remove($setting->getKey());
 }
 /**
  * @param ThirdParty $thirdParty
  *
  * @return bool
  */
 public function removeThirdParty(ThirdParty $thirdParty)
 {
     return (bool) $this->thirdPartyCredentials->remove($thirdParty);
 }
Ejemplo n.º 15
0
 /**
  * @param Lesson $lesson
  */
 public function removeLesson(Lesson $lesson)
 {
     $this->lessons->remove($lesson);
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     $this->_initialize();
     $removed = $this->_coll->remove($key);
     return $removed;
 }
Ejemplo n.º 17
0
 /**
  * @param PageAttribute $att
  */
 public function removeAttribute(PageAttribute $att)
 {
     $this->attributes->remove($att);
 }
 /**
  * @param RoleInterface $role
  */
 public function removeRole(RoleInterface $role)
 {
     $this->roles->remove($role);
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     // TODO: If the keys are persistent as well (not yet implemented)
     //       and the collection is not initialized and orphanRemoval is
     //       not used we can issue a straight SQL delete/update on the
     //       association (table). Without initializing the collection.
     $this->_initialize();
     $removed = $this->_coll->remove($key);
     if ($removed) {
         $this->_changed();
         if ($this->_association !== null && $this->_association->isOneToMany() && $this->_association->orphanRemoval) {
             $this->_em->getUnitOfWork()->scheduleOrphanRemoval($removed);
         }
     }
     return $removed;
 }
Ejemplo n.º 20
0
 /**
  * @param EmailAttachment $attachment
  */
 public function removeAttachment(EmailAttachment $attachment)
 {
     if ($this->attachments->contains($attachment)) {
         $this->attachments->remove($attachment);
     }
 }
Ejemplo n.º 21
0
 /**
  * Removes an element from the collection.
  *
  * @param mixed $key
  * @return boolean
  * @override
  */
 public function remove($key)
 {
     //TODO: delete entity if shouldDeleteOrphans
     /*if ($this->_association->isOneToMany() && $this->_association->shouldDeleteOrphans()) {
           $this->_em->delete($removed);
       }*/
     $removed = parent::remove($key);
     if ($removed) {
         $this->_changed();
     }
     return $removed;
 }
 /**
  * {@inheritDoc}
  */
 public function remove($key)
 {
     $this->initialize();
     return $this->collection->remove($key);
 }
Ejemplo n.º 23
0
 /**
  * @param array
  */
 public function setPieces(array $pieces)
 {
     foreach ($this->pieces as $index => $p) {
         $this->pieces->remove($index);
     }
     foreach ($pieces as $piece) {
         $this->addPiece($piece);
     }
 }
Ejemplo n.º 24
0
 public function testCanRemoveNullValuesByKey()
 {
     $this->_coll->add(null);
     $this->_coll->remove(0);
     $this->assertTrue($this->_coll->isEmpty());
 }
Ejemplo n.º 25
0
 /**
  * @param Entity\Session $session
  */
 public function removeOrder(Entity\Order $order)
 {
     $this->orders->remove($order);
 }