/** * @param integer $x * @param integer $y * @param integer $width * @param integer $height * * @return boolean */ public function crop($x, $y, $width, $height) { try { $this->imagick->cropimage($width, $height, $x, $y); $this->imagick->writeimage($this->pathToUploadDir . $this->file->getPath()); $this->file->getParams()->setWidth($width); $this->file->getParams()->setHeight($height); $this->entityManager->flush(); return true; } catch (\Exception $exception) { return false; } }
/** * Convert file entity to array format * * @param File $file * * @return array */ public function convertFileEntityToArray(File $file) { $params = $file->getParams(); $directory = $file->getDirectory(); $fileData = array('id' => $file->getId(), 'dirId' => $directory ? $directory->getId() : 0, 'name' => $file->getName(), 'src' => $file->getPath(), 'mime' => $params->getMime(), 'width' => $params->getWidth(), 'height' => $params->getHeight()); return $fileData; }
public function load(ObjectManager $manager) { foreach ($this->data as $fileData) { $file = new File(); $file->setDirectory($this->getReference($fileData['directory_reference'])); $file->setName($fileData['name']); $file->setParams(new UploadedFileParametersModel()); $file->setPath($fileData['path']); $manager->persist($file); $this->addReference($fileData['file_reference'], $file); } $manager->flush(); }
/** * @param string $filename * @param UploadedFile $uploadedFile * @param Directory $directory * * @return File */ public function save($filename, UploadedFile $uploadedFile, Directory $directory = null) { if (!$this->isAllowMimeTypes($uploadedFile)) { throw new UploadException(sprintf('File type %s is not allowed to upload', $uploadedFile->getMimeType())); } $newFilePath = $this->uploadDirectoryManager->getNewPath($filename); $size = $uploadedFile->getSize(); $mimeType = $uploadedFile->getMimeType(); $uploadedFile->move($this->webDir . dirname($newFilePath), basename($newFilePath)); $path = $this->webDir . $newFilePath; if ($this->doResize) { $this->resizeImage($path); } $fileParams = $this->createFileParams($size, $mimeType, $path); $file = new File(); $file->setName($filename); $file->setDirectory($directory); $file->setPath($newFilePath); $file->setChecksum($this->getChecksum($newFilePath)); $file->setParams($fileParams); $this->entityManager->persist($file); $this->entityManager->flush(); return $file; }
/** * Set necessary mocks */ private function setMocks() { $directory1 = new Directory(); $directory1->setName('first'); $directory2 = new Directory(); $directory2->setName('second'); $directory3 = new Directory(); $directory3->setName('subfirst'); $this->directories = array(self::DIR_ID_1 => $directory1, self::DIR_ID_2 => $directory2, self::DIR_ID_1_1 => $directory3); $file1 = new File(); $file1->setDirectory($directory1); $file1->setPath('/../../web/abc.jpg'); $file2 = new File(); $file2->setDirectory($directory2); $file2->setPath('/../../web/xyz.jpg'); $this->files = array(); $this->files[self::FILE_ID_1] = $file1; $this->files[self::FILE_ID_2] = $file2; }
/** * @param Directory $directory * @param File $file * * @return File * @throws CopyMoveSelectionException */ private function copyFile(Directory $directory = null, File $file) { $newFile = clone $file; $newFile->setDirectory($directory); $newFile->setPath($this->copyFileOnDisk($file->getPath())); $this->entityManager->persist($newFile); return $newFile; }