Completed
Pull Request — master (#3)
by
unknown
20:32
created
Manager/MediaManager.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     public $rootDir;
21 21
     public $resize_parameters;
22 22
 
23
-    public function __construct( ManagerRegistry $managerRegistry, $rootDir,$resize_parameters )
23
+    public function __construct(ManagerRegistry $managerRegistry, $rootDir, $resize_parameters)
24 24
     {
25 25
         $this->em = $managerRegistry->getManager();
26 26
         $this->rootDir = $rootDir;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
     public function webroot()
32 32
     {
33
-        return $this->rootDir . '/../web/img/';
33
+        return $this->rootDir.'/../web/img/';
34 34
     }
35 35
 
36 36
     /**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
         $model_info = $this->getModelInfos($models);
53 53
         $queryResult = $this->em->getRepository("MykeesMediaBundle:Media")->findForArrayModels($model_info);
54 54
 
55
-        return $this->refreshMediasArray($queryResult,$models);
55
+        return $this->refreshMediasArray($queryResult, $models);
56 56
     }
57 57
 
58 58
     /**
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
         $model = Reflection::getClassShortName($obj);
74 74
         $model_id = $obj->getId();
75 75
 
76
-        $queryResult = $this->em->getRepository('MykeesMediaBundle:Media')->findForModelAndId($model,$model_id);
76
+        $queryResult = $this->em->getRepository('MykeesMediaBundle:Media')->findForModelAndId($model, $model_id);
77 77
 
78
-        return $this->refreshMedias($queryResult,$obj);
78
+        return $this->refreshMedias($queryResult, $obj);
79 79
     }
80 80
 
81 81
     /**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function getQueryByModelAndId($model_name, $model_id)
87 87
     {
88
-        return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model_name,$model_id);
88
+        return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model_name, $model_id);
89 89
     }
90 90
 
91 91
     /**
@@ -106,38 +106,38 @@  discard block
 block discarded – undo
106 106
         $model = Reflection::getClassShortName($obj);
107 107
         $model_id = $obj->getId();
108 108
 
109
-        return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model,$model_id);
109
+        return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model, $model_id);
110 110
     }
111 111
 
112 112
     public function unlink($model, Media $media)
113 113
     {
114
-        $info  = pathinfo($media->getFile());
114
+        $info = pathinfo($media->getFile());
115 115
 
116
-        $this->removeSizes($model,$info);
116
+        $this->removeSizes($model, $info);
117 117
 
118
-        if(file_exists($this->webroot() . $media->getFile()))
118
+        if (file_exists($this->webroot().$media->getFile()))
119 119
         {
120
-            return unlink($this->webroot() . $media->getFile());
120
+            return unlink($this->webroot().$media->getFile());
121 121
         }
122 122
 
123 123
         return false;
124 124
     }
125 125
 
126
-    public function removeSizes($model,$info)
126
+    public function removeSizes($model, $info)
127 127
     {
128
-        if(!empty($this->resize_parameters[$model]))
128
+        if (!empty($this->resize_parameters[$model]))
129 129
         {
130
-            if(!empty($this->resize_parameters[$model]['size']))
130
+            if (!empty($this->resize_parameters[$model]['size']))
131 131
             {
132 132
                 $sizes = $this->resize_parameters[$model]['size'];
133 133
 
134
-                foreach($sizes as $k=>$size)
134
+                foreach ($sizes as $k=>$size)
135 135
                 {
136 136
                     $w = $size['width'];
137 137
                     $h = $size['height'];
138
-                    $resizedFile = $this->webroot() . $info['dirname'] . '/' . $info['filename'] . "_$w" . "x$h" . '.jpg';
138
+                    $resizedFile = $this->webroot().$info['dirname'].'/'.$info['filename']."_$w"."x$h".'.jpg';
139 139
 
140
-                    if(file_exists($resizedFile))
140
+                    if (file_exists($resizedFile))
141 141
                     {
142 142
                         unlink($resizedFile);
143 143
                     }
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 	/**
161 161
 	 * @param Mediable $model
162 162
 	 */
163
-    public function removeAllMediasForModel( Mediable $model )
163
+    public function removeAllMediasForModel(Mediable $model)
164 164
     {
165 165
         $model_name = Reflection::getClassShortName($model);
166 166
         $model_id = $model->getId();
167 167
 
168
-        if(method_exists($model,'getThumb') && $model->getThumb() !== null)
168
+        if (method_exists($model, 'getThumb') && $model->getThumb() !== null)
169 169
         {
170 170
             $model->setThumb(null);
171 171
         }
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             'model'=>$model_name,
174 174
             'modelId'=>$model_id
175 175
         ]);
176
-        foreach($medias as $k=>$media)
176
+        foreach ($medias as $k=>$media)
177 177
         {
178 178
             $this->unlink($model_name, $media);
179 179
             $this->remove($media);
@@ -183,6 +183,6 @@  discard block
 block discarded – undo
183 183
     /**
184 184
      * Remodel ALL Medias
185 185
      */
186
-    public function removeAll(){}
186
+    public function removeAll() {}
187 187
 
188 188
 }
Please login to merge, or discard this patch.
Manager/AbstractManager.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,35 +16,35 @@  discard block
 block discarded – undo
16 16
 
17 17
     public function getModelInfos(array $datas)
18 18
     {
19
-        $ids= [];
19
+        $ids = [];
20 20
         $models = [];
21 21
         $model_exist = false;
22 22
 
23
-        foreach( $datas as $k=>$data )
23
+        foreach ($datas as $k=>$data)
24 24
         {
25
-            if($data instanceof Mediable)
25
+            if ($data instanceof Mediable)
26 26
             {
27
-                array_push($ids,$data->getMediableId());
28
-                if( $model_exist != $data->getMediableModel() )
27
+                array_push($ids, $data->getMediableId());
28
+                if ($model_exist != $data->getMediableModel())
29 29
                 {
30
-                    array_push($models,$data->getMediableModel());
30
+                    array_push($models, $data->getMediableModel());
31 31
                     $model_exist = $data->getMediableModel();
32 32
                 }
33 33
             }
34 34
         }
35 35
 
36
-        return [ 'ids'=>$ids, 'models'=>$models ];
36
+        return ['ids'=>$ids, 'models'=>$models];
37 37
     }
38 38
 
39 39
     public function refreshMediasArray(array $medias, array $models)
40 40
     {
41 41
         $this->clean($models);
42
-        foreach($models as $model)
42
+        foreach ($models as $model)
43 43
         {
44
-            foreach($medias as $media){
45
-                if($model instanceof Mediable)
44
+            foreach ($medias as $media) {
45
+                if ($model instanceof Mediable)
46 46
                 {
47
-                    if($model->getId() == $media->getMediableId() && $model->getMediableModel() == $media->getMediableModel())
47
+                    if ($model->getId() == $media->getMediableId() && $model->getMediableModel() == $media->getMediableModel())
48 48
                     {
49 49
                         $model->getMedias()->add($media);
50 50
                     }
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 
61 61
     public function addMedias(array $medias, Mediable $model)
62 62
     {
63
-        foreach($medias as $media){
64
-            if(!empty($media) && Reflection::getClassShortName($media) == 'Media'){
65
-                $this->addMedia($media,$model);
63
+        foreach ($medias as $media) {
64
+            if (!empty($media) && Reflection::getClassShortName($media) == 'Media') {
65
+                $this->addMedia($media, $model);
66 66
             }
67 67
         }
68 68
     }
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
     public function refreshMedias(array $medias, Mediable $model)
71 71
     {
72 72
         $model->getMedias()->clear();
73
-        $this->addMedias($medias,$model);
73
+        $this->addMedias($medias, $model);
74 74
     }
75 75
 
76 76
     public function clean(array $models)
77 77
     {
78
-        foreach($models as $model)
78
+        foreach ($models as $model)
79 79
         {
80 80
             $model->getMedias()->clear();
81 81
         }
Please login to merge, or discard this patch.
Controller/MediasController.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
      * @param $editor
28 28
      * @return \Symfony\Component\HttpFoundation\Response
29 29
      */
30
-    public function indexAction( $model, $bundle, $model_id, $editor )
30
+    public function indexAction($model, $bundle, $model_id, $editor)
31 31
     {
32 32
         $params = [
33 33
             'medias'=>$this->get('mk.media.manager')->findMediasByModelAndId($model, $model_id),
34 34
             'entity'=>$this->getManage()->getRepository("$bundle:$model")->find($model_id),
35
-            'mode'=>$editor=='true' ? $editor : null,
36
-            'url'=>$editor == "true" ? ['model'=>$model,'bundle'=>$bundle,'model_id'=>$model_id,'mode'=>'true'] : ['model'=>$model,'bundle'=>$bundle,'model_id'=>$model_id]
35
+            'mode'=>$editor == 'true' ? $editor : null,
36
+            'url'=>$editor == "true" ? ['model'=>$model, 'bundle'=>$bundle, 'model_id'=>$model_id, 'mode'=>'true'] : ['model'=>$model, 'bundle'=>$bundle, 'model_id'=>$model_id]
37 37
         ];
38 38
         $form = $this->createForm(
39 39
             new MediaType(),
40 40
             new Media,
41 41
             [
42
-                'action' => $this->generateUrl('mykees_media_add',$params['url']),
42
+                'action' => $this->generateUrl('mykees_media_add', $params['url']),
43 43
                 'method' => 'POST',
44 44
             ]
45 45
         );
46 46
 
47
-        return $this->render('MykeesMediaBundle:Media:index.html.twig',[
47
+        return $this->render('MykeesMediaBundle:Media:index.html.twig', [
48 48
             'form'=>$form->createView(),
49 49
             'model'=>$model,
50 50
             'bundle'=> $bundle,
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
             'mode'=>$request->get('mode')
67 67
         ];
68 68
 
69
-        if( $request->isXmlHttpRequest() && $requestArray['file'] )
69
+        if ($request->isXmlHttpRequest() && $requestArray['file'])
70 70
         {
71 71
             // Init Event
72 72
             $event = $this->initEvent($requestArray['file'], $model);
73 73
 
74
-            if($event->getMedia())
74
+            if ($event->getMedia())
75 75
             {
76
-                return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig',[
76
+                return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig', [
77 77
                     'params'=>$requestArray,
78 78
                     'media'=>$event->getMedia(),
79 79
                     'model'=>$model,
80 80
                     'bundle'=>$bundle,
81 81
                 ]);
82 82
                 return JsonResponse($event->getMedia());
83
-            }else{
83
+            }else {
84 84
                 $response = new Response();
85 85
                 $response->setContent(json_encode(array(
86 86
                     'error'=>"Le format n'est pas valid"
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      * @throws \Exception
99 99
      * @return \Symfony\Component\HttpFoundation\Response
100 100
      */
101
-    public function addAction( Request $request )
101
+    public function addAction(Request $request)
102 102
     {
103 103
         $requestArray = [
104 104
             'file'=>$request->files,
@@ -108,24 +108,24 @@  discard block
 block discarded – undo
108 108
         $bundle = $request->get('bundle');
109 109
         $model_id = $request->get('model_id');
110 110
 
111
-        if( $request->isXmlHttpRequest() && $requestArray['file'] )
111
+        if ($request->isXmlHttpRequest() && $requestArray['file'])
112 112
         {
113 113
             //Init Event
114
-            $event = $this->initEvent($requestArray['file'],$model,$model_id);
114
+            $event = $this->initEvent($requestArray['file'], $model, $model_id);
115 115
 
116
-            if($event->getMedia())
116
+            if ($event->getMedia())
117 117
             {
118 118
                 $requestArray['entity'] = $this->getManage()->getRepository("$bundle:$model")->find($model_id);
119 119
 
120 120
 
121
-                return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig',[
121
+                return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig', [
122 122
                     'params'=>$requestArray,
123 123
                     'media'=>$event->getMedia(),
124 124
                     'model'=>$model,
125 125
                     'bundle'=>$bundle,
126 126
                     'model_id'=>$model_id
127 127
                 ]);
128
-            }else{
128
+            }else {
129 129
                 $response = new Response();
130 130
                 $response->setContent(json_encode(array(
131 131
                     'error'=>"Le format n'est pas valid"
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
      * @param Request $request
161 161
      * @return \Symfony\Component\HttpFoundation\RedirectResponse
162 162
      */
163
-    public function thumbAction( $model, $bundle, $model_id, $id, Request $request )
163
+    public function thumbAction($model, $bundle, $model_id, $id, Request $request)
164 164
     {
165
-        $media  = $this->getManage()->getRepository("MykeesMediaBundle:Media")->find($id);
166
-        $entity  = $this->getManage()->getRepository("$bundle:$model")->find($model_id);
165
+        $media = $this->getManage()->getRepository("MykeesMediaBundle:Media")->find($id);
166
+        $entity = $this->getManage()->getRepository("$bundle:$model")->find($model_id);
167 167
         $entity->setThumb($media);
168 168
         $this->getManage()->persist($entity);
169 169
         $this->getManage()->flush();
@@ -178,16 +178,16 @@  discard block
 block discarded – undo
178 178
      * @param Request $request
179 179
      * @return Response
180 180
      */
181
-    public function showAction( $model=null, $id = null, Request $request )
181
+    public function showAction($model = null, $id = null, Request $request)
182 182
     {
183
-        if( !$id )
183
+        if (!$id)
184 184
         {
185 185
             $params = [
186 186
                 'class'=>$request->get('class'),
187 187
                 'alt'=>$request->get('alt')
188 188
             ];
189
-            $params['media'] = $this->getManage()->getRepository('MykeesMediaBundle:Media')->findOneBy(['name'=>$params['alt'],'model'=>$model]);
190
-        }else{
189
+            $params['media'] = $this->getManage()->getRepository('MykeesMediaBundle:Media')->findOneBy(['name'=>$params['alt'], 'model'=>$model]);
190
+        }else {
191 191
             $params = [
192 192
                 'media'=>$this->getManage()->getRepository('MykeesMediaBundle:Media')->find($id),
193 193
                 'class'=>null
@@ -197,18 +197,18 @@  discard block
 block discarded – undo
197 197
             new MediaShowType(),
198 198
             $params['media'],
199 199
             [
200
-                'action' => $this->generateUrl('mykees_media_show',['model'=>$model,'id'=>$id]),
200
+                'action' => $this->generateUrl('mykees_media_show', ['model'=>$model, 'id'=>$id]),
201 201
                 'method' => 'POST',
202 202
             ]
203 203
         );
204
-        if($request->getMethod() == "POST")
204
+        if ($request->getMethod() == "POST")
205 205
         {
206 206
             $media = $request->request->all();
207
-            return $this->render('MykeesMediaBundle:Media:tinymce.html.twig',['media'=>$media]);
207
+            return $this->render('MykeesMediaBundle:Media:tinymce.html.twig', ['media'=>$media]);
208 208
         }
209 209
 
210
-        return $this->render('MykeesMediaBundle:Media:show/show.html.twig',[
211
-            'media'=>$params['media'],'form'=>$form->createView(),'class'=>$params['class'],"model"=>$model
210
+        return $this->render('MykeesMediaBundle:Media:show/show.html.twig', [
211
+            'media'=>$params['media'], 'form'=>$form->createView(), 'class'=>$params['class'], "model"=>$model
212 212
         ]);
213 213
     }
214 214
 
@@ -220,16 +220,16 @@  discard block
 block discarded – undo
220 220
      * @param $id
221 221
      * @return Response
222 222
      */
223
-    public function deleteAction( $model, $bundle, $id )
223
+    public function deleteAction($model, $bundle, $id)
224 224
     {
225
-        if( $id )
225
+        if ($id)
226 226
         {
227 227
             $media = $this->getManage()->getRepository('MykeesMediaBundle:Media')->find($id);
228 228
             $media_manager = $this->get('mk.media.manager');
229
-            $media_manager->unlink($model,$media);
229
+            $media_manager->unlink($model, $media);
230 230
 
231 231
             $model_referer = $this->getManage()->getRepository("$bundle:$model")->find($media->getMediableId());
232
-            if(method_exists($model_referer,'getThumb') && $model_referer->getThumb() !== null && $model_referer->getThumb()->getId() == $media->getId())
232
+            if (method_exists($model_referer, 'getThumb') && $model_referer->getThumb() !== null && $model_referer->getThumb()->getId() == $media->getId())
233 233
             {
234 234
                 $model_referer->setThumb(null);
235 235
             }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
     {
263 263
         $params = [
264 264
             'medias'=>$this->get('mk.media.manager')->findMediasByModel($model),
265
-            'url'=> ['model'=>$model,'bundle'=>$bundle]
265
+            'url'=> ['model'=>$model, 'bundle'=>$bundle]
266 266
         ];
267 267
         $form = $this->createForm(
268 268
             new MediaType(),
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
             ]
274 274
         );
275 275
 
276
-        return $this->render('MykeesMediaBundle:Media:basic-uploader.html.twig',[
276
+        return $this->render('MykeesMediaBundle:Media:basic-uploader.html.twig', [
277 277
             'form'=>$form->createView(),
278 278
             'model'=>$model,
279 279
             'bundle'=> $bundle,
Please login to merge, or discard this patch.
EventListener/UploadSubscriber.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function uploadProcess(UploadEvent $event)
40 40
     {
41
-        $file  = $event->getFile()->all();
41
+        $file = $event->getFile()->all();
42 42
         $fileUploaded = $file['file'];
43
-        $model   = $event->getMediableModel();
43
+        $model = $event->getMediableModel();
44 44
         $model_id = $event->getMediableId();
45 45
         $resize_option = $event->getContainer()->getParameter('mykees.media.resize');
46 46
         $extension = pathinfo($fileUploaded->getClientOriginalName(), PATHINFO_EXTENSION);
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
                 }
86 86
 
87 87
                 return true;
88
-            } else {
88
+            }else {
89 89
                 return new Response();
90 90
             }
91
-        } else {
91
+        }else {
92 92
             return new Response();
93 93
         }
94 94
     }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     private function isValidExtension($extension, $event)
103 103
     {
104 104
         $extensions = $event->getContainer()->getParameter('mykees.media.extension');
105
-        $valid_extensions = !empty($extensions) ? $extensions : ['jpg','jpeg','JPG','JPEG'];
105
+        $valid_extensions = !empty($extensions) ? $extensions : ['jpg', 'jpeg', 'JPG', 'JPEG'];
106 106
 
107 107
         return in_array($extension, $valid_extensions);
108 108
     }
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
             $count++;
143 143
 
144 144
             return $this->mediaExist($filename, $webroot, $count);
145
-        } else {
146
-            $filename =  $file;
145
+        }else {
146
+            $filename = $file;
147 147
 
148 148
             return $filename;
149 149
         }
Please login to merge, or discard this patch.
Form/DataTransformer/IdToMediaTransformer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
             return '';
22 22
         }
23 23
 
24
-        return (int)$val;
24
+        return (int) $val;
25 25
     }
26 26
 
27 27
     // transforms the Media id into an Media object
Please login to merge, or discard this patch.
Helper/ResizeHelper.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function resize($image)
28 28
     {
29
-        $absolute_path = $this->webroot . $image;
29
+        $absolute_path = $this->webroot.$image;
30 30
         $absolute_info = pathinfo($absolute_path);
31
-        $allowedExtension = ['jpg','JPG','jpeg',"JPEG",'png','PNG','gif','GIF'];
31
+        $allowedExtension = ['jpg', 'JPG', 'jpeg', "JPEG", 'png', 'PNG', 'gif', 'GIF'];
32 32
         $extension = pathinfo($image);
33 33
         $extension = $extension['extension'];
34 34
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
                     $imagine = new \Imagine\Gd\Imagine();
47 47
                     $mode = $this->options['mode'];
48 48
 
49
-                    $imagine->open($absolute_info['dirname'] . '/' . $absolute_info['filename'] . '.'.$extension)
49
+                    $imagine->open($absolute_info['dirname'].'/'.$absolute_info['filename'].'.'.$extension)
50 50
                         ->thumbnail(
51 51
                             new \Imagine\Image\Box($width, $height),
52 52
                             !empty($mode) &&
Please login to merge, or discard this patch.
Twig/Extension/UploaderExtension.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
 
59 59
             return '<iframe src="'.$url.'" style="width:100%;border: none;min-height:100%;" class="iframe-uploader">
60 60
                 </iframe>';
61
-        } else {
61
+        }else {
62 62
             return '<h3 style="font-weight: bold;text-align: center;color:#777">
63 63
                 The <span style="color:#DD6F6F;border-bottom:2px dashed #777;">ID</span> 
64 64
                 from your entity <span style="color:#DD6F6F;border-bottom:2px dashed #777;">'.$model.
Please login to merge, or discard this patch.