@@ -30,6 +30,10 @@ |
||
| 30 | 30 | |
| 31 | 31 | private $unitOfWork; |
| 32 | 32 | |
| 33 | + /** |
|
| 34 | + * @param string $class |
|
| 35 | + * @param string $property |
|
| 36 | + */ |
|
| 33 | 37 | public function __construct(EntityManager $em, $class, $property, $queryBuilder, $multiple) |
| 34 | 38 | { |
| 35 | 39 | if (!(null === $queryBuilder || $queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) { |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * Sets the value of uri. |
| 128 | 128 | * |
| 129 | - * @param string $name $uri the uri |
|
| 130 | 129 | * |
| 130 | + * @param string $uri |
|
| 131 | 131 | * @return self |
| 132 | 132 | */ |
| 133 | 133 | public function setUri($uri) |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | /** |
| 151 | 151 | * Sets the value of secretKey. |
| 152 | 152 | * |
| 153 | - * @param string $name $secretKey the secret key |
|
| 154 | 153 | * |
| 154 | + * @param string $secretKey |
|
| 155 | 155 | * @return self |
| 156 | 156 | */ |
| 157 | 157 | public function setSecretKey($secretKey) |
@@ -174,8 +174,8 @@ discard block |
||
| 174 | 174 | /** |
| 175 | 175 | * Sets the value of mime. |
| 176 | 176 | * |
| 177 | - * @param string $name $mime the mime |
|
| 178 | 177 | * |
| 178 | + * @param string $mime |
|
| 179 | 179 | * @return self |
| 180 | 180 | */ |
| 181 | 181 | public function setMime($mime) |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | /** |
| 199 | 199 | * Sets the value of lifetime. |
| 200 | 200 | * |
| 201 | - * @param string $label $lifetime the lifetime |
|
| 202 | 201 | * |
| 202 | + * @param null|\DateTime $lifetime |
|
| 203 | 203 | * @return self |
| 204 | 204 | */ |
| 205 | 205 | public function setLifetime($lifetime) |
@@ -60,6 +60,9 @@ |
||
| 60 | 60 | return (array_key_exists($mime, $this->previewIcon)) ? $this->previewIcon[$mime] : $this->previewIcon['unknown']; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + /** |
|
| 64 | + * @param boolean $isIcon |
|
| 65 | + */ |
|
| 63 | 66 | protected function generatePath($isIcon, $str) |
| 64 | 67 | { |
| 65 | 68 | if($isIcon === true) { |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | |
| 72 | 72 | public function generatePathFromSecretKey($secretKey) |
| 73 | 73 | { |
| 74 | - if($secretKey == '') |
|
| 74 | + if($secretKey == '') |
|
| 75 | 75 | return ''; |
| 76 | 76 | |
| 77 | 77 | $mimeType = $this->getMimeType($secretKey); |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | $this->allowedMimetypes = $allowedMimetypes; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * $current_uri String actual uri of the file |
|
| 39 | - * $dest_folder String future uri of the file starting from web/upload folder |
|
| 40 | - * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
| 41 | - **/ |
|
| 42 | - public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
| 43 | - { |
|
| 37 | + /** |
|
| 38 | + * $current_uri String actual uri of the file |
|
| 39 | + * $dest_folder String future uri of the file starting from web/upload folder |
|
| 40 | + * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
| 41 | + **/ |
|
| 42 | + public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
| 43 | + { |
|
| 44 | 44 | |
| 45 | 45 | //Cleaning up old files before uploading this one |
| 46 | 46 | $this->cleanup(); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $fs = new Filesystem(); |
| 65 | 65 | if (!$fs->exists($this->uploadDir.$dest_folder)) { |
| 66 | - $fs->mkdir($this->uploadDir.$dest_folder); |
|
| 66 | + $fs->mkdir($this->uploadDir.$dest_folder); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $em = $this->doctrine->getManager(); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $em->flush(); |
| 118 | 118 | |
| 119 | 119 | return $media; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | public function cleanup() |
| 123 | 123 | { |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | $mediaPreview = $this->container->get('twig.extension.media_preview_extension'); |
| 33 | 33 | foreach ($this->get('request')->files as $files) { |
| 34 | 34 | if(!is_array($files)) |
| 35 | - $files = array($files); |
|
| 35 | + $files = array($files); |
|
| 36 | 36 | foreach($files as $file) { |
| 37 | - $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
| 38 | - $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
| 39 | - $returnData[] = array( |
|
| 40 | - 'id' => $media->getSecretKey(), |
|
| 41 | - 'path' => $path, |
|
| 42 | - 'name' => $media->getName(), |
|
| 43 | - ); |
|
| 37 | + $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
| 38 | + $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
| 39 | + $returnData[] = array( |
|
| 40 | + 'id' => $media->getSecretKey(), |
|
| 41 | + 'path' => $path, |
|
| 42 | + 'name' => $media->getName(), |
|
| 43 | + ); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
@@ -81,29 +81,29 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function showMediaAction(Media $media, $filter = null) |
| 83 | 83 | { |
| 84 | - $response = new Response(); |
|
| 84 | + $response = new Response(); |
|
| 85 | 85 | |
| 86 | - $lastModified = new \DateTime('now'); |
|
| 86 | + $lastModified = new \DateTime('now'); |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - //Checking if it is an image or not |
|
| 90 | - $src = $this->get('media')->getAbsolutePath($media); |
|
| 91 | - $isImage = @getimagesize($src); |
|
| 89 | + //Checking if it is an image or not |
|
| 90 | + $src = $this->get('media')->getAbsolutePath($media); |
|
| 91 | + $isImage = @getimagesize($src); |
|
| 92 | 92 | |
| 93 | - if($isImage) { |
|
| 93 | + if($isImage) { |
|
| 94 | 94 | $response->headers->set('Content-disposition', 'inline;filename='.$media->getName()); |
| 95 | 95 | if (!empty($filter) && $isImage) { |
| 96 | 96 | |
| 97 | - $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
| 98 | - $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | - $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
| 97 | + $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
| 98 | + $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | + $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
| 100 | 100 | |
| 101 | - $uploadDir = $this->get('media')->getUploadDir($filter); |
|
| 101 | + $uploadDir = $this->get('media')->getUploadDir($filter); |
|
| 102 | 102 | |
| 103 | - if (!is_file($src)) { |
|
| 103 | + if (!is_file($src)) { |
|
| 104 | 104 | $fs = new Filesystem(); |
| 105 | 105 | if (!$fs->exists($uploadDir.$media->getFolder())) { |
| 106 | - $fs->mkdir($uploadDir.$media->getFolder()); |
|
| 106 | + $fs->mkdir($uploadDir.$media->getFolder()); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $path = 'upload/'.$media->getUri(); |
@@ -111,33 +111,33 @@ discard block |
||
| 111 | 111 | $responseData = $filterManager->applyFilter($image, $filter); // run the filter |
| 112 | 112 | $data = $responseData->getContent(); // get the image from the response |
| 113 | 113 | file_put_contents($uploadDir.$media->getUri(), $data); |
| 114 | - } else { |
|
| 114 | + } else { |
|
| 115 | 115 | $data = file_get_contents($src); |
| 116 | 116 | $lastModified->setTimestamp(filemtime($src)); |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } else { |
| 120 | - $src = $this->get('media')->getAbsolutePath($media); |
|
| 121 | - $lastModified->setTimestamp(filemtime($src)); |
|
| 122 | - $data = file_get_contents($src); |
|
| 120 | + $src = $this->get('media')->getAbsolutePath($media); |
|
| 121 | + $lastModified->setTimestamp(filemtime($src)); |
|
| 122 | + $data = file_get_contents($src); |
|
| 123 | 123 | } |
| 124 | - } else { |
|
| 124 | + } else { |
|
| 125 | 125 | $lastModified->setTimestamp(filemtime($src)); |
| 126 | 126 | $data = file_get_contents($src); |
| 127 | 127 | $response->headers->set('Content-disposition', 'attachment;filename='.basename($media->getUri())); |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $response->setLastModified($lastModified); |
|
| 131 | - $response->setPublic(); |
|
| 132 | - $response->headers->set('Content-Type', $media->getMime()); |
|
| 130 | + $response->setLastModified($lastModified); |
|
| 131 | + $response->setPublic(); |
|
| 132 | + $response->headers->set('Content-Type', $media->getMime()); |
|
| 133 | 133 | |
| 134 | - if ($response->isNotModified($this->get('request'))) { |
|
| 135 | - return $response; |
|
| 136 | - } |
|
| 134 | + if ($response->isNotModified($this->get('request'))) { |
|
| 135 | + return $response; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $response->setContent($data); |
|
| 138 | + $response->setContent($data); |
|
| 139 | 139 | |
| 140 | - return $response; |
|
| 140 | + return $response; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | } |