Пример #1
0
 public function load(ObjectManager $manager)
 {
     $data = $this->container->get('ilioscore.dataloader.learningMaterial')->getAll();
     $fs = new Filesystem();
     $storePath = $this->container->getParameter('ilios_core.file_store_path');
     foreach ($data as $arr) {
         $entity = new LearningMaterial();
         if (array_key_exists('id', $arr)) {
             $entity->setId($arr['id']);
         }
         $entity->setTitle($arr['title']);
         $entity->setDescription($arr['description']);
         $entity->setOriginalAuthor($arr['originalAuthor']);
         $entity->setCopyrightRationale($arr['copyrightRationale']);
         $entity->setCopyrightPermission($arr['copyrightPermission']);
         $entity->setUserRole($this->getReference('learningMaterialUserRoles' . $arr['userRole']));
         $entity->setStatus($this->getReference('learningMaterialStatus' . $arr['status']));
         $entity->setOwningUser($this->getReference('users' . $arr['owningUser']));
         $optional = ['link', 'citation', 'filename', 'mimetype', 'filesize', 'token'];
         foreach ($optional as $key) {
             if (array_key_exists($key, $arr)) {
                 $method = 'set' . ucfirst($key);
                 $entity->{$method}($arr[$key]);
             }
         }
         if (array_key_exists('relativePath', $arr)) {
             $entity->setRelativePath($arr['relativePath']);
             $fs->copy(__FILE__, $storePath . '/' . $arr['relativePath']);
         }
         $manager->persist($entity);
         $this->addReference('learningMaterials' . $arr['id'], $entity);
     }
     $manager->flush();
 }
Пример #2
0
 public function load(ObjectManager $manager)
 {
     $data = $this->container->get('ilioscore.dataloader.learningMaterial')->getAll();
     $fs = new Filesystem();
     $fakeTestFileDir = __DIR__ . '/FakeTestFiles';
     if (!$fs->exists($fakeTestFileDir)) {
         $fs->mkdir($fakeTestFileDir);
     }
     $fs->copy(__FILE__, $fakeTestFileDir . '/TESTFILE.txt');
     $storePath = $this->container->getParameter('ilios_core.file_store_path');
     foreach ($data as $arr) {
         $entity = new LearningMaterial();
         $entity->setId($arr['id']);
         $entity->setTitle($arr['title']);
         $entity->setDescription($arr['description']);
         $entity->setOriginalAuthor($arr['originalAuthor']);
         $entity->setCopyrightRationale($arr['copyrightRationale']);
         $entity->setCopyrightPermission($arr['copyrightPermission']);
         $entity->setUserRole($this->getReference('learningMaterialUserRoles' . $arr['userRole']));
         $entity->setStatus($this->getReference('learningMaterialStatus' . $arr['status']));
         $entity->setOwningUser($this->getReference('users' . $arr['owningUser']));
         $optional = ['mimetype', 'link', 'citation', 'filename', 'filesize'];
         foreach ($optional as $key) {
             if (array_key_exists($key, $arr)) {
                 $method = 'set' . ucfirst($key);
                 $entity->{$method}($arr[$key]);
             }
         }
         //copy a test file into the filestore for this file type LM
         if (array_key_exists('filesize', $arr)) {
             $path = $storePath . '/' . 'fakefile' . $arr['id'];
             $entity->setRelativePath('fakefile' . $arr['id']);
             $fs->copy(__FILE__, $path);
         }
         $entity->generateToken();
         $manager->persist($entity);
         $this->addReference('learningMaterials' . $arr['id'], $entity);
     }
     $manager->flush();
 }
Пример #3
0
 /**
  * @covers \Ilios\CoreBundle\Entity\LearningMaterial::getOwningSchool
  */
 public function testGetOwningSchool()
 {
     $this->assertNull($this->object->getOwningSchool());
     $school = new School();
     $user = new User();
     $user->setSchool($school);
     $lm = new LearningMaterial();
     $lm->setOwningUser($user);
     $this->assertSame($school, $lm->getOwningSchool());
     $user = new User();
     $lm = new LearningMaterial();
     $lm->setOwningUser($user);
     $this->assertNull($lm->getOwningSchool());
     $lm = new LearningMaterial();
     $this->assertNull($lm->getOwningSchool());
 }