Ejemplo n.º 1
0
 public function testPrepareDir()
 {
     $videoPath = $this->videoService->videoPath($this->videoId, $this->videoEntityData['extension']);
     $this->assertTrue($this->videoService->prepareDir($videoPath));
 }
Ejemplo n.º 2
0
Archivo: File.php Proyecto: zfury/cmf
 /**
  * @param int $thumbSize
  * @return null|string
  * @throws \Exception
  */
 public function getThumb($thumbSize = Image::SMALL_THUMB)
 {
     switch ($this->type) {
         case self::IMAGE_FILETYPE:
             $ext = $this->getExtension();
             $imageId = $this->getId();
             $urlPart = Image::imgPath($thumbSize, $imageId, $ext, FileService::FROM_PUBLIC);
             if (!file_exists($urlPart)) {
                 $originalLocation = $this->getLocation();
                 $image = new \Imagick($originalLocation);
                 $size = Image::sizeByType($thumbSize);
                 $image->cropThumbnailImage($size['width'], $size['height']);
                 FileService::prepareDir(FileService::PUBLIC_PATH . $urlPart);
                 $image->writeimage(FileService::PUBLIC_PATH . $urlPart);
             }
             return $urlPart;
         case self::AUDIO_FILETYPE:
             return Audio::audioPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC);
         case self::VIDEO_FILETYPE:
             return Video::videoPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC);
         default:
     }
     return null;
 }
Ejemplo n.º 3
0
Archivo: File.php Proyecto: zfury/cmf
 /**
  * Writes file to a DB and moves it to an appropriate path
  *
  * @param FileUpload $form
  * @return FileEntity
  * @throws \Exception
  */
 public function writeFile(FileUpload $form)
 {
     $ext = $this->getExt($form->getData()[$form->getFileType()]['name']);
     $type = $form->getFileType();
     //Creating new image to get ID for building its path
     $file = new FileEntity();
     $file->setExtension($ext);
     $file->setType($type);
     $this->sm->get('doctrine.entitymanager.orm_default')->persist($file);
     $this->sm->get('doctrine.entitymanager.orm_default')->flush();
     //Building path and creating directory. Then - moving
     $destination = null;
     switch ($type) {
         case FileEntity::AUDIO_FILETYPE:
             $destination = Audio::audioPath($file->getId(), $ext);
             break;
         case FileEntity::VIDEO_FILETYPE:
             $destination = Video::videoPath($file->getId(), $ext);
             break;
         case FileEntity::IMAGE_FILETYPE:
             $destination = Image::imgPath(Image::ORIGINAL, $file->getId(), $ext);
             break;
         default:
     }
     $this->prepareDir($destination);
     $this->moveFile($destination, $form->getData()[$type]);
     return $file;
 }