Example #1
0
 /**
  * Set groups
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 private function setGroups(\SimpleXMLElement $xml)
 {
     $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->children() as $groupXml) {
         $this->groups->add(Group::createFromXml($groupXml));
     }
 }
Example #2
0
 /**
  * Set remote content
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 private function setRemoteContent(\SimpleXMLElement $xml)
 {
     $this->remoteContent = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->children() as $remoteContentXml) {
         $this->remoteContent->add(RemoteContent::createFromXml($remoteContentXml));
     }
 }
Example #3
0
 /**
  * Set subjects
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 protected function setSubjects(\SimpleXMLElement $xml)
 {
     $this->subjects = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->subject as $subjectXml) {
         $this->subjects->add(Subject::createFromXml($subjectXml));
     }
 }
Example #4
0
 /**
  * Set catalog refs
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 public function setCatalogRefs(\SimpleXMLElement $xml)
 {
     $this->catalogRefs = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->catalogRef as $catalogRefXml) {
         $this->catalogRefs->add(new CatalogRef($catalogRefXml['href']));
     }
 }
Example #5
0
 /**
  * Set refs
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 public function setRefs($xml)
 {
     $this->refs = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->children() as $refXml) {
         if ($refXml->getName() === 'groupRef') {
             $this->refs->add(new GroupRef($refXml['idref']));
         } else {
             if ($refXml->getName() === 'itemRef') {
                 $this->refs->add(ItemRef::createFromXml($refXml));
             } else {
                 throw new \InvalidArgumentException("Expected group or item ref, got '{$refXml->getName()}'");
             }
         }
     }
 }
Example #6
0
 /**
  * Add item for this participant
  *
  * @param Doctrine\Common\Collections\Collection $items
  * @return Participant
  */
 public function addItems(Item $item)
 {
     if (!$this->items->contains($item)) {
         $this->items->add($item);
     }
     return $this;
 }
 /**
  * @param string $value
  * @param Doctrine\Common\Collections\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;
     }
     $className = $this->getOption('className');
     $values = explode($this->getOption('separator'), $value);
     if ($this->getOption('trim') === true) {
         $values = array_map('trim', $values);
     }
     /* @var $em Doctrine\ORM\EntityManager */
     $em = $this->getOption('em');
     $reflField = $em->getClassMetadata($className)->getReflectionProperty($this->getOption('fieldName'));
     // 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 = "SELECT o FROM " . $className . " o WHERE o." . $this->getOption('fieldName') . " IN (";
         $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('createInstanceCallback');
         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("Error while trying to create a new instance for " . "the identifier '" . $newValue . "'. No new instance was created.");
             }
             $collection->add($newInstance);
             $em->persist($newInstance);
         }
     }
     return $collection;
 }
Example #8
0
 /**
  * Add ban of a champion for this game
  *
  * @param Doctrine\Common\Collections\Collection $bans
  * @return Game
  */
 public function addBans(Champion $ban)
 {
     if (!$this->bans->contains($ban)) {
         $this->bans->add($ban);
     }
     return $this;
 }
Example #9
0
 /**
  * (non-PHPdoc)
  * @see \Rizza\CalendarBundle\Model\CalendarInterface::addEvent()
  */
 public function addEvent(EventInterface $event)
 {
     if (!$this->events->contains($event)) {
         $this->events->add($event);
     }
 }