remove() public method

{@inheritDoc}
public remove ( $key )
 /**
  * @param mixed $valueOrObject
  * @param string $target
  * @return array
  */
 protected function toMany($valueOrObject, $target, Collection $collection = null, $depth = 2)
 {
     if (!is_array($valueOrObject) && !$valueOrObject instanceof Traversable) {
         $valueOrObject = (array) $valueOrObject;
     }
     if (!$collection instanceof Collection) {
         $collection = new ArrayCollection();
     }
     $keepers = array();
     foreach ($valueOrObject as $value) {
         if (method_exists($value, 'toArray')) {
             $value = $value->toArray($depth);
         } else {
             if (!is_array($value) && !$value instanceof Traversable) {
                 $value = (array) $value;
             }
         }
         if (isset($value['id']) && strlen($value['id']) && ($found = $this->find($target, $value['id']))) {
             $keepers[] = $found->id;
             $this->hydrate($value, $found);
         } else {
             $obj = new $target();
             $obj->fromArray($value);
             $obj->id = null;
             if ($collection instanceof PersistentCollection) {
                 if ($owner = $collection->getOwner()) {
                     $mapping = $collection->getMapping();
                     $mappedBy = $mapping['mappedBy'];
                     $obj->{$mappedBy} = $owner;
                 }
             }
             $collection->add($obj);
         }
     }
     $collection->forAll(function ($key, $element) use($collection, $keepers) {
         if (strlen($element->id) && !in_array($element->id, $keepers)) {
             $collection->remove($key);
         }
     });
     return $collection;
 }
Example #2
0
 /**
  * @param Car $car
  * @return boolean
  */
 public function remove(Car $car)
 {
     if (!$this->has($car)) {
         return false;
     }
     $this->cars->remove($car->getId());
     $this->session->set('cart', $this->cars);
     return true;
 }
 /**
  * @param string $member
  * @return GroupOfNames
  */
 public function removeMember($member)
 {
     foreach ($this->members as $attr) {
         if ($attr->get() == $member) {
             $this->members->remove($attr);
             return $this;
         }
     }
     return $this;
 }
Example #4
0
 /**
  * @param ArrayCollection $joueurs
  * @return Ligue $this
  */
 public function removeJoueurs($joueurs)
 {
     foreach ($joueurs as $joueur) {
         $this->joueurs->remove($joueur);
     }
     return $this;
 }
 /**
  * Removes child channel from collection
  *
  * @param CircularReferenceEntity $child child
  *
  * @return void
  */
 private function removeChild(CircularReferenceEntity $child)
 {
     $index = $this->getChildren()->indexOf($child);
     if ($index !== false) {
         $this->Children->remove($index);
     }
 }
 public function remove($key)
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->remove($key);
 }
 public function removeQuestion(SurveyQuestion $question)
 {
     if ($this->questions->contains($question)) {
         $this->questions->remove($question);
         $question->setSurvey(null);
     }
 }
 /**
  * @param TermTaxonomy $taxonomy
  *
  * @return Term
  */
 public function removeTaxonomy(TermTaxonomy $taxonomy)
 {
     if ($this->taxonomies->contains($taxonomy)) {
         $this->taxonomies->remove($taxonomy);
     }
     return $this;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     foreach ($this->fields as $managerName => $method) {
         call_user_func(array(self::getElementMethod($this->model, $managerName, $method), 'remove'), $key);
     }
     return parent::remove($key);
 }
 /**
  * @param TermRelationships $relationship
  *
  * @return Term
  */
 public function removeRelationship(TermRelationships $relationship)
 {
     if ($this->relationships->contains($relationship)) {
         $this->relationships->remove($relationship);
     }
     return $this;
 }
Example #11
0
 public function removeReport(ReportModule $reportModule)
 {
     $index = $this->modules->indexOf($reportModule);
     if ($index !== null) {
         $this->modules->remove($index);
     }
     return $this;
 }
