@@ -5,15 +5,10 @@ |
||
| 5 | 5 | use Alpixel\Bundle\MediaBundle\Entity\Media; |
| 6 | 6 | use Doctrine\Common\Collections\Collection; |
| 7 | 7 | use Doctrine\ORM\EntityManager; |
| 8 | -use Doctrine\ORM\NoResultException; |
|
| 9 | 8 | use Doctrine\ORM\QueryBuilder; |
| 10 | 9 | use Symfony\Component\Form\DataTransformerInterface; |
| 11 | -use Symfony\Component\Form\Exception\FormException; |
|
| 12 | 10 | use Symfony\Component\Form\Exception\TransformationFailedException; |
| 13 | 11 | use Symfony\Component\Form\Exception\UnexpectedTypeException; |
| 14 | -use Symfony\Component\Form\FormError; |
|
| 15 | -use Symfony\Component\Form\FormInterface; |
|
| 16 | -use Symfony\Component\PropertyAccess\PropertyAccessor; |
|
| 17 | 12 | |
| 18 | 13 | /** |
| 19 | 14 | * Data transformation class |
@@ -79,10 +79,11 @@ |
||
| 79 | 79 | |
| 80 | 80 | protected function transformSingleEntity($data) |
| 81 | 81 | { |
| 82 | - if($data instanceof Media) |
|
| 83 | - return $data->getSecretKey(); |
|
| 84 | - else |
|
| 85 | - return $this->em->getRepository($this->class)->findOneBySecretKey($data); |
|
| 82 | + if($data instanceof Media) { |
|
| 83 | + return $data->getSecretKey(); |
|
| 84 | + } else { |
|
| 85 | + return $this->em->getRepository($this->class)->findOneBySecretKey($data); |
|
| 86 | + } |
|
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | public function reverseTransform($data) |
@@ -4,11 +4,7 @@ discard block |
||
| 4 | 4 | use Alpixel\Bundle\MediaBundle\DataTransformer\EntityToIdTransformer; |
| 5 | 5 | use Alpixel\Bundle\MediaBundle\Entity\Media; |
| 6 | 6 | use Alpixel\Bundle\MediaBundle\EventListener\MediaEvent; |
| 7 | -use Alpixel\Bundle\MediaBundle\EventListener\MediaListener; |
|
| 8 | 7 | use Symfony\Bridge\Doctrine\RegistryInterface; |
| 9 | -use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; |
|
| 10 | -use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; |
|
| 11 | -use Symfony\Component\EventDispatcher\EventDispatcher; |
|
| 12 | 8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 13 | 9 | use Symfony\Component\Form\AbstractType; |
| 14 | 10 | use Symfony\Component\Form\FormBuilderInterface; |
@@ -16,7 +12,6 @@ discard block |
||
| 16 | 12 | use Symfony\Component\Form\FormEvents; |
| 17 | 13 | use Symfony\Component\Form\FormInterface; |
| 18 | 14 | use Symfony\Component\Form\FormView; |
| 19 | -use Symfony\Component\HttpKernel\Kernel; |
|
| 20 | 15 | use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
| 21 | 16 | |
| 22 | 17 | class MediaType extends AbstractType |
@@ -48,11 +48,13 @@ |
||
| 48 | 48 | { |
| 49 | 49 | $results = $event->getForm()->getData(); |
| 50 | 50 | |
| 51 | - if($results === null) |
|
| 52 | - return; |
|
| 51 | + if($results === null) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | - if(!is_array($results)) |
|
| 55 | - $results = array($results); |
|
| 55 | + if(!is_array($results)) { |
|
| 56 | + $results = array($results); |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | foreach($results as $media) { |
| 58 | 60 | $mediaEvent = new MediaEvent($media); |
@@ -31,8 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function previewIconFilter(\Twig_Environment $twig, $secretKey = '') |
| 33 | 33 | { |
| 34 | - if($secretKey == '') |
|
| 35 | - return ''; |
|
| 34 | + if($secretKey == '') { |
|
| 35 | + return ''; |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | $mimeType = $this->getMimeType($secretKey); |
| 38 | 39 | $icon = ''; |
@@ -41,8 +42,7 @@ discard block |
||
| 41 | 42 | if(preg_match('/^image/', $mimeType) === 0) { |
| 42 | 43 | $icon = $this->getIcon($mimeType); |
| 43 | 44 | $link = $this->generatePath(true, $icon); |
| 44 | - } |
|
| 45 | - else { |
|
| 45 | + } else { |
|
| 46 | 46 | $link = $this->generatePath(false, $secretKey); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -71,8 +71,9 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function generatePathFromSecretKey($secretKey) |
| 73 | 73 | { |
| 74 | - if($secretKey == '') |
|
| 75 | - return ''; |
|
| 74 | + if($secretKey == '') { |
|
| 75 | + return ''; |
|
| 76 | + } |
|
| 76 | 77 | |
| 77 | 78 | $mimeType = $this->getMimeType($secretKey); |
| 78 | 79 | |
@@ -31,8 +31,9 @@ |
||
| 31 | 31 | |
| 32 | 32 | $mediaPreview = $this->container->get('twig.extension.media_preview_extension'); |
| 33 | 33 | foreach ($this->get('request')->files as $files) { |
| 34 | - if(!is_array($files)) |
|
| 35 | - $files = array($files); |
|
| 34 | + if(!is_array($files)) { |
|
| 35 | + $files = array($files); |
|
| 36 | + } |
|
| 36 | 37 | foreach($files as $file) { |
| 37 | 38 | $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
| 38 | 39 | $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |