/** * 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; }
/** * 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; }
/** * 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; }
/** * {@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; }
public function removeModifier(string $name) { $this->modifiers->remove($name); }
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; }
/** * {@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; }
/** * {@inheritdoc} */ public function removeReview(ReviewInterface $review) { $this->reviews->remove($review); }
/** * 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); }
/** * @param Lesson $lesson */ public function removeLesson(Lesson $lesson) { $this->lessons->remove($lesson); }
/** * {@inheritdoc} */ public function remove($key) { $this->_initialize(); $removed = $this->_coll->remove($key); return $removed; }
/** * @param PageAttribute $att */ public function removeAttribute(PageAttribute $att) { $this->attributes->remove($att); }
/** * @param RoleInterface $role */ public function removeRole(RoleInterface $role) { $this->roles->remove($role); }
/** * {@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; }
/** * @param EmailAttachment $attachment */ public function removeAttachment(EmailAttachment $attachment) { if ($this->attachments->contains($attachment)) { $this->attachments->remove($attachment); } }
/** * 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); }
/** * @param array */ public function setPieces(array $pieces) { foreach ($this->pieces as $index => $p) { $this->pieces->remove($index); } foreach ($pieces as $piece) { $this->addPiece($piece); } }
public function testCanRemoveNullValuesByKey() { $this->_coll->add(null); $this->_coll->remove(0); $this->assertTrue($this->_coll->isEmpty()); }
/** * @param Entity\Session $session */ public function removeOrder(Entity\Order $order) { $this->orders->remove($order); }