Example #12
0
 public function removeCourse(CourseModule $courseModule)
 {
     $index = $this->modules->indexOf($courseModule);
     if ($index !== null) {
         $this->modules->remove($index);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     $removedElement = parent::remove($key);
     if (null !== $removedElement) {
         unset($this->keys[(string) $removedElement]);
     }
     return $removedElement;
 }
Example #14
0
 /**
  * @param $item
  * @param $key
  */
 protected function setProcessed(ImportItemProcess $item, $key)
 {
     $this->entityManager->remove($item);
     $this->itemProcessCollection->remove($key);
     $this->importLog->addProcessItemCount();
     $this->processedItemCount++;
     $index = $item->getItemIndex();
     $this->setItemLogIndex($index);
 }
Example #15
0
 /**
  * Drops a Collection - removing all data
  *
  * @param  string $collection  The name of the Collection to drop
  */
 public function drop($collection)
 {
     if (!$this->collections->containsKey($collection)) {
         return false;
     }
     $this->collections->get($collection)->drop();
     $this->collections->remove($collection);
     return true;
 }
Example #16
0
 /**
  * Remove an Etudiant from this Bus
  * @param Etudiant $etudiant The person to add
  * @return Affectation Result from this, see BdE\WeiBundle\Utils\Affectation
  */
 public function removeEtudiant(Etudiant $etudiant)
 {
     if (!$etudiant) {
         return Affectation::Error;
     }
     if (!$this->students->contains($etudiant)) {
         return Affectation::Error;
     }
     $this->students->remove($etudiant);
     return Affectation::OK;
 }
Example #17
0
 public function deleteQuestion($questionId)
 {
     $delKey = null;
     foreach ($this->questions->toArray() as $key => $val) {
         if ($val->getId() == $questionId) {
             $delKey = $key;
         }
     }
     if (!is_null($delKey)) {
         $this->questions->remove($delKey);
     }
 }
Example #18
0
 protected function addRoute(ControllerCollection $ctr, $name, array $config)
 {
     $config = new ArrayCollection($config);
     if (!($path = $config['path'])) {
         return;
     }
     if (!($defaults = $config['defaults'])) {
         return;
     }
     $defaults = new ArrayCollection($defaults);
     if (!($to = $defaults->remove('_controller'))) {
         return;
     }
     $route = $ctr->match($path, $to);
     $before = $defaults->remove('_before') ?: '::before';
     $before = $this->resolveBefore($before);
     $route->before($before);
     $after = $defaults->remove('_after') ?: '::after';
     $after = $this->resolveAfter($after);
     $route->after($after);
     foreach ($defaults as $key => $value) {
         $route->value($key, $value);
     }
     foreach ($config['requirements'] ?: [] as $variable => $callback) {
         $callback = $this->callbackResolver->resolveCallback($callback);
         $requirement = is_callable($callback) ? call_user_func($callback) : $callback;
         $route->assert($variable, $requirement);
     }
     if ($host = $config['host']) {
         $route->getRoute()->setHost($host);
     }
     if ($methods = $config['methods']) {
         $route->getRoute()->setMethods($methods);
     }
     if ($schemes = $config['schemes']) {
         $route->getRoute()->setSchemes($schemes);
     }
     $route->bind($name);
 }
 /**
  * Method for separating collection to "exists" and "new" items
  */
 public function ranking()
 {
     foreach ($this->collection as $key => $item) {
         // Extending each array element by number field
         $item['number'] = $key;
         if (isset($item['id']) && $item['id']) {
             // Add item to "exists" collection
             $this->exists->add($item);
         } else {
             // Add item to "new" collection
             $this->new->add($item);
         }
         // Clear result for memory free
         $this->collection->remove($key);
     }
 }
 /**
  * Deletes all ACEs the given type and security identity from the list of ACEs associated with this item
  *
  * @param string      $type  The ACE type. Can be one of AclManager::*_ACE constants
  * @param string|null $field The name of a field.
  *                           Set to null for class-based or object-based ACE
  *                           Set to not null class-field-based or object-field-based ACE
  * @param SID $sid
  */
 public function removeAces($type, $field, SID $sid)
 {
     if ($this->aces !== null) {
         $toRemoveKeys = [];
         foreach ($this->aces as $key => $val) {
             if ($sid->equals($val->getSecurityIdentity()) && $type === $val->getType() && $field === $val->getField()) {
                 $toRemoveKeys[] = $key;
                 break;
             }
         }
         if (!empty($toRemoveKeys)) {
             foreach ($toRemoveKeys as $key) {
                 $this->aces->remove($key);
             }
         }
     }
 }
 /**
  * Filtering collection
  *
  * @param ArrayCollection|CrudEntityInterface[] $collection Collection
  * @param bool                                  $replace    replace
  *
  * @return CrudUnitOfWork
  */
 public function filterCollection(ArrayCollection $collection, $replace = true)
 {
     $unitOfWork = new CrudUnitOfWork();
     foreach ($collection as $entity) {
         if ($entity->getId()) {
             $crudEntity = $this->find(get_class($entity), $entity->getId());
         } else {
             $this->crudTransformer->initializeClassMetadata(get_class($entity));
             $conditions = $this->crudTransformer->getUniqueSearchConditions($entity);
             $crudEntity = $this->entityManager->getRepository(get_class($entity))->findOneBy($conditions);
         }
         if ($crudEntity instanceof CrudEntityInterface) {
             if ($replace) {
                 $key = $collection->indexOf($entity);
                 $collection->remove($key);
                 $collection->set($key, $crudEntity);
             }
             $unitOfWork->update($crudEntity);
         } else {
             $unitOfWork->insert($entity);
         }
     }
     return $unitOfWork;
 }
Example #22
0
 public function testRemove()
 {
     $elements = array(1, 'A' => 'a', 2, 'B' => 'b', 3);
     $collection = new ArrayCollection($elements);
     $this->assertEquals(1, $collection->remove(0));
     unset($elements[0]);
     $this->assertEquals(null, $collection->remove('non-existent'));
     unset($elements['non-existent']);
     $this->assertEquals(2, $collection->remove(1));
     unset($elements[1]);
     $this->assertEquals('a', $collection->remove('A'));
     unset($elements['A']);
     $this->assertEquals($elements, $collection->toArray());
 }
 /**
  * @param $referenceMany
  */
 public function removeReferenceMany($referenceMany)
 {
     foreach ($referenceMany as $key => $record) {
         $this->referenceMany->remove($key);
     }
 }
Example #24
0
 /**
  * @param Website $website
  *
  * @return Product
  */
 public function removeWebsite(Website $website)
 {
     if ($this->websites->contains($website)) {
         $this->websites->remove($website);
     }
     return $this;
 }
 public function removeBeer(BeerEntity $beer)
 {
     $this->beers->remove($beer);
 }
Example #26
0
 /**
  * @param Counterpart $counterpart
  * @return $this
  */
 public function removeCounterpart(Counterpart $counterpart)
 {
     $this->counterparts->remove($counterpart->getId());
     return $this;
 }
Example #27
0
 /**
  * @param Article $article
  */
 public function removeArticles(Article $article)
 {
     $this->articles->remove($article);
     $article->setTicket(null);
 }
Example #28
0
 public function setAttribute($name, $value)
 {
     if (isset($this->attributes[$name])) {
         if ($value == null) {
             $this->attributes->remove($name);
         } else {
             $this->attributes[$name]->setValue($value);
         }
     } else {
         $this->attributes[$name] = new Zikula_Doctrine2_Entity_CategoryAttribute($this->getId(), 'A', $name, $value);
     }
 }
Example #29
0
 /**
  * @param  Publisher $publisher
  * @return $this
  */
 public function removePublisher(Publisher $publisher)
 {
     $this->publishers->remove($publisher);
     return $this;
 }
 /**
  * @param Attribute $authRole
  * @return LenticularUser
  */
 public function removeAuthRole($authRole)
 {
     foreach ($this->authRoles as $authRole) {
         if ($authRole->get() == $authRole) {
             $this->authRoles->remove($authRole);
         }
     }
     return $this;
 }