Beispiel #1
0
 public function testCanShowImage()
 {
     $object = new ImageObject();
     $object->setObject('Blaat');
     $this->image->getObject()->add($object);
     $image = $this->ideaImage->__invoke($this->image);
     $this->assertContains('<img src', $image);
 }
 /**
  * Load the Image
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $image = new Image();
     $image->setContentType($manager->find("General\\Entity\\ContentType", 1));
     $image->setSize(1000);
     $image->setImage('This is the test-image');
     $image->setIdea($manager->find("Project\\Entity\\Idea\\Idea", 1));
     $imageObject = new ImageObject();
     $imageObject->setObject(file_get_contents(__DIR__ . '/../../assets/img/idea_image.jpg'));
     $imageObject->setImage($image);
     $manager->persist($imageObject);
     $manager->flush();
 }
Beispiel #3
0
 /**
  * @param Idea $idea
  * @param      $fileData
  * @param null $alternativeName
  */
 public function addFileToIdea(Idea $idea, $fileData, $alternativeName = null)
 {
     //Parse first the type of file to see in which table it should be stored
     $mimeType = new MimeType();
     $mimeType->isValid($fileData);
     /*
      * Use the fileSize validator to validate the size
      */
     $fileSize = new FilesSize(PHP_INT_MAX);
     $fileSize->isValid($fileData);
     $contentType = $this->getGeneralService()->findContentTypeByContentTypeName($fileData['type']);
     switch ($mimeType->type) {
         case 'application/pdf':
             //All treated as document
         //All treated as document
         case 'application/msword':
             //All treated as document
         //All treated as document
         case 'application/vnd.ms-excel':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
             $ideaDocument = new Document();
             $ideaDocument->setIdea($idea);
             $ideaDocument->setFilename($fileData['name']);
             $ideaDocument->setSize($fileSize->size);
             if (is_null($alternativeName)) {
                 $ideaDocument->setDocument($fileData['name']);
             } else {
                 $ideaDocument->setDocument($alternativeName);
             }
             $ideaDocumentObject = new DocumentObject();
             $ideaDocumentObject->setObject(file_get_contents($fileData['tmp_name']));
             $ideaDocument->setContentType($contentType);
             $ideaDocumentObject->setDocument($ideaDocument);
             $this->newEntity($ideaDocumentObject);
             break;
         case 'image/jpeg':
         case 'image/png':
             $ideaImage = new Image();
             $ideaImage->setIdea($idea);
             if (is_null($alternativeName)) {
                 $ideaImage->setImage($fileData['name']);
             } else {
                 $ideaImage->setImage($alternativeName);
             }
             $ideaImage->setSize($fileSize->size);
             $ideaImage->setContentType($contentType);
             $ideaImageObject = new ImageObject();
             $ideaImageObject->setObject(file_get_contents($fileData['tmp_name']));
             $thumb = new GD($fileData['tmp_name']);
             $thumb->resize(200);
             $ideaImageObject->setThumb($thumb->getImageAsString());
             $ideaImageObject->setImage($ideaImage);
             $this->newEntity($ideaImageObject);
             break;
     }
 }