/** * @param File $value * @param AbstractPlatform $platform * @return string * @throws \RuntimeException */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!$value) { return ''; } if (false === $value instanceof File) { throw new \RuntimeException("Value should be a File type."); } /** @var $value File */ return parent::convertToDatabaseValue($value->getPathname(), $platform); }
protected function getDropboxName(File $file, $hash) { return sprintf('/%s/%s.%s', basename(dirname($file->getPathname())), $hash, $file->getExtension()); }
/** * @param \Diamante\DeskBundle\Model\Attachment\File $file * @param $hash * @param $fileNamePrefix * @return \Imagine\Image\ManipulatorInterface */ public function createThumbnail(File $file, $hash, $fileNamePrefix) { $image = $this->loader->getImagine()->open($file->getPathname()); $thumbnail = $image->thumbnail(new Box(100, 100)); $destinationFolder = sprintf('%s/thumbnails', $this->getDestination($fileNamePrefix)); try { if (!file_exists($destinationFolder)) { mkdir($destinationFolder); chmod($destinationFolder, 0777); } $destination = sprintf("%s/%s.%s", $destinationFolder, $hash, self::DEFAULT_THUMB_EXT); $thumbnail->save($destination); } catch (\Exception $e) { $this->logger->error(sprintf('Attachment directory is not accessible! Reason: %s', $e->getMessage())); throw new \RuntimeException('Thumbnail could not be created. ' . $e->getMessage()); } }