@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | public function testListMedias() |
33 | 33 | { |
34 | 34 | $crawler = $this->client->request('GET', '/admin/medias/Post/MvcBlogBundle/1'); |
35 | - $this->assertEquals(200,$this->client->getResponse()->getStatusCode()); |
|
36 | - $this->assertEquals(2,$crawler->filter('.count-tr')->count()); |
|
35 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
|
36 | + $this->assertEquals(2, $crawler->filter('.count-tr')->count()); |
|
37 | 37 | |
38 | 38 | |
39 | 39 | $crawler = $this->client->request('GET', '/admin/medias/Post/MvcBlogBundle/2'); |
40 | - $this->assertEquals(200,$this->client->getResponse()->getStatusCode()); |
|
41 | - $this->assertEquals(1,$crawler->filter('.count-tr')->count()); |
|
40 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
|
41 | + $this->assertEquals(1, $crawler->filter('.count-tr')->count()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function testFindAllMediasForAModel() |
45 | 45 | { |
46 | - $medias = $this->manager->findMediasByModelAndId('Post',1); |
|
47 | - $this->assertGreaterThan(1,count($medias)); |
|
46 | + $medias = $this->manager->findMediasByModelAndId('Post', 1); |
|
47 | + $this->assertGreaterThan(1, count($medias)); |
|
48 | 48 | $this->assertEquals(2, count($medias)); |
49 | 49 | } |
50 | 50 | |
51 | 51 | public function testRemoveFile() |
52 | 52 | { |
53 | 53 | $this->client->request('GET', '/admin/medias/delete/Post/MvcBlogBundle/9'); |
54 | - $this->assertEquals(200,$this->client->getResponse()->getStatusCode()); |
|
54 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
|
55 | 55 | |
56 | - $medias = $this->manager->findMediasByModelAndId('Post',2); |
|
56 | + $medias = $this->manager->findMediasByModelAndId('Post', 2); |
|
57 | 57 | $this->assertEquals(0, count($medias)); |
58 | 58 | } |
59 | 59 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] |
76 | 76 | ); |
77 | 77 | |
78 | - $this->assertEquals(200,$this->client->getResponse()->getStatusCode()); |
|
79 | - $medias = $this->manager->findMediasByModelAndId('Post',13); |
|
78 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
|
79 | + $medias = $this->manager->findMediasByModelAndId('Post', 13); |
|
80 | 80 | |
81 | 81 | $this->assertEquals(1, count($medias)); |
82 | 82 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] |
100 | 100 | ); |
101 | 101 | |
102 | - $this->assertEquals(500,$this->client->getResponse()->getStatusCode()); |
|
102 | + $this->assertEquals(500, $this->client->getResponse()->getStatusCode()); |
|
103 | 103 | |
104 | 104 | $this->manager = $this->container->get('mk.media.manager'); |
105 | - $medias = $this->manager->findMediasByModelAndId('Post',17); |
|
105 | + $medias = $this->manager->findMediasByModelAndId('Post', 17); |
|
106 | 106 | $this->assertEquals(0, count($medias)); |
107 | 107 | } |
108 | 108 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafidion Michael |
|
5 | - * Date: 02/12/2014 |
|
6 | - * Time: 01:56 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafidion Michael |
|
5 | + * Date: 02/12/2014 |
|
6 | + * Time: 01:56 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\Interfaces; |
10 | 10 |
@@ -9,7 +9,7 @@ |
||
9 | 9 | namespace Mykees\MediaBundle\Interfaces; |
10 | 10 | |
11 | 11 | |
12 | -Interface Mediable{ |
|
12 | +Interface Mediable { |
|
13 | 13 | |
14 | 14 | public function getId(); |
15 | 15 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafidion Michael |
|
5 | - * Date: 30/11/2014 |
|
6 | - * Time: 18:22 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafidion Michael |
|
5 | + * Date: 30/11/2014 |
|
6 | + * Time: 18:22 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\EventListener; |
10 | 10 |
@@ -36,57 +36,57 @@ discard block |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | - public function uploadProcess( UploadEvent $event ) |
|
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); |
47 | 47 | $DS = DIRECTORY_SEPARATOR; |
48 | 48 | |
49 | 49 | |
50 | - if( $this->isValidExtension($extension,$event) ) |
|
50 | + if ($this->isValidExtension($extension, $event)) |
|
51 | 51 | { |
52 | 52 | //create dir |
53 | 53 | $webroot = $event->getRootDir().'/../web'; |
54 | 54 | $dir = $webroot.'/img'; |
55 | 55 | |
56 | - if(!file_exists($dir)){mkdir($dir,0777);} |
|
56 | + if (!file_exists($dir)) {mkdir($dir, 0777); } |
|
57 | 57 | |
58 | 58 | $dir .= $DS.date('Y'); |
59 | - if(!file_exists($dir)){mkdir($dir,0777);} |
|
59 | + if (!file_exists($dir)) {mkdir($dir, 0777); } |
|
60 | 60 | |
61 | 61 | $dir .= $DS.date('m'); |
62 | - if(!file_exists($dir)){mkdir($dir,0777);} |
|
62 | + if (!file_exists($dir)) {mkdir($dir, 0777); } |
|
63 | 63 | |
64 | 64 | //clean and define path filename |
65 | - $filename = $this->cleanFilename( $fileUploaded->getClientOriginalName(), $extension ); |
|
65 | + $filename = $this->cleanFilename($fileUploaded->getClientOriginalName(), $extension); |
|
66 | 66 | //test duplicate |
67 | - $name = $this->mediaExist( $filename,$webroot ); |
|
67 | + $name = $this->mediaExist($filename, $webroot); |
|
68 | 68 | |
69 | 69 | $filePath = date('Y').'/'.date('m').'/'.$name; |
70 | 70 | $save_media = $this->saveMedia($filePath, $name, $model, $model_id); |
71 | 71 | |
72 | - if($save_media) |
|
72 | + if ($save_media) |
|
73 | 73 | { |
74 | 74 | //upload |
75 | - $fileUploaded->move($dir,$name); |
|
75 | + $fileUploaded->move($dir, $name); |
|
76 | 76 | $event->setMedia($save_media); |
77 | 77 | |
78 | - if(!empty($resize_option[$model])) |
|
78 | + if (!empty($resize_option[$model])) |
|
79 | 79 | { |
80 | 80 | $resize = new ResizeHelper($resize_option[$model], $webroot); |
81 | 81 | $resize->resize($save_media->getFile()); |
82 | 82 | } |
83 | 83 | |
84 | 84 | return true; |
85 | - }else{ |
|
85 | + }else { |
|
86 | 86 | |
87 | 87 | return new Response(); |
88 | 88 | } |
89 | - }else{ |
|
89 | + }else { |
|
90 | 90 | |
91 | 91 | return new Response(); |
92 | 92 | } |
@@ -98,12 +98,12 @@ discard block |
||
98 | 98 | * @param $event |
99 | 99 | * @return bool |
100 | 100 | */ |
101 | - private function isValidExtension($extension,$event) |
|
101 | + private function isValidExtension($extension, $event) |
|
102 | 102 | { |
103 | 103 | $extensions = $event->getContainer()->getParameter('mykees.media.extension'); |
104 | - $valid_extensions = !empty($extensions) ? $extensions : ['jpg','jpeg','JPG','JPEG']; |
|
104 | + $valid_extensions = !empty($extensions) ? $extensions : ['jpg', 'jpeg', 'JPG', 'JPEG']; |
|
105 | 105 | |
106 | - return in_array($extension,$valid_extensions); |
|
106 | + return in_array($extension, $valid_extensions); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | * @param $extension |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - private function cleanFilename( $filename, $extension ) |
|
115 | + private function cleanFilename($filename, $extension) |
|
116 | 116 | { |
117 | - $f = explode('.',$filename); |
|
118 | - $cleanFilename = Urlizer::urlize(implode('.',array_slice($f,0,-1))); |
|
117 | + $f = explode('.', $filename); |
|
118 | + $cleanFilename = Urlizer::urlize(implode('.', array_slice($f, 0, -1))); |
|
119 | 119 | |
120 | 120 | return $cleanFilename.'.'.$extension; |
121 | 121 | } |
@@ -127,23 +127,23 @@ discard block |
||
127 | 127 | * @param int $count |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - private function mediaExist( $filename, $webroot, $count=0 ) |
|
130 | + private function mediaExist($filename, $webroot, $count = 0) |
|
131 | 131 | { |
132 | 132 | $file = $filename; |
133 | 133 | $filePath = false; |
134 | - if($count > 0){ |
|
135 | - $f = explode('.',$filename); |
|
134 | + if ($count > 0) { |
|
135 | + $f = explode('.', $filename); |
|
136 | 136 | $file = $f[0].'_'.$count.'.'.end($f); |
137 | 137 | $filePath = $webroot.'/img/'.date('Y').'/'.date('m').'/'.$file; |
138 | 138 | } |
139 | 139 | $filePath = !$filePath ? $webroot.'/img/'.date('Y').'/'.date('m').'/'.$file : $filePath; |
140 | - if(file_exists($filePath)) |
|
140 | + if (file_exists($filePath)) |
|
141 | 141 | { |
142 | 142 | $count++; |
143 | 143 | |
144 | - return $this->mediaExist( $filename, $webroot, $count ); |
|
145 | - }else{ |
|
146 | - $filename = $file; |
|
144 | + return $this->mediaExist($filename, $webroot, $count); |
|
145 | + }else { |
|
146 | + $filename = $file; |
|
147 | 147 | |
148 | 148 | return $filename; |
149 | 149 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | private function saveMedia($filePath, $filename, $model, $model_id) |
161 | 161 | { |
162 | 162 | $media = new Media(); |
163 | - $fn = explode('.',$filename); |
|
163 | + $fn = explode('.', $filename); |
|
164 | 164 | $media->setName($fn[0]); |
165 | 165 | $media->setMediableModel($model); |
166 | 166 | $media->setMediableId($model_id); |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | return true; |
85 | - }else{ |
|
85 | + } else{ |
|
86 | 86 | |
87 | 87 | return new Response(); |
88 | 88 | } |
89 | - }else{ |
|
89 | + } else{ |
|
90 | 90 | |
91 | 91 | return new Response(); |
92 | 92 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $count++; |
143 | 143 | |
144 | 144 | return $this->mediaExist( $filename, $webroot, $count ); |
145 | - }else{ |
|
145 | + } else{ |
|
146 | 146 | $filename = $file; |
147 | 147 | |
148 | 148 | return $filename; |
@@ -31,9 +31,9 @@ |
||
31 | 31 | { |
32 | 32 | $model = $args->getEntity(); |
33 | 33 | |
34 | - if($model instanceof Mediable) |
|
34 | + if ($model instanceof Mediable) |
|
35 | 35 | { |
36 | - $manager = new MediaManager($this->managerRegistry,$this->rootDir,$this->resize_parameters); |
|
36 | + $manager = new MediaManager($this->managerRegistry, $this->rootDir, $this->resize_parameters); |
|
37 | 37 | $manager->removeAllMediasForModel($model); |
38 | 38 | } |
39 | 39 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafidion Michael |
|
5 | - * Date: 12/12/2014 |
|
6 | - * Time: 12:21 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafidion Michael |
|
5 | + * Date: 12/12/2014 |
|
6 | + * Time: 12:21 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\EventListener; |
10 | 10 |
@@ -14,16 +14,16 @@ |
||
14 | 14 | |
15 | 15 | protected $medias; |
16 | 16 | |
17 | - public function getMediableModel(){ |
|
17 | + public function getMediableModel() { |
|
18 | 18 | return Reflection::getClassShortName($this); |
19 | 19 | } |
20 | 20 | |
21 | - public function getMediableId(){ |
|
21 | + public function getMediableId() { |
|
22 | 22 | return $this->getId(); |
23 | 23 | } |
24 | 24 | |
25 | - public function getMedias(){ |
|
26 | - $this->medias = $this->medias ? : new ArrayCollection(); |
|
25 | + public function getMedias() { |
|
26 | + $this->medias = $this->medias ?: new ArrayCollection(); |
|
27 | 27 | return $this->medias; |
28 | 28 | } |
29 | 29 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: tetsu0o |
|
5 | - * Date: 28/12/14 |
|
6 | - * Time: 12:45 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: tetsu0o |
|
5 | + * Date: 28/12/14 |
|
6 | + * Time: 12:45 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\Util; |
10 | 10 |
@@ -19,25 +19,25 @@ |
||
19 | 19 | } |
20 | 20 | |
21 | 21 | |
22 | - public static function getClassShortName ( $model ) { |
|
23 | - $reflection = new \ReflectionClass( $model ); |
|
22 | + public static function getClassShortName($model) { |
|
23 | + $reflection = new \ReflectionClass($model); |
|
24 | 24 | return $reflection->getShortName(); |
25 | 25 | } |
26 | 26 | |
27 | 27 | |
28 | - public static function getBundlePath ( $model ){ |
|
29 | - $explode = explode('\\', self::getClassName($model )); |
|
28 | + public static function getBundlePath($model) { |
|
29 | + $explode = explode('\\', self::getClassName($model)); |
|
30 | 30 | return $explode[0].'\\'.$explode[1].'\\'.$explode[2].'\\'.$explode[3]; |
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | - public static function getBundleRepository ( $model ){ |
|
35 | - $explode = explode('\\', self::getClassName($model )); |
|
34 | + public static function getBundleRepository($model) { |
|
35 | + $explode = explode('\\', self::getClassName($model)); |
|
36 | 36 | return $explode[0].$explode[1].':'.$explode[3]; |
37 | 37 | } |
38 | 38 | |
39 | - public static function getShortBundleRepository ( $model ){ |
|
40 | - $explode = explode('\\', self::getClassName($model )); |
|
39 | + public static function getShortBundleRepository($model) { |
|
40 | + $explode = explode('\\', self::getClassName($model)); |
|
41 | 41 | return $explode[0].$explode[1]; |
42 | 42 | } |
43 | 43 |
@@ -16,35 +16,35 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: tetsu0o |
|
5 | - * Date: 28/12/14 |
|
6 | - * Time: 15:02 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: tetsu0o |
|
5 | + * Date: 28/12/14 |
|
6 | + * Time: 15:02 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\Manager; |
10 | 10 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafidion Michael |
|
5 | - * Date: 28/11/2014 |
|
6 | - * Time: 17:38 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafidion Michael |
|
5 | + * Date: 28/11/2014 |
|
6 | + * Time: 17:38 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\DataFixtures\ORM; |
10 | 10 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Rafidion Michael |
|
5 | - * Date: 30/11/2014 |
|
6 | - * Time: 18:21 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Rafidion Michael |
|
5 | + * Date: 30/11/2014 |
|
6 | + * Time: 18:21 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Mykees\MediaBundle\Event; |
10 | 10 |