Пример #1
0
 /**
  * @return NotBlank
  */
 public function validate()
 {
     if (!in_array($this->attachment->getMimeType(), $this->allowdMimeTypes)) {
         return new TranslatorObject('bigfish.media.error.mimetype', array('%extensions%' => implode(', ', $this->allowedExtensions)));
     }
     return true;
 }
Пример #2
0
 public function execute()
 {
     /** @var $dimensionSettings ImageDimension **/
     $dimensionSettings = $this->cropping->getDimension();
     // first delete old file
     $oldFile = sprintf('%s/%s.%s', $this->uploadPath, $this->oldFile->getFileName(), $this->attachment->getExtension());
     if (file_exists($oldFile)) {
         @unlink($oldFile);
     }
     /* @var Box */
     $size = $this->setBox($dimensionSettings);
     $originalFile = sprintf('%s/%s.%s', $this->uploadPath, $this->attachment->getName(), $this->attachment->getExtension());
     $checkFilename = sprintf('%s/%s.%s', $this->uploadPath, $this->cropping->getFileName(), $this->attachment->getExtension());
     if ($this->oldFile->getName() == $this->cropping->getName() && file_exists($checkFilename)) {
         $cropName = $this->cropping->getFileName();
     } else {
         $fileDuplicateChecker = $this->checkDuplicateFile($this->cropping->getName(), $this->attachment->getExtension());
         $cropName = $fileDuplicateChecker['name'];
         $counter = $fileDuplicateChecker['counter'];
         $this->cropping->setCounter($counter);
     }
     $cropFile = sprintf('%s/%s.%s', $this->uploadPath, $cropName, $this->attachment->getExtension());
     $this->imagine->open($originalFile)->crop(new Point($this->x, $this->y), new Box($this->width, $this->height))->save($cropFile);
     $this->imagine->open($cropFile)->thumbnail($size, ImageInterface::THUMBNAIL_INSET)->save($cropFile);
     $this->cropping->setFileName($cropName);
     $this->cropping->setChecksum(sha1_file($cropFile));
     $initSize = new MediaFile($cropFile);
     $this->cropping->setClientHeight($initSize->getHeight());
     $this->cropping->setClientWidth($initSize->getWidth());
     return $this->cropping;
 }
Пример #3
0
 /**
  * @param Request       $request
  * @param Attachment    $attachment
  * @param ImageInstance $imageInstance
  *
  * @return JsonResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function editAction(Request $request, Attachment $attachment, ImageInstance $imageInstance)
 {
     $em = $this->getDoctrine()->getManager();
     $findCurrentDimensions = $em->getRepository('BigfishMediaBundle:Attachment')->findDimensions($attachment->getId(), $imageInstance->getId());
     $form = $this->createForm(new ImageCollectionType($findCurrentDimensions));
     $form->handleRequest($request);
     if ($form->isValid()) {
         foreach ($findCurrentDimensions as $cropping) {
             $exists = $em->getRepository('BigfishMediaBundle:ImageCropping')->findOneBy(array('attachment' => $attachment, 'instance' => $imageInstance->getId(), 'id' => $cropping->getId()));
             $generatedCropping = $this->container->get('bigfish.media.cropping.handler')->initialize($attachment, $cropping, $exists)->execute();
             $em->persist($generatedCropping);
         }
         $em->flush();
         return new JsonResponse(array('success' => true, 'currentUrl' => $this->generateUrl('media_form', array('value' => $imageInstance->getId()))));
     }
     return $this->render('BigfishMediaBundle:Default:edit.html.twig', array('attachment' => $attachment, 'selected' => $request->get('selected'), 'form' => $form->createView(), 'dimensions' => $findCurrentDimensions, 'actionUrl' => $this->generateUrl('media_edit', array('attachment' => $attachment->getId(), 'imageInstance' => $imageInstance->getId()))));
 }
Пример #4
0
 /**
  * @return NotBlank
  */
 public function validate()
 {
     $height = array();
     $width = array();
     foreach ($this->dimensionContainer->getDimensions() as $dimension) {
         if ($dimension->getFixedHeight() > 0) {
             $height[] = $dimension->getFixedHeight();
         }
         if ($dimension->getMinHeight() > 0) {
             $height[] = $dimension->getMinHeight();
         }
         if ($dimension->getFixedWidth() > 0) {
             $width[] = $dimension->getFixedWidth();
         }
         if ($dimension->getMinWidth() > 0) {
             $width[] = $dimension->getMinWidth();
         }
     }
     if ($this->attachment->getWidth() > 0 && count($height) > 0) {
         if (max($height) > $this->attachment->getHeight() || max($width) > $this->attachment->getWidth()) {
             return new TranslatorObject('bigfish.media.error.minsize', array('%min_width%' => max($width), '%min_height%' => max($height), '%currentWidth%' => $this->attachment->getWidth(), '%currentHeight%' => $this->attachment->getHeight()));
         }
     }
     return true;
 }
Пример #5
0
 /**
  * @param File $file
  */
 public function upload(MediaFile $file)
 {
     if ($file->getHeight() && $file->getWidth()) {
         $category = MediaTypes::IMAGE;
     } else {
         $category = MediaTypes::DOCUMENT;
     }
     $oCategory = $this->objectManager->getRepository('BigfishMediaBundle:Category')->find($category);
     $fs = new Filesystem();
     $checksum = $file->getChecksum();
     $checkIfExists = $this->objectManager->getRepository('BigfishMediaBundle:Attachment')->findOneBy(array('checksum' => $checksum));
     if ($checkIfExists) {
         $fs->remove(array($file->getRealPath()));
         return $checkIfExists;
     }
     $baseName = str_replace('.' . $file->getExtension(), '', $file->getFilename());
     $entity = new Attachment();
     $entity->setChecksum($checksum);
     $entity->setName($baseName);
     $entity->setFile($file->getFilename());
     $entity->setExtension($file->getExtension());
     $entity->setSize($file->getSize());
     $entity->setMimeType($file->getMimeType());
     $entity->setWidth($file->getWidth());
     $entity->setHeight($file->getHeight());
     $entity->setCategory($oCategory);
     $this->objectManager->persist($entity);
     $this->objectManager->flush();
     $file->move($this->uploadPath, $file->getFilename());
     return $entity;
 }