Example #1
0
 /**
  * Add Link to Multimedia Object
  *
  * @param MultimediaObject $multimediaObject
  * @param Link $link
  * @return MultimediaObject
  */
 public function addLinkToMultimediaObject(MultimediaObject $multimediaObject, Link $link)
 {
     $multimediaObject->addLink($link);
     $this->dm->persist($multimediaObject);
     $this->dm->flush();
     // NOTE Workaround to fix embedded documents modifications
     $this->dm->clear(get_class($multimediaObject));
     return $this->dm->find('PumukitSchemaBundle:MultimediaObject', $multimediaObject->getId());
 }
 public function testEmbedLinksInMultimediaObject()
 {
     $link1 = new Link();
     $link2 = new Link();
     $link3 = new Link();
     $this->dm->persist($link1);
     $this->dm->persist($link2);
     $this->dm->persist($link3);
     $mm = new MultimediaObject();
     $mm->addLink($link1);
     $mm->addLink($link2);
     $mm->addLink($link3);
     $this->dm->persist($mm);
     $this->dm->flush();
     $this->assertEquals($link1, $this->repo->find($mm->getId())->getLinkById($link1->getId()));
     $this->assertEquals($link2, $this->repo->find($mm->getId())->getLinkById($link2->getId()));
     $this->assertEquals($link3, $this->repo->find($mm->getId())->getLinkById($link3->getId()));
     $this->assertNull($this->repo->find($mm->getId())->getLinkById(null));
     $mm->removeLinkById($link2->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $linksArray = array($link1, $link3);
     $this->assertEquals(count($linksArray), count($this->repo->find($mm->getId())->getLinks()));
     $this->assertEquals($linksArray, array_values($this->repo->find($mm->getId())->getLinks()->toArray()));
     $mm->upLinkById($link3->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $linksArray = array($link3, $link1);
     $this->assertEquals($linksArray, array_values($this->repo->find($mm->getId())->getLinks()->toArray()));
     $mm->downLinkById($link3->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $linksArray = array($link1, $link3);
     $this->assertEquals($linksArray, array_values($this->repo->find($mm->getId())->getLinks()->toArray()));
 }
 public function testGetLinksWithTag()
 {
     $mm = new MultimediaObject();
     $m1 = new Link();
     $m1->setTags(array('master'));
     $m2 = new Link();
     $m2->setTags(array('mosca', 'master', 'old'));
     $m3 = new Link();
     $m3->setTags(array('master', 'mosca'));
     $m4 = new Link();
     $m4->setTags(array('flv', 'itunes', 'hide'));
     $m5 = new Link();
     $m5->setTags(array('flv', 'webtv'));
     $mm->addLink($m3);
     $mm->addLink($m2);
     $mm->addLink($m1);
     $mm->addLink($m4);
     $mm->addLink($m5);
     $this->assertEquals(array($m3, $m2, $m1), $mm->getLinksWithTag('master'));
     $this->assertEquals($m3, $mm->getLinkWithTag('master'));
     $this->assertEquals(null, $mm->getLinkWithTag('del_universo'));
     $this->assertEquals($m3, $mm->getLinkWithAnyTag(array('master', 'pr')));
     $this->assertEquals(array($m2), $mm->getLinksWithAllTags(array('master', 'mosca', 'old')));
     $this->assertTrue(in_array($mm->getLinkWithAllTags(array('mosca', 'master')), array($m3, $m2)));
     $this->assertEquals(null, $mm->getLinkWithAllTags(array('mosca', 'master', 'del_universo')));
     $this->assertEquals(4, count($mm->getLinksWithAnyTag(array('master', 'webtv'))));
     $this->assertEquals(1, count($mm->getLinkWithAnyTag(array('master'))));
     $this->assertEquals(null, $mm->getLinkWithAnyTag(array('del_universo')));
     $this->assertEquals(5, count($mm->getFilteredLinksWithTags()));
     $this->assertEquals(3, count($mm->getFilteredLinksWithTags(array('master'))));
     $this->assertEquals(1, count($mm->getFilteredLinksWithTags(array('master'), array('mosca', 'old'))));
     $this->assertEquals(0, count($mm->getFilteredLinksWithTags(array(), array('mosca', 'old'), array('master'))));
     $this->assertEquals(3, count($mm->getFilteredLinksWithTags(array(), array(), array('flv'))));
     $this->assertEquals(0, count($mm->getFilteredLinksWithTags(array(), array(), array('flv', 'master'))));
     $this->assertEquals(5, count($mm->getFilteredLinksWithTags(array(), array(), array(), array('flv', 'master'))));
     $this->assertEquals(1, count($mm->getFilteredLinksWithTags(array('mosca', 'old'), array(), array(), array('old'))));
 }