Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: implements WellCommerce\Bundle\MediaBundle\Entity\MediaInterface, use trait Knp\DoctrineBehaviors\Model\Timestampable\Timestampable, use trait Knp\DoctrineBehaviors\Model\Blameable\Blameable
 public function create() : MediaInterface
 {
     $media = new Media();
     $media->setSize(0);
     $media->setName('');
     $media->setMime('');
     $media->setExtension('');
     $media->setPath('');
     return $media;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function save(UploadedFile $file, $dir)
 {
     $media = new Media();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     $this->_em->persist($media);
     $this->_em->flush();
     return $media;
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $rootPath = $this->container->get('kernel')->getRootDir() . '/../web/themes/wellcommerce/assets/prod/';
     $uploader = $this->container->get('media.uploader');
     $uploadPath = $uploader->getUploadRootDir('images');
     $filesystem = $this->container->get('filesystem');
     foreach (self::$samples as $photo) {
         $image = new UploadedFile($rootPath . $photo, $photo, 'image/jpeg', filesize($rootPath . $photo));
         $media = new Media();
         $media->setName($image->getClientOriginalName());
         $media->setExtension($image->guessClientExtension());
         $media->setMime($image->getClientMimeType());
         $media->setSize($image->getClientSize());
         $manager->persist($media);
         $filesystem->copy($rootPath . $photo, $uploadPath . '/' . $media->getPath());
         $this->setReference('photo_' . $photo, $media);
     }
     $manager->flush();
 }
Example #4
0
 /**
  * Returns relative path to file
  *
  * @param Media $media
  *
  * @return string
  */
 public function getRelativePath(Media $media)
 {
     return sprintf('%s/%s.%s', $media->getPath(), $media->getId(), $media->getExtension());
 }
 /**
  * Checks whether photo was chosen as main product photo
  *
  * @param Media $photo
  * @param int   $mainId
  *
  * @return bool
  */
 private function isMainPhoto(Media $photo, $mainId)
 {
     return $photo->getId() === (int) $mainId;
 }
Example #6
0
 /**
  * @return \WellCommerce\Bundle\MediaBundle\Entity\MediaInterface
  */
 public function create()
 {
     $media = new Media();
     $media->setProductPhotos(new ArrayCollection());
     return $media;
 }