/** * Set a pic from an url into the multimediaObject */ public function addPicFile(MultimediaObject $multimediaObject, UploadedFile $picFile) { if (UPLOAD_ERR_OK != $picFile->getError()) { throw new \Exception($picFile->getErrorMessage()); } if (!is_file($picFile->getPathname())) { throw new FileNotFoundException($picFile->getPathname()); } $path = $picFile->move($this->targetPath . "/" . $multimediaObject->getId(), $picFile->getClientOriginalName()); $pic = new Pic(); $pic->setUrl(str_replace($this->targetPath, $this->targetUrl, $path)); $pic->setPath($path); $multimediaObject->addPic($pic); $this->dm->persist($multimediaObject); $this->dm->flush(); return $multimediaObject; }
public function testEmbedPicsInMultimediaObject() { $pic1 = new Pic(); $pic2 = new Pic(); $pic3 = new Pic(); $pic4 = new Pic(); $this->dm->persist($pic1); $this->dm->persist($pic2); $this->dm->persist($pic3); $this->dm->persist($pic4); $mm = new MultimediaObject(); $mm->addPic($pic1); $mm->addPic($pic2); $mm->addPic($pic3); $this->dm->persist($mm); $this->dm->flush(); $this->assertEquals($mm, $this->repo->findByPicId($pic1->getId())); $this->assertEquals(null, $this->repo->findByPicId($pic4->getId())); $this->assertEquals($pic1, $this->repo->find($mm->getId())->getPicById($pic1->getId())); $this->assertEquals($pic2, $this->repo->find($mm->getId())->getPicById($pic2->getId())); $this->assertEquals($pic3, $this->repo->find($mm->getId())->getPicById($pic3->getId())); $this->assertNull($this->repo->find($mm->getId())->getPicById(null)); $mm->removePicById($pic2->getId()); $this->dm->persist($mm); $this->dm->flush(); $picsArray = array($pic1, $pic3); $this->assertEquals(count($picsArray), count($this->repo->find($mm->getId())->getPics())); $this->assertEquals($picsArray, array_values($this->repo->find($mm->getId())->getPics()->toArray())); $mm->upPicById($pic3->getId()); $this->dm->persist($mm); $this->dm->flush(); $picsArray = array($pic3, $pic1); $this->assertEquals($picsArray, array_values($this->repo->find($mm->getId())->getPics()->toArray())); $mm->downPicById($pic3->getId()); $this->dm->persist($mm); $this->dm->flush(); $picsArray = array($pic1, $pic3); $this->assertEquals($picsArray, array_values($this->repo->find($mm->getId())->getPics()->toArray())); }
public function testGetPicsWithTag() { $mm = new MultimediaObject(); $p1 = new Pic(); $p1->setTags(array('master')); $p2 = new Pic(); $p2->setTags(array('master', 'mosca', 'old')); $p3 = new Pic(); $p3->setTags(array('master', 'mosca')); $p4 = new Pic(); $p4->setTags(array('flv', 'itunes', 'hide')); $p5 = new Pic(); $p5->setTags(array('flv', 'webtv')); $mm->addPic($p3); $mm->addPic($p2); $mm->addPic($p1); $mm->addPic($p4); $mm->addPic($p5); $this->assertEquals(array($p3, $p2, $p1), $mm->getPicsWithTag('master')); $this->assertEquals($p3, $mm->getPicWithTag('master')); $this->assertEquals(null, $mm->getPicWithTag('del_universo')); $this->assertEquals($p3, $mm->getPicWithAnyTag(array('master', 'pr'))); $this->assertEquals(array($p2), $mm->getPicsWithAllTags(array('master', 'mosca', 'old'))); $this->assertTrue(in_array($mm->getPicWithAllTags(array('mosca', 'master')), array($p3, $p2))); $this->assertEquals(null, $mm->getPicWithAllTags(array('mosca', 'master', 'del_universo'))); $this->assertEquals(4, count($mm->getPicsWithAnyTag(array('master', 'webtv')))); $this->assertEquals(1, count($mm->getPicWithAnyTag(array('master')))); $this->assertEquals(null, $mm->getPicWithAnyTag(array('del_universo'))); $this->assertEquals(5, count($mm->getFilteredPicsWithTags())); $this->assertEquals(3, count($mm->getFilteredPicsWithTags(array('master')))); $this->assertEquals(1, count($mm->getFilteredPicsWithTags(array('master'), array('mosca', 'old')))); $this->assertEquals(0, count($mm->getFilteredPicsWithTags(array(), array('mosca', 'old'), array('master')))); $this->assertEquals(3, count($mm->getFilteredPicsWithTags(array(), array(), array('flv')))); $this->assertEquals(0, count($mm->getFilteredPicsWithTags(array(), array(), array('flv', 'master')))); $this->assertEquals(5, count($mm->getFilteredPicsWithTags(array(), array(), array(), array('flv', 'master')))); $this->assertEquals(1, count($mm->getFilteredPicsWithTags(array('mosca', 'old'), array(), array(), array('old')))); }