/**
  * Set the list of roles
  * @param Collection $roles
  */
 public function setRoles(Collection $roles)
 {
     $this->roles->clear();
     foreach ($roles as $role) {
         $this->roles[] = $role;
     }
 }
 /**
  * setGroups
  *
  * Set the users groups.
  *
  * @param  UserGroup[]|\Traversable  $groups  The collection of user groups to set.
  *
  * @return $this
  */
 public function setGroups($groups)
 {
     $this->groups->clear();
     foreach ($groups as $group) {
         $this->addGroup($group);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Set tags
  *
  * @param Collection $tags Tags
  *
  * @return Product self Object
  */
 public function setTags(Collection $tags)
 {
     $this->tags->clear();
     if (!$tags->isEmpty()) {
         foreach ($tags as $tag) {
             $this->addTag($tag);
         }
     }
     return $this;
 }
 /**
  * setUsers
  *
  * Replace all current users with the provided collection.
  *
  * @param  UserInterface[]|Collection  $users  The new users collection to set.
  *
  * @return $this
  * @throws Exception\InvalidArgumentException  If the collection is not an array or \Traversable instance.
  */
 public function setUsers($users)
 {
     if (!is_array($users) && !$users instanceof \Traversable) {
         throw new Exception\InvalidArgumentException(sprintf('The \'users\' argument must be an \'array\' or object of type \'%s\'; \'%s\' given in \'%s\'', \Traversable::class, is_object($users) ? get_class($users) : gettype($users), __METHOD__));
     }
     $this->users->clear();
     foreach ($users as $user) {
         $this->addUser($user);
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Map a data to a collection of model objects.
  *
  * @param array $data An array of data.
  * @param callable $callable The callable you want to call for each row of data.
  * @return Collection A collection of objects.
  */
 protected function mapToObjects(array $data, callable $callable = null)
 {
     $this->collection->clear();
     if (count($data) > 0) {
         foreach ($data as $row) {
             if (is_callable($callable)) {
                 $this->collection->add(call_user_func($callable, $row));
             } else {
                 $this->collection->add($this->instantiateObject($row));
             }
         }
     }
     return clone $this->collection;
 }
Exemplo n.º 6
0
 /**
  * @param TranslationInterface[]|Collection $translations
  */
 public function setTranslations($translations)
 {
     $this->translations->clear();
     foreach ($translations as $translation) {
         $this->addTranslation($translation);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->isOrphanRemovalEnabled()) {
         $this->initialize();
         foreach ($this->coll as $element) {
             $this->uow->scheduleOrphanRemoval($element);
         }
     }
     $this->mongoData = array();
     $this->coll->clear();
     // Nothing to do for inverse-side collections
     if (!$this->mapping['isOwningSide']) {
         return;
     }
     // Nothing to do if the collection was initialized but contained no data
     if ($this->initialized && empty($this->snapshot)) {
         return;
     }
     $this->changed();
     $this->uow->scheduleCollectionDeletion($this);
     $this->takeSnapshot();
 }
Exemplo n.º 8
0
 public function testClear()
 {
     $this->_coll[] = 'one';
     $this->_coll[] = 'two';
     $this->_coll->clear();
     $this->assertEquals($this->_coll->isEmpty(), true);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function setVariants(Collection $variants)
 {
     $this->variants->clear();
     foreach ($variants as $variant) {
         $this->addVariant($variant);
     }
 }
Exemplo n.º 10
0
 /**
  * Sets this variant option values.
  *
  * @param Collection $options
  *
  * @return $this Self object
  */
 public function setOptions(Collection $options)
 {
     /*
      * We want to be able to assign an empty
      * ArrayCollection to variant options
      *
      * When the collection is not empty, each
      * option in the collection will be added
      * separately since it needs to update the
      * parent product attribute list
      */
     if ($options->isEmpty()) {
         $this->options = $options;
     } else {
         $this->options->clear();
     }
     /**
      * @var ValueInterface $option
      */
     foreach ($options as $option) {
         /*
          * We need to update the parent product attribute collection
          */
         $this->addOption($option);
     }
     return $this;
 }
Exemplo n.º 11
0
 /**
  * Set addresses.
  *
  * This method could not be named setAddresses because of bug CRM-253.
  *
  * @param Collection|AbstractAddress[] $addresses
  * @return BasePerson
  */
 public function resetAddresses($addresses)
 {
     $this->addresses->clear();
     foreach ($addresses as $address) {
         $this->addAddress($address);
     }
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Set children locales
  *
  * @param Collection|Locale[] $locales
  *
  * @return Locale
  */
 public function resetLocales($locales)
 {
     $this->childLocales->clear();
     foreach ($locales as $locale) {
         $this->addChildLocale($locale);
     }
     return $this;
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     $this->coll->clear();
     $this->changed();
     $this->takeSnapshot();
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     $this->_initialize();
     $result = $this->_coll->clear();
     if ($this->_mapping->isOwningSide) {
         $this->_changed();
         $this->_dm->getUnitOfWork()->scheduleCollectionDeletion($this);
     }
     return $result;
 }
Exemplo n.º 15
0
 /**
  * {@inheritDoc}
  */
 public function partition(Closure $p)
 {
     $array = $this->toArray();
     $this->collection->clear();
     foreach ($array as $key => $element) {
         $this->collection->set($key, $element);
     }
     $partitions = $this->collection->partition($p);
     return [new static($partitions[0]), new static($partitions[1])];
 }
Exemplo n.º 16
0
 /**
  * @param Collection $groups
  */
 public function setGroups($groups)
 {
     foreach ($this->groups as $group) {
         $this->removeGroup($group);
     }
     $this->groups->clear();
     foreach ($groups as $group) {
         $this->addGroup($group);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->isOrphanRemovalEnabled()) {
         foreach ($this->coll as $element) {
             $this->uow->scheduleOrphanRemoval($element);
         }
     }
     $this->mongoData = array();
     $this->coll->clear();
     if ($this->mapping['isOwningSide']) {
         $this->changed();
         $this->uow->scheduleCollectionDeletion($this);
         $this->takeSnapshot();
     }
 }
Exemplo n.º 18
0
 /**
  * don't clone id to create a new entities.
  */
 public function __clone()
 {
     if ($this->id) {
         $this->id = null;
         /** @var FileVersionMeta[] $newMetaList */
         $newMetaList = [];
         $defaultMetaLocale = $this->getDefaultMeta()->getLocale();
         /** @var FileVersionContentLanguage[] $newContentLanguageList */
         $newContentLanguageList = [];
         /** @var FileVersionPublishLanguage[] $newPublishLanguageList */
         $newPublishLanguageList = [];
         /** @var FileVersionMeta $meta */
         foreach ($this->meta as $meta) {
             $newMetaList[] = clone $meta;
         }
         $this->meta->clear();
         foreach ($newMetaList as $newMeta) {
             $newMeta->setFileVersion($this);
             $this->addMeta($newMeta);
             if ($newMeta->getLocale() === $defaultMetaLocale) {
                 $this->setDefaultMeta($newMeta);
             }
         }
         /** @var FileVersionContentLanguage $contentLanguage */
         foreach ($this->contentLanguages as $contentLanguage) {
             $newContentLanguageList[] = clone $contentLanguage;
         }
         $this->contentLanguages->clear();
         foreach ($newContentLanguageList as $newContentLanguage) {
             $newContentLanguage->setFileVersion($this);
             $this->addContentLanguage($newContentLanguage);
         }
         /** @var FileVersionPublishLanguage $publishLanguage */
         foreach ($this->publishLanguages as $publishLanguage) {
             $newPublishLanguageList[] = clone $publishLanguage;
         }
         $this->publishLanguages->clear();
         foreach ($newPublishLanguageList as $newPublishLanguage) {
             $newPublishLanguage->setFileVersion($this);
             $this->addPublishLanguage($newPublishLanguage);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->association['type'] == ClassMetadata::ONE_TO_MANY && $this->association['orphanRemoval']) {
         // we need to initialize here, as orphan removal acts like implicit cascadeRemove,
         // hence for event listeners we need the objects in memory.
         $this->initialize();
         foreach ($this->coll as $element) {
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($element);
         }
     }
     $this->coll->clear();
     $this->initialized = true;
     // direct call, {@link initialize()} is too expensive
     if ($this->association['isOwningSide']) {
         $this->changed();
         $this->em->getUnitOfWork()->scheduleCollectionDeletion($this);
         $this->takeSnapshot();
     }
 }
Exemplo n.º 20
0
 public function removeAllEmployment()
 {
     if (isset($this->employment)) {
         $this->employment->clear();
     }
 }
 /**
  * {@inheritDoc}
  */
 public function clear()
 {
     $this->initialize();
     $this->collection->clear();
 }
Exemplo n.º 22
0
 /**
  * Pass an array or Collection of Role objects and re-set roles collection with new Roles.
  * Type hinted array due to interface.
  *
  * @param  array|Collection $roles Array of Role objects
  *
  * @return User
  * @throws \InvalidArgumentException
  */
 public function setRoles($roles)
 {
     if (!$roles instanceof Collection && !is_array($roles)) {
         throw new \InvalidArgumentException('$roles must be an instance of Doctrine\\Common\\Collections\\Collection or an array');
     }
     $this->roles->clear();
     foreach ($roles as $role) {
         $this->addRole($role);
     }
     return $this;
 }
Exemplo n.º 23
0
 /**
  * Helper function which checks the option configuration for the passed collection.
  * If the data property contains the "__options_$optionName" value and this value contains
  * the "replace" parameter the collection will be cleared.
  *
  * @param Collection $collection
  * @param $data
  * @param $optionName
  * @param $defaultReplace
  * @return \Doctrine\Common\Collections\Collection
  */
 protected function checkDataReplacement(Collection $collection, $data, $optionName, $defaultReplace)
 {
     $key = '__options_' . $optionName;
     if (isset($data[$key])) {
         if ($data[$key]['replace']) {
             $collection->clear();
         }
     } elseif ($defaultReplace) {
         $collection->clear();
     }
     return $collection;
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     $this->tasks->clear();
 }
Exemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->association->isOneToMany() && $this->association->orphanRemoval) {
         foreach ($this->coll as $element) {
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($element);
         }
     }
     $this->coll->clear();
     if ($this->association->isOwningSide) {
         $this->changed();
         $this->em->getUnitOfWork()->scheduleCollectionDeletion($this);
         $this->takeSnapshot();
     }
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function clearAdjustments()
 {
     $this->adjustments->clear();
     $this->recalculateAdjustmentsTotal();
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function removeShipments()
 {
     $this->shipments->clear();
 }
Exemplo n.º 28
0
 /**
  * @param string     $value
  * @param Collection $collection
  */
 public function reverseTransform($value, $collection)
 {
     if (strlen(trim($value)) == 0) {
         // don't check for collection count, a straight clear doesnt initialize the collection
         $collection->clear();
         return $collection;
     }
     $callback = $this->getOption('explode_callback');
     $values = call_user_func($callback, $this->getOption('separator'), $value);
     if ($this->getOption('trim') === true) {
         $values = array_map('trim', $values);
     }
     /* @var $em Doctrine\ORM\EntityManager */
     $em = $this->getOption('em');
     $className = $this->getOption('class_name');
     $reflField = $em->getClassMetadata($className)->getReflectionProperty($this->getOption('field_name'));
     // 1. removing elements that are not yet present anymore
     foreach ($collection as $object) {
         $uniqueIdent = $reflField->getValue($object);
         $key = array_search($uniqueIdent, $values);
         if ($key === false) {
             $collection->removeElement($object);
         } else {
             // found in the collection, no need to do anything with it so remove it
             unset($values[$key]);
         }
     }
     // 2. add elements that are known to the EntityManager but newly connected, query them from the repository
     if (count($values)) {
         $dql = sprintf('SELECT o FROM %s o WHERE o.%s IN (', $className, $this->getOption('field_name'));
         $query = $em->createQuery();
         $needles = array();
         $i = 0;
         foreach ($values as $val) {
             $query->setParameter(++$i, $val);
             $needles[] = '?' . $i;
         }
         $dql .= implode(',', $needles) . ')';
         $query->setDql($dql);
         $newElements = $query->getResult();
         foreach ($newElements as $object) {
             $collection->add($object);
             $uniqueIdent = $reflField->getValue($object);
             $key = array_search($uniqueIdent, $values);
             unset($values[$key]);
         }
     }
     // 3. new elements that are not in the repository have to be created and persisted then attached:
     if (count($values)) {
         $callback = $this->getOption('create_instance_callback');
         if (!$callback || !is_callable($callback)) {
             throw new TransformationFailedException('Cannot transform list of identifiers, because a new element was detected and it is unknown how to create an instance of this element.');
         }
         foreach ($values as $newValue) {
             $newInstance = call_user_func($callback, $newValue);
             if (!$newInstance instanceof $className) {
                 throw new TransformationFailedException(sprintf('Error while trying to create a new instance for the identifier "%s". No new instance was created.', $newValue));
             }
             $collection->add($newInstance);
             $em->persist($newInstance);
         }
     }
     return $collection;
 }
 /**
  * Removes all the items from the container
  *
  * @return $this
  */
 public function clearItems()
 {
     $this->items->clear();
     return $this;
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function clearAdjustments()
 {
     return $this->adjustments->clear();
 }