private function createTagWithCode($code, $title, $tagParentCode = null, $metatag = false) { if ($tag = $this->tagRepo->findOneByCod($code)) { throw new \Exception("Nothing done - Tag retrieved from DB id: " . $tag->getId() . " cod: " . $tag->getCod()); } $tag = new Tag(); $tag->setCod($code); $tag->setMetatag($metatag); $tag->setDisplay(true); $tag->setTitle($title, 'es'); $tag->setTitle($title, 'gl'); $tag->setTitle($title, 'en'); if ($tagParentCode) { if ($parent = $this->tagRepo->findOneByCod($tagParentCode)) { $tag->setParent($parent); } elseif ('CHANNELS' === $tagParentCode) { $channelTag = $this->createTagWithCode('CHANNELS', 'CHANNELS', 'ROOT', true); $tag->setParent($channelTag); } elseif ('ROOT' === $tagParentCode) { throw new \Exception("Nothing done - There is no tag in the database with code " . $tagParentCode . " to be the parent tag. Please init Pumukit tags"); } } $this->dm->persist($tag); $this->dm->flush(); return $tag; }
public function createTestTree() { $tag = new Tag(); $tag->setCod("ROOT"); $this->dm->persist($tag); $this->dm->flush(); $tagA = new Tag(); $tagA->setCod("A"); $tagA->setParent($tag); $this->dm->persist($tagA); $tagB = new Tag(); $tagB->setCod("B"); $tagB->setParent($tag); $this->dm->persist($tagB); $tagB1 = new Tag(); $tagB1->setCod("B1"); $tagB1->setParent($tagB); $this->dm->persist($tagB1); $tagB2 = new Tag(); $tagB2->setCod("B2"); $tagB2->setParent($tagB); $this->dm->persist($tagB2); $tagB2A = new Tag(); $tagB2A->setCod("B2A"); $tagB2A->setParent($tagB2); $this->dm->persist($tagB2A); $this->dm->flush(); }
public function testGetterAndSetter() { $title = 'title'; $description = 'description'; $slug = 'slug'; $cod = 23; $metatag = true; $created = new \DateTime("now"); $updated = new \DateTime("now"); $display = true; $youtubeProperty = "w7dD-JJJytM&list=PLmXxqSJJq-yUfrjvKe5c5LX_1x7nGVF6c"; $properties = array('youtube' => $youtubeProperty); $tag = new Tag($title); $tag->setTitle($title); $tag->setDescription($description); $tag->setSlug($slug); $tag->setCod($cod); $tag->setMetatag($metatag); $tag->setCreated($created); $tag->setUpdated($updated); $tag->setDisplay($display); $tag->setProperties($properties); $tag_parent = new Tag("parent"); $tag->setParent($tag_parent); $this->assertEquals($title, $tag->getTitle()); $this->assertEquals($description, $tag->getDescription()); $this->assertEquals($slug, $tag->getSlug()); $this->assertEquals($cod, $tag->getCod()); $this->assertEquals($metatag, $tag->getMetatag()); $this->assertEquals($created, $tag->getCreated()); $this->assertEquals($updated, $tag->getUpdated()); $this->assertEquals($tag_parent, $tag->getParent()); $this->assertEquals($display, $tag->getDisplay()); $this->assertEquals($properties, $tag->getProperties()); $this->assertEquals(null, $tag->getLockTime()); $this->assertEquals('', $tag->getTitle('fr')); $this->assertEquals('', $tag->getDescription('fr')); $titleEs = 'título'; $titleArray = array('en' => $title, 'es' => $titleEs); $descriptionEs = 'descripción'; $descriptionArray = array('en' => $description, 'es' => $descriptionEs); $tag->setI18nTitle($titleArray); $tag->setI18nDescription($descriptionArray); $this->assertEquals($titleArray, $tag->getI18nTitle()); $this->assertEquals($descriptionArray, $tag->getI18nDescription()); $this->assertEquals($tag->getTitle(), $tag->__toString()); $testProperty = 'test property'; $tag->setProperty('test', $testProperty); $this->assertEquals($youtubeProperty, $tag->getProperty('youtube')); $this->assertEquals($testProperty, $tag->getProperty('test')); $testProperty = null; $tag->setProperty('test', $testProperty); $this->assertEquals($testProperty, $tag->getProperty('test')); }
/** * @ParamConverter("tag", class="PumukitSchemaBundle:Tag", options={"id" = "parent"}) * @Template */ public function createAction(Tag $parent, Request $request) { $dm = $this->get('doctrine_mongodb')->getManager(); $repo = $dm->getRepository('PumukitSchemaBundle:Tag'); $tag = new Tag(); $tag->setParent($parent); $translator = $this->get('translator'); $locale = $request->getLocale(); $form = $this->createForm(new TagType($translator, $locale), $tag); if (($request->isMethod('PUT') || $request->isMethod('POST')) && $form->bind($request)->isValid()) { try { $dm->persist($tag); $dm->flush(); } catch (\Exception $e) { return new JsonResponse(array("status" => $e->getMessage()), 409); } return $this->redirect($this->generateUrl('pumukitnewadmin_tag_list')); } return array('tag' => $tag, 'form' => $form->createView()); }
/** * */ private function createTagFromCsvArray($csv_array, $tag_parent = null) { if ($tag = $this->tagsRepo->findOneByCod($csv_array[1])) { throw new \LengthException("Nothing done - Tag retrieved from DB id: " . $tag->getId() . " cod: " . $tag->getCod()); } $tag = new Tag(); $tag->setCod($csv_array[1]); $tag->setMetatag($csv_array[3]); $tag->setDisplay($csv_array[4]); if ($tag_parent) { $tag->setParent($tag_parent); } $tag->setTitle($csv_array[5], 'es'); // NOTE Take care of csv language order! if (isset($csv_array[6])) { $tag->setTitle($csv_array[6], 'gl'); } if (isset($csv_array[7])) { $tag->setTitle($csv_array[7], 'en'); } $this->dm->persist($tag); return $tag; }
public function testFindRelatedMultimediaObjects() { $broadcast = $this->createBroadcast(Broadcast::BROADCAST_TYPE_PUB); $tagUNESCO = new Tag(); $tagUNESCO->setCod('UNESCO'); $tag1 = new Tag(); $tag1->setCod('tag1'); $tag2 = new Tag(); $tag2->setCod('tag2'); $tag3 = new Tag(); $tag3->setCod('tag3'); $tag1->setParent($tagUNESCO); $tag2->setParent($tagUNESCO); $tag3->setParent($tagUNESCO); $this->dm->persist($tag1); $this->dm->persist($tag2); $this->dm->persist($tag3); $this->dm->persist($tagUNESCO); $this->dm->flush(); $series1 = $this->createSeries('Series 1'); $mm11 = $this->factoryService->createMultimediaObject($series1); $mm12 = $this->factoryService->createMultimediaObject($series1); $mm13 = $this->factoryService->createMultimediaObject($series1); $series2 = $this->createSeries('Series 2'); $mm21 = $this->factoryService->createMultimediaObject($series2); $mm22 = $this->factoryService->createMultimediaObject($series2); $mm23 = $this->factoryService->createMultimediaObject($series2); $series3 = $this->createSeries('Series 3'); $mm31 = $this->factoryService->createMultimediaObject($series3); $mm32 = $this->factoryService->createMultimediaObject($series3); $mm33 = $this->factoryService->createMultimediaObject($series3); $mm11->addTag($tag1); $mm12->addTag($tag2); $mm13->addTag($tag1); $mm21->addTag($tag3); $mm22->addTag($tag1); $mm23->addTag($tag1); $mm31->addTag($tag1); $mm32->addTag($tag3); $mm33->addTag($tag3); $this->dm->persist($mm11); $this->dm->persist($mm12); $this->dm->persist($mm13); $this->dm->persist($mm21); $this->dm->persist($mm22); $this->dm->persist($mm23); $this->dm->persist($mm31); $this->dm->persist($mm32); $this->dm->persist($mm33); $this->dm->persist($series1); $this->dm->persist($series2); $this->dm->persist($series3); $this->dm->flush(); $this->assertEquals(0, count($this->repo->findRelatedMultimediaObjects($mm33))); }
public function testGetParentTags() { $tag = new Tag(); $tag->setCod("ROOT"); $this->dm->persist($tag); $this->dm->flush(); $tagA = new Tag(); $tagA->setCod("A"); $tagA->setParent($tag); $this->dm->persist($tagA); $tagB = new Tag(); $tagB->setCod("B"); $tagB->setParent($tag); $this->dm->persist($tagB); $tagB1 = new Tag(); $tagB1->setCod("B1"); $tagB1->setParent($tagB); $this->dm->persist($tagB1); $tagB2 = new Tag(); $tagB2->setCod("B2"); $tagB2->setParent($tagB); $this->dm->persist($tagB2); $tagB2A = new Tag(); $tagB2A->setCod("B2A"); $tagB2A->setParent($tagB2); $this->dm->persist($tagB2A); $this->dm->flush(); $this->assertEquals(2, count($this->factory->getParentTags())); }
public function syncMmobj($parsedTerena, \MongoDate $lastSyncDate = null) { if (!isset($lastSyncDate)) { $lastSyncDate = new \MongoDate(); } $factory = $this->factoryService; $mmobj = $this->mmobjRepo->createQueryBuilder()->field('properties.geant_id')->equals($parsedTerena['identifier'])->getQuery()->getSingleResult(); $series = $this->seriesRepo->createQueryBuilder()->field('properties.geant_provider')->equals($parsedTerena['provider'])->getQuery()->getSingleResult(); if (!isset($series)) { $series = $factory->createSeries(); $series->setProperty('geant_provider', $parsedTerena['provider']); $series->setTitle($parsedTerena['provider']); $this->dm->persist($series); $this->dm->flush(); } //We assume the 'provider' property of a feed won't change for the same Geant Feed Resource. //If it changes, the mmobj would keep it's original provider. if (!isset($mmobj)) { $mmobj = $factory->createMultimediaObject($series, false); $mmobj->setProperty('geant_id', $parsedTerena['identifier']); //Add 'provider' tag $providerTag = $this->tagRepo->findOneByCod($parsedTerena['provider']); if (!isset($providerTag)) { $providerTag = new Tag(); $providerTag->setParent($this->providerRootTag); $providerTag->setCod($parsedTerena['provider']); $providerTag->setTitle($parsedTerena['provider']); $providerTag->setDisplay(true); $providerTag->setMetatag(false); $this->dm->persist($providerTag); } $this->tagService->addTagToMultimediaObject($mmobj, $providerTag->getId(), false); } else { $feedUpdatedDate = $mmobj->getProperty('feed_updated_date'); //We will disable this 'improvement' for now. We can consider to add it with an optional parameter on the future. /*if (!$feedUpdatedDate || $feedUpdatedDate < $parsedTerena['lastUpdateDate']) { $mmobj->setProperty('feed_updated_date', new \MongoDate($parsedTerena['lastUpdateDate']->getTimestamp())); } else { $mmobj->setProperty('last_sync_date', $lastSyncDate); $series->setProperty('last_sync_date', $lastSyncDate); $mmobj->setStatus(MultimediaObject::STATUS_PUBLISHED); $this->dm->persist($mmobj); return 0; }*/ } $mmobj->setProperty('last_sync_date', $lastSyncDate); $series->setProperty('last_sync_date', $lastSyncDate); //PUBLISH $mmobj->setStatus(MultimediaObject::STATUS_PUBLISHED); $this->tagService->addTagToMultimediaObject($mmobj, $this->webTVTag->getId(), false); //METADATA $this->syncMetadata($mmobj, $parsedTerena); //TAGS $this->syncTags($mmobj, $parsedTerena); //PEOPLE $this->syncPeople($mmobj, $parsedTerena); //TRACK $this->syncTrack($mmobj, $parsedTerena); //THUMBNAIL $this->syncThumbnail($mmobj, $parsedTerena); //Errors if ($parsedTerena['geantErrors']) { $mmobj->setProperty('geant_errors', $parsedTerena['geantErrors']); } else { $mmobj->setProperty('geant_errors', null); } //SAVE CHANGES $this->dm->persist($mmobj); $this->dm->persist($series); }
private function createTagWithTree($cod, $withROOT = true) { if ($withROOT) { $rootTag = $this->tagRepo->findOneByCod('ROOT'); if (null == $rootTag) { $rootTag = new Tag(); $rootTag->setCod('ROOT'); $this->dm->persist($rootTag); } } else { $rootTag = $this->tagRepo->findOneByCod('grandparent'); if (null == $rootTag) { $rootTag = new Tag(); $rootTag->setCod('grandparent'); $this->dm->persist($rootTag); } } $locale = 'en'; $parentTag = $this->tagRepo->findOneByCod('parent'); if (null == $parentTag) { $parentTag = new Tag(); $parentTag->setLocale($locale); $parentTag->setCod('parent'); $parentTag->setTitle('Parent'); $parentTag->setParent($rootTag); $this->dm->persist($parentTag); } $tag = new Tag(); $tag->setLocale($locale); $tag->setCod($cod); $tag->setTitle(ucfirst($cod)); $tag->setParent($parentTag); $this->dm->persist($tag); $broTag = $this->tagRepo->findOneByCod('brother'); if (null == $broTag) { $broTag = new Tag(); $broTag->setLocale($locale); $broTag->setCod('brother'); $broTag->setTitle('Brother'); $broTag->setParent($parentTag); $this->dm->persist($broTag); } $this->dm->flush(); return $tag; }