Пример #1
0
 /**
  * Add a material from a file into the multimediaObject
  */
 public function addMaterialFile(MultimediaObject $multimediaObject, UploadedFile $materialFile, $formData)
 {
     if (UPLOAD_ERR_OK != $materialFile->getError()) {
         throw new \Exception($materialFile->getErrorMessage());
     }
     if (!is_file($materialFile->getPathname())) {
         throw new FileNotFoundException($materialFile->getPathname());
     }
     $material = new Material();
     $material = $this->saveFormData($material, $formData);
     $path = $materialFile->move($this->targetPath . "/" . $multimediaObject->getId(), $materialFile->getClientOriginalName());
     $material->setPath($path);
     $material->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
     $multimediaObject->addMaterial($material);
     $this->dm->persist($multimediaObject);
     $this->dm->flush();
     return $multimediaObject;
 }
 public function testEmbedMaterialsInMultimediaObject()
 {
     $material1 = new Material();
     $material2 = new Material();
     $material3 = new Material();
     $this->dm->persist($material1);
     $this->dm->persist($material2);
     $this->dm->persist($material3);
     $mm = new MultimediaObject();
     $mm->addMaterial($material1);
     $mm->addMaterial($material2);
     $mm->addMaterial($material3);
     $this->dm->persist($mm);
     $this->dm->flush();
     $this->assertEquals($material1, $this->repo->find($mm->getId())->getMaterialById($material1->getId()));
     $this->assertEquals($material2, $this->repo->find($mm->getId())->getMaterialById($material2->getId()));
     $this->assertEquals($material3, $this->repo->find($mm->getId())->getMaterialById($material3->getId()));
     $this->assertNull($this->repo->find($mm->getId())->getMaterialById(null));
     $mm->removeMaterialById($material2->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $materialsArray = array($material1, $material3);
     $this->assertEquals(count($materialsArray), count($this->repo->find($mm->getId())->getMaterials()));
     $this->assertEquals($materialsArray, array_values($this->repo->find($mm->getId())->getMaterials()->toArray()));
     $mm->upMaterialById($material3->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $materialsArray = array($material3, $material1);
     $this->assertEquals($materialsArray, array_values($this->repo->find($mm->getId())->getMaterials()->toArray()));
     $mm->downMaterialById($material3->getId());
     $this->dm->persist($mm);
     $this->dm->flush();
     $materialsArray = array($material1, $material3);
     $this->assertEquals($materialsArray, array_values($this->repo->find($mm->getId())->getMaterials()->toArray()));
 }
 public function testGetMaterialsWithTag()
 {
     $mm = new MultimediaObject();
     $m1 = new Material();
     $m1->setTags(array('master'));
     $m2 = new Material();
     $m2->setTags(array('mosca', 'master', 'old'));
     $m3 = new Material();
     $m3->setTags(array('master', 'mosca'));
     $m4 = new Material();
     $m4->setTags(array('flv', 'itunes', 'hide'));
     $m5 = new Material();
     $m5->setTags(array('flv', 'webtv'));
     $mm->addMaterial($m3);
     $mm->addMaterial($m2);
     $mm->addMaterial($m1);
     $mm->addMaterial($m4);
     $mm->addMaterial($m5);
     $this->assertEquals(array($m3, $m2, $m1), $mm->getMaterialsWithTag('master'));
     $this->assertEquals($m3, $mm->getMaterialWithTag('master'));
     $this->assertEquals(null, $mm->getMaterialWithTag('del_universo'));
     $this->assertEquals($m3, $mm->getMaterialWithAnyTag(array('master', 'pr')));
     $this->assertEquals(array($m2), $mm->getMaterialsWithAllTags(array('master', 'mosca', 'old')));
     $this->assertTrue(in_array($mm->getMaterialWithAllTags(array('mosca', 'master')), array($m3, $m2)));
     $this->assertEquals(null, $mm->getMaterialWithAllTags(array('mosca', 'master', 'del_universo')));
     $this->assertEquals(4, count($mm->getMaterialsWithAnyTag(array('master', 'webtv'))));
     $this->assertEquals(1, count($mm->getMaterialWithAnyTag(array('master'))));
     $this->assertEquals(null, $mm->getMaterialWithAnyTag(array('del_universo')));
     $this->assertEquals(5, count($mm->getFilteredMaterialsWithTags()));
     $this->assertEquals(3, count($mm->getFilteredMaterialsWithTags(array('master'))));
     $this->assertEquals(1, count($mm->getFilteredMaterialsWithTags(array('master'), array('mosca', 'old'))));
     $this->assertEquals(0, count($mm->getFilteredMaterialsWithTags(array(), array('mosca', 'old'), array('master'))));
     $this->assertEquals(3, count($mm->getFilteredMaterialsWithTags(array(), array(), array('flv'))));
     $this->assertEquals(0, count($mm->getFilteredMaterialsWithTags(array(), array(), array('flv', 'master'))));
     $this->assertEquals(5, count($mm->getFilteredMaterialsWithTags(array(), array(), array(), array('flv', 'master'))));
     $this->assertEquals(1, count($mm->getFilteredMaterialsWithTags(array('mosca', 'old'), array(), array(), array('old'))));
 }