public function testEmbeddedTag()
 {
     $locale = 'en';
     $title = 'title';
     $description = 'description';
     $slug = 'slug';
     $cod = 23;
     $metatag = true;
     $created = new \DateTime("now");
     $updated = new \DateTime("now");
     $display = true;
     $tag = new Tag($title);
     $tag->setLocale($locale);
     $tag->setTitle($title);
     $tag->setDescription($description);
     $tag->setSlug($slug);
     $tag->setCod($cod);
     $tag->setMetatag($metatag);
     $tag->setCreated($created);
     $tag->setUpdated($updated);
     $tag->setDisplay($display);
     $titleEs = 'título';
     $titleArray = array('en' => $title, 'es' => $titleEs);
     $descriptionEs = 'descripción';
     $descriptionArray = array('en' => $description, 'es' => $descriptionEs);
     $tag->setI18nTitle($titleArray);
     $tag->setI18nDescription($descriptionArray);
     $mm = new MultimediaObject();
     $mm->addTag($tag);
     // TEST GETTERS
     $this->assertEquals($locale, $mm->getTags()[0]->getLocale());
     $this->assertEquals($title, $mm->getTags()[0]->getTitle());
     $this->assertEquals($description, $mm->getTags()[0]->getDescription());
     $this->assertEquals($slug, $mm->getTags()[0]->getSlug());
     $this->assertEquals($cod, $mm->getTags()[0]->getCod());
     $this->assertEquals($metatag, $mm->getTags()[0]->getMetatag());
     $this->assertEquals($created, $mm->getTags()[0]->getCreated());
     $this->assertEquals($updated, $mm->getTags()[0]->getUpdated());
     $this->assertEquals($display, $mm->getTags()[0]->getDisplay());
     $this->assertEquals($tag->getPath(), $mm->getTags()[0]->getPath());
     $this->assertEquals($tag->getLevel(), $mm->getTags()[0]->getLevel());
     $this->assertEquals('', $mm->getTags()[0]->getTitle('fr'));
     $this->assertEquals('', $mm->getTags()[0]->getDescription('fr'));
     $this->assertEquals($titleArray, $mm->getTags()[0]->getI18nTitle());
     $this->assertEquals($descriptionArray, $mm->getTags()[0]->getI18nDescription());
     $this->assertEquals($mm->getTags()[0]->getTitle(), $mm->getTags()[0]->__toString());
     // TEST SETTERS
     $title = 'modified title';
     $description = 'modified description';
     $slug = 'modified slug';
     $cod = 'modcod';
     $metatag = false;
     $created = new \DateTime("now");
     $updated = new \DateTime("now");
     $display = false;
     $mm->getTags()[0]->setTitle($title);
     $mm->getTags()[0]->setDescription($description);
     $mm->getTags()[0]->setSlug($slug);
     $mm->getTags()[0]->setCod($cod);
     $mm->getTags()[0]->setMetatag($metatag);
     $mm->getTags()[0]->setCreated($created);
     $mm->getTags()[0]->setUpdated($updated);
     $mm->getTags()[0]->setDisplay($display);
     $titleEs = 'título modificado';
     $titleArray = array('en' => $title, 'es' => $titleEs);
     $descriptionEs = 'descripción modificada';
     $descriptionArray = array('en' => $description, 'es' => $descriptionEs);
     $mm->getTags()[0]->setI18nTitle($titleArray);
     $mm->getTags()[0]->setI18nDescription($descriptionArray);
     $this->assertEquals($title, $mm->getTags()[0]->getTitle());
     $this->assertEquals($description, $mm->getTags()[0]->getDescription());
     $this->assertEquals($slug, $mm->getTags()[0]->getSlug());
     $this->assertEquals($cod, $mm->getTags()[0]->getCod());
     $this->assertEquals($metatag, $mm->getTags()[0]->getMetatag());
     $this->assertEquals($created, $mm->getTags()[0]->getCreated());
     $this->assertEquals($updated, $mm->getTags()[0]->getUpdated());
     $this->assertEquals($display, $mm->getTags()[0]->getDisplay());
     $this->assertEquals('', $mm->getTags()[0]->getTitle('fr'));
     $this->assertEquals('', $mm->getTags()[0]->getDescription('fr'));
     $this->assertEquals($titleArray, $mm->getTags()[0]->getI18nTitle());
     $this->assertEquals($descriptionArray, $mm->getTags()[0]->getI18nDescription());
     $this->assertEquals($mm->getTags()[0]->getTitle(), $mm->getTags()[0]->__toString());
     $locale = 'es';
     $mm->getTags()[0]->setLocale($locale);
     $this->assertEquals($titleEs, $mm->getTags()[0]->getTitle());
     $this->assertEquals($descriptionEs, $mm->getTags()[0]->getDescription());
 }
 /**
  * Find similar multimedia objects to a given one
  * with same tags, from different series,
  * broadcast public, status normal,
  * maximum 20 and random
  *
  * @param MultimediaObject $multimediaObject
  * @param array $tags
  * @return ArrayCollection
  */
 public function findRelatedMultimediaObjects(MultimediaObject $multimediaObject)
 {
     $qb = $this->createQueryBuilder()->field('_id')->notEqual($multimediaObject->getId())->field('series')->notEqual($multimediaObject->getSeries()->getId())->field('status')->equals(MultimediaObject::STATUS_PUBLISHED);
     // Broadcast public
     $broadcastRepo = $this->dm->getRepository('PumukitSchemaBundle:Broadcast');
     $broadcast = $broadcastRepo->findPublicBroadcast();
     $qb->field('broadcast')->references($broadcast);
     // Includes PUCHWEBTV code
     $tagRepo = $this->dm->getRepository('PumukitSchemaBundle:Tag');
     $unescoTag = $tagRepo->findOneByCod('UNESCO');
     $codes = array();
     foreach ($multimediaObject->getTags() as $tag) {
         if ($unescoTag) {
             if ($tag->isDescendantOf($unescoTag)) {
                 $codes[] = $tag->getCod();
             }
         }
     }
     $qb->field('tags.cod')->in($codes);
     // Limit 20 and random order
     $qb->limit(20)->sort('rank', mt_rand(0, 1) ? 1 : -1);
     $aux = $qb->getQuery()->execute();
     return $aux;
 }
 /**
  * Clone a multimedia object.
  *
  * @param  MultimediaObject $src
  * @return MultimediaObject
  */
 public function cloneMultimediaObject(MultimediaObject $src)
 {
     $new = new MultimediaObject();
     $new->setI18nTitle($src->getI18nTitle());
     $new->setI18nSubtitle($src->getI18nSubtitle());
     $new->setI18nDescription($src->getI18nDescription());
     $new->setI18nLine2($src->getI18nLine2());
     $new->setI18nKeyword($src->getI18nKeyword());
     $new->setCopyright($src->getCopyright());
     $new->setLicense($src->getLicense());
     // NOTE: #7408 Specify which properties are clonable
     $new->setProperty("subseries", $src->getProperty("subseries"));
     $new->setProperty("subseriestitle", $src->getProperty("subseriestitle"));
     $new->setProperty("clonedfrom", $src->getId());
     foreach ($src->getTags() as $tag) {
         $tagAdded = $this->tagService->addTagToMultimediaObject($new, $tag->getId(), false);
     }
     foreach ($src->getRoles() as $embeddedRole) {
         foreach ($embeddedRole->getPeople() as $embeddedPerson) {
             $new->addPersonWithRole($embeddedPerson, $embeddedRole);
         }
     }
     $new->setSeries($src->getSeries());
     if ($broadcast = $src->getBroadcast()) {
         $new->setBroadcast($broadcast);
         $this->dm->persist($broadcast);
     }
     $new->setPublicDate($src->getPublicDate());
     $new->setRecordDate($src->getRecordDate());
     $new->setStatus(MultimediaObject::STATUS_BLOQ);
     $this->dm->persist($new);
     $this->dm->flush();
     return $new;
 }