Example #1
0
 public function check(EntityManager $em, File $file)
 {
     $boolean = false;
     if (method_exists($file->getMedia(), 'getWidth')) {
         $boolean = $file->getMedia()->getWidth() >= $this->width && $file->getMedia()->getHeight() >= $this->height;
     }
     return new Response($boolean, $this);
 }
Example #2
0
 public function check(EntityManager $em, File $file)
 {
     // if empty authorize all mediative
     if (0 === count($this->mediaTypes)) {
         $boolean = true;
     } else {
         $boolean = in_array($file->getMedia()->getType(), $this->mediaTypes);
     }
     return new Response($boolean, $this);
 }
Example #3
0
 public function check(EntityManager $em, File $file)
 {
     $boolean = false;
     if (0 === count($this->colorspaces)) {
         $boolean = true;
         //bypass color if empty array
     } elseif (method_exists($file->getMedia(), 'getColorSpace')) {
         $colorspace = null;
         switch ($file->getMedia()->getColorSpace()) {
             case \MediaVorus\Media\Image::COLORSPACE_CMYK:
                 $colorspace = self::COLORSPACE_CMYK;
                 break;
             case \MediaVorus\Media\Image::COLORSPACE_RGB:
             case \MediaVorus\Media\Image::COLORSPACE_SRGB:
                 $colorspace = self::COLORSPACE_RGB;
                 break;
             case \MediaVorus\Media\Image::COLORSPACE_GRAYSCALE:
                 $colorspace = self::COLORSPACE_GRAYSCALE;
                 break;
         }
         $boolean = $colorspace !== null && in_array(strtolower($colorspace), $this->colorspaces);
     }
     return new Response($boolean, $this);
 }
Example #4
0
 /**
  *
  * @param File        $file
  * @param Application $app
  *
  * @return \record_adapter
  */
 public static function createFromFile(File $file, Application $app)
 {
     $databox = $file->getCollection()->get_databox();
     $sql = 'INSERT INTO record
           (coll_id, record_id, parent_record_id, moddate, credate
             , type, sha256, uuid, originalname, mime)
         VALUES
           (:coll_id, null, :parent_record_id, NOW(), NOW()
           , :type, :sha256, :uuid
           , :originalname, :mime)';
     $stmt = $databox->get_connection()->prepare($sql);
     $stmt->execute([':coll_id' => $file->getCollection()->get_coll_id(), ':parent_record_id' => 0, ':type' => $file->getType() ? $file->getType()->getType() : 'unknown', ':sha256' => $file->getMedia()->getHash('sha256'), ':uuid' => $file->getUUID(true), ':originalname' => $file->getOriginalName(), ':mime' => $file->getFile()->getMimeType()]);
     $record_id = $databox->get_connection()->lastInsertId();
     $record = new self($app, $databox->get_sbas_id(), $record_id);
     try {
         $log_id = $app['phraseanet.logger']($databox)->get_id();
         $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment)
         VALUES (null, :log_id, now(),
           :record_id, "add", :coll_id,"")';
         $stmt = $databox->get_connection()->prepare($sql);
         $stmt->execute([':log_id' => $log_id, ':record_id' => $record_id, ':coll_id' => $file->getCollection()->get_coll_id()]);
         $stmt->closeCursor();
     } catch (\Exception $e) {
         unset($e);
     }
     $pathhd = databox::dispatch($app['filesystem'], trim($databox->get_sxml_structure()->path));
     $newname = $record->get_record_id() . "_document." . pathinfo($file->getOriginalName(), PATHINFO_EXTENSION);
     $app['filesystem']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true);
     $media = $app['mediavorus']->guess($pathhd . $newname);
     media_subdef::create($app, $record, 'document', $media);
     $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS);
     $record->insertTechnicalDatas($app['mediavorus']);
     $record->rebuild_subdefs();
     return $record;
 }
Example #5
0
 /**
  * Add technical Metadata attribute to a package file by reference to add it
  * to Phraseanet
  *
  * @param File $file The file
  */
 protected function addMediaAttributes(File $file)
 {
     $metadataCollection = $this->app['phraseanet.metadata-reader']->read($file->getMedia());
     array_walk($metadataCollection, function (Metadata $metadata) use($file) {
         $file->addAttribute(new MetadataAttr($metadata));
     });
     return $this;
 }
Example #6
0
 /**
  * Add technical Metadata attribute to a package file by reference to add it
  * to Phraseanet
  *
  * @param  File                        $file The file
  * @return \Doctrine\ORM\EntityManager
  */
 protected function addMediaAttributes(File $file)
 {
     if (method_exists($file->getMedia(), 'getWidth')) {
         $file->addAttribute(new MetadataAttr(new Metadata(new TfWidth(), new MonoValue($file->getMedia()->getWidth()))));
     }
     if (method_exists($file->getMedia(), 'getHeight')) {
         $file->addAttribute(new MetadataAttr(new Metadata(new TfHeight(), new MonoValue($file->getMedia()->getHeight()))));
     }
     if (method_exists($file->getMedia(), 'getChannels')) {
         $file->addAttribute(new MetadataAttr(new Metadata(new TfChannels(), new MonoValue($file->getMedia()->getChannels()))));
     }
     if (method_exists($file->getMedia(), 'getColorDepth')) {
         $file->addAttribute(new MetadataAttr(new Metadata(new TfBits(), new MonoValue($file->getMedia()->getColorDepth()))));
     }
     if (method_exists($file->getMedia(), 'getDuration')) {
         $file->addAttribute(new MetadataAttr(new Metadata(new TfDuration(), new MonoValue($file->getMedia()->getDuration()))));
     }
     if ($file->getFile()->getMimeType() == 'application/pdf' && null !== $this->pdfToText) {
         try {
             $text = $this->pdfToText->getText($file->getFile()->getRealPath());
             if (trim($text)) {
                 $file->addAttribute(new MetadataAttr(new Metadata(new PdfText(), new MonoValue($text))));
             }
         } catch (\XPDF\Exception\Exception $e) {
         }
     }
     $file->addAttribute(new MetadataAttr(new Metadata(new TfMimetype(), new MonoValue($file->getFile()->getMimeType()))));
     $file->addAttribute(new MetadataAttr(new Metadata(new TfSize(), new MonoValue($file->getFile()->getSize()))));
     $file->addAttribute(new MetadataAttr(new Metadata(new TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME)))));
     $file->addAttribute(new MetadataAttr(new Metadata(new TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME)))));
     $file->addAttribute(new MetadataAttr(new Metadata(new TfExtension(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_EXTENSION)))));
     return $this;
 }
Example #7
0
 /**
  * @covers Alchemy\Phrasea\Border\File::getMedia
  */
 public function testGetMedia()
 {
     $this->assertInstanceof('\\MediaVorus\\Media\\Image', $this->object->getMedia());
 }