Exemple #1
0
 /**
  * Add tag
  *
  * @param RestBundle\Entity\Tag $tag
  */
 public function addTag(\RestBundle\Entity\Tag $tag)
 {
     if ($this->getTags() != null) {
         foreach ($this->getTags() as $tagObject) {
             if ($tag === $tagObject) {
                 return false;
             }
         }
     }
     $tag->addPhotos($this);
     $this->tags[] = $tag;
     return true;
 }
 /**
  * Create a new Photo.
  *
  * @param array $parameters
  *
  * @return PhotoInterface
  */
 public function post(array $parameters)
 {
     $photo = new Photo();
     $manager = $this->om->getRepository('RestBundle:Tag');
     $tagList = [];
     if (isset($parameters['tags'])) {
         foreach ($parameters['tags'] as $tag) {
             $tagObject = $manager->findOneBy(['caption' => trim($tag)]);
             if ($tagObject == null) {
                 $tagObject = new Tag();
                 $tagObject->setCaption($tag);
                 $this->om->persist($tagObject);
             }
             $tagList[] = $tagObject;
         }
     }
     $this->om->flush();
     $photo->addTags($tagList);
     return $this->processForm($photo, $parameters, 'POST');
 }