@@ -19,14 +19,17 @@ discard block |
||
19 | 19 | { |
20 | 20 | $this->ffmpegBin = Yii::$app->getModule('files')->ffmpeg; |
21 | 21 | |
22 | - if (!file_exists($this->ffmpegBin)) |
|
23 | - throw new ErrorException("ffmpeg is not found: {$this->ffmpegBin}"); |
|
22 | + if (!file_exists($this->ffmpegBin)) { |
|
23 | + throw new ErrorException("ffmpeg is not found: {$this->ffmpegBin}"); |
|
24 | + } |
|
24 | 25 | |
25 | - if (!is_executable($this->ffmpegBin)) |
|
26 | - throw new ErrorException("ffmpeg is not executable: {$this->ffmpegBin}"); |
|
26 | + if (!is_executable($this->ffmpegBin)) { |
|
27 | + throw new ErrorException("ffmpeg is not executable: {$this->ffmpegBin}"); |
|
28 | + } |
|
27 | 29 | |
28 | - if (!is_file($videoSourceFilename)) |
|
29 | - throw new ErrorException('File not found on disk.'); |
|
30 | + if (!is_file($videoSourceFilename)) { |
|
31 | + throw new ErrorException('File not found on disk.'); |
|
32 | + } |
|
30 | 33 | |
31 | 34 | $this->videoSourceFilename = $videoSourceFilename; |
32 | 35 | $this->outputImageFilename = $outputImageFilename; |
@@ -39,8 +42,9 @@ discard block |
||
39 | 42 | { |
40 | 43 | $command = "{$this->ffmpegBin} -i {$this->videoSourceFilename} -ss 00:00:03.000 -vframes 1 {$this->outputImageFilename}"; |
41 | 44 | exec($command, $out, $result); |
42 | - if ($result !== 0) |
|
43 | - throw new ErrorException('FFmpeg frame extracting fail:' . print_r($out, true)); |
|
45 | + if ($result !== 0) { |
|
46 | + throw new ErrorException('FFmpeg frame extracting fail:' . print_r($out, true)); |
|
47 | + } |
|
44 | 48 | } |
45 | 49 | |
46 | 50 | } |
@@ -28,11 +28,13 @@ |
||
28 | 28 | */ |
29 | 29 | public function run(): ?string |
30 | 30 | { |
31 | - if (empty($this->model) || !in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) |
|
32 | - return null; |
|
31 | + if (empty($this->model) || !in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) { |
|
32 | + return null; |
|
33 | + } |
|
33 | 34 | |
34 | - if (is_array($this->width)) |
|
35 | - $this->view = 'mediaPictureWidget'; |
|
35 | + if (is_array($this->width)) { |
|
36 | + $this->view = 'mediaPictureWidget'; |
|
37 | + } |
|
36 | 38 | |
37 | 39 | return $this->render($this->view, [ |
38 | 40 | 'model' => $this->model, |
@@ -205,7 +205,7 @@ |
||
205 | 205 | if (isset($this->_values[$att_name])) { |
206 | 206 | unset($this->_values[$att_name][0]); |
207 | 207 | if (sizeof($this->_values[$att_name])) |
208 | - return array_map(function ($fileId) { |
|
208 | + return array_map(function($fileId) { |
|
209 | 209 | return File::findOne($fileId); |
210 | 210 | }, $this->_values[$att_name]); |
211 | 211 | } else { |
@@ -69,9 +69,11 @@ discard block |
||
69 | 69 | ] |
70 | 70 | )->execute(); |
71 | 71 | |
72 | - if ($ids) foreach ($ids as $id) { |
|
72 | + if ($ids) { |
|
73 | + foreach ($ids as $id) { |
|
73 | 74 | if (empty($id)) |
74 | 75 | continue; |
76 | + } |
|
75 | 77 | $file = File::findOne($id); |
76 | 78 | if ($file) { |
77 | 79 | $file->object_id = $this->owner->id; |
@@ -106,8 +108,9 @@ discard block |
||
106 | 108 | in_array($this->owner->scenario, $params['requiredOn']) && |
107 | 109 | !in_array($this->owner->scenario, $params['requiredExcept']) && |
108 | 110 | !isset($this->_values[$attributeIds][1]) |
109 | - ) |
|
110 | - $this->owner->addError($attributeName, $params['requiredMessage']); |
|
111 | + ) { |
|
112 | + $this->owner->addError($attributeName, $params['requiredMessage']); |
|
113 | + } |
|
111 | 114 | } |
112 | 115 | } |
113 | 116 | |
@@ -124,8 +127,8 @@ discard block |
||
124 | 127 | $validators = $owner->validators; |
125 | 128 | |
126 | 129 | // Пробегаемся по валидаторам и вычисляем, какие из них касаются наших файл-полей |
127 | - if ($validators) |
|
128 | - foreach ($validators as $key => $validator) { |
|
130 | + if ($validators) { |
|
131 | + foreach ($validators as $key => $validator) { |
|
129 | 132 | |
130 | 133 | // Сначала пробегаемся по файловым валидаторам |
131 | 134 | if ($validator::className() == 'yii\validators\FileValidator' || $validator::className() == 'floor12\files\components\ReformatValidator') { |
@@ -133,6 +136,7 @@ discard block |
||
133 | 136 | |
134 | 137 | if (is_string($params)) { |
135 | 138 | $field = $params; |
139 | + } |
|
136 | 140 | $params = []; |
137 | 141 | } |
138 | 142 | |
@@ -168,8 +172,10 @@ discard block |
||
168 | 172 | } |
169 | 173 | |
170 | 174 | // Добавляем дефолтный валидатор для прилетающих айдишников |
171 | - if ($this->attributes) foreach ($this->attributes as $fieldName => $fieldParams) { |
|
175 | + if ($this->attributes) { |
|
176 | + foreach ($this->attributes as $fieldName => $fieldParams) { |
|
172 | 177 | $validator = Validator::createValidator('safe', $owner, ["{$fieldName}_ids"]); |
178 | + } |
|
173 | 179 | $validators->append($validator); |
174 | 180 | } |
175 | 181 | } |
@@ -190,8 +196,9 @@ discard block |
||
190 | 196 | */ |
191 | 197 | public function canSetProperty($name, $checkVars = true) |
192 | 198 | { |
193 | - if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) |
|
194 | - return true; |
|
199 | + if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) { |
|
200 | + return true; |
|
201 | + } |
|
195 | 202 | |
196 | 203 | return parent::canSetProperty($name, $checkVars = true); |
197 | 204 | } |
@@ -204,9 +211,10 @@ discard block |
||
204 | 211 | { |
205 | 212 | if (isset($this->_values[$att_name])) { |
206 | 213 | unset($this->_values[$att_name][0]); |
207 | - if (sizeof($this->_values[$att_name])) |
|
208 | - return array_map(function ($fileId) { |
|
214 | + if (sizeof($this->_values[$att_name])) { |
|
215 | + return array_map(function ($fileId) { |
|
209 | 216 | return File::findOne($fileId); |
217 | + } |
|
210 | 218 | }, $this->_values[$att_name]); |
211 | 219 | } else { |
212 | 220 | if (!isset($this->cachedFiles[$att_name])) { |
@@ -214,8 +222,8 @@ discard block |
||
214 | 222 | isset($this->attributes[$att_name]['validator']) && |
215 | 223 | isset($this->attributes[$att_name]['validator']['yii\validators\FileValidator']) && |
216 | 224 | $this->attributes[$att_name]['validator']['yii\validators\FileValidator']->maxFiles > 1 |
217 | - ) |
|
218 | - $this->cachedFiles[$att_name] = File::find() |
|
225 | + ) { |
|
226 | + $this->cachedFiles[$att_name] = File::find() |
|
219 | 227 | ->where( |
220 | 228 | [ |
221 | 229 | 'object_id' => $this->owner->id, |
@@ -224,7 +232,7 @@ discard block |
||
224 | 232 | ]) |
225 | 233 | ->orderBy('ordering ASC') |
226 | 234 | ->all(); |
227 | - else { |
|
235 | + } else { |
|
228 | 236 | $this->cachedFiles[$att_name] = File::find() |
229 | 237 | ->where( |
230 | 238 | [ |
@@ -249,8 +257,9 @@ discard block |
||
249 | 257 | { |
250 | 258 | $attribute = $this->getRealAttributeName($name); |
251 | 259 | |
252 | - if (array_key_exists($attribute, $this->attributes)) |
|
253 | - $this->_values[$attribute] = $value; |
|
260 | + if (array_key_exists($attribute, $this->attributes)) { |
|
261 | + $this->_values[$attribute] = $value; |
|
262 | + } |
|
254 | 263 | } |
255 | 264 | |
256 | 265 |
@@ -30,8 +30,9 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function init() |
32 | 32 | { |
33 | - if (empty($this->files)) |
|
34 | - return null; |
|
33 | + if (empty($this->files)) { |
|
34 | + return null; |
|
35 | + } |
|
35 | 36 | Yii::$app->getModule('files')->registerTranslations(); |
36 | 37 | if (empty($this->lightboxKey)) { |
37 | 38 | $this->lightboxKey = $this->files[0]->field . '-' . $this->files[0]->object_id; |
@@ -50,8 +51,9 @@ discard block |
||
50 | 51 | |
51 | 52 | $this->getView()->registerJs("yiiDownloadAllLink = '" . Url::toRoute('files/default/zip') . "'", View::POS_BEGIN, 'yiiDownloadAllLink'); |
52 | 53 | |
53 | - if ($this->passFirst && sizeof($this->files) > 0) |
|
54 | - $this->files = array_slice($this->files, 1); |
|
54 | + if ($this->passFirst && sizeof($this->files) > 0) { |
|
55 | + $this->files = array_slice($this->files, 1); |
|
56 | + } |
|
55 | 57 | |
56 | 58 | |
57 | 59 | return $this->render('fileListWidget', [ |
@@ -37,8 +37,9 @@ |
||
37 | 37 | $this->registerTranslations(); |
38 | 38 | $this->block_id = rand(9999999, 999999999); |
39 | 39 | |
40 | - if (!$this->uploadButtonText) |
|
41 | - $this->uploadButtonText = Yii::t('files', 'Upload'); |
|
40 | + if (!$this->uploadButtonText) { |
|
41 | + $this->uploadButtonText = Yii::t('files', 'Upload'); |
|
42 | + } |
|
42 | 43 | |
43 | 44 | $this->ratio = $this->model->getBehavior('files')->attributes[$this->attribute]['ratio'] ?? null; |
44 | 45 |
@@ -27,18 +27,21 @@ discard block |
||
27 | 27 | public function __construct(array $data) |
28 | 28 | { |
29 | 29 | |
30 | - if (!isset($data['id'])) |
|
31 | - throw new BadRequestHttpException('ID of file is not set.'); |
|
30 | + if (!isset($data['id'])) { |
|
31 | + throw new BadRequestHttpException('ID of file is not set.'); |
|
32 | + } |
|
32 | 33 | |
33 | - if (!isset($data['alt'])) |
|
34 | - throw new BadRequestHttpException('Alt of file is not set.'); |
|
34 | + if (!isset($data['alt'])) { |
|
35 | + throw new BadRequestHttpException('Alt of file is not set.'); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | $this->alt = $data['alt']; |
37 | 39 | |
38 | 40 | $this->_file = File::findOne($data['id']); |
39 | 41 | |
40 | - if (!$this->_file) |
|
41 | - throw new NotFoundHttpException('File not found.'); |
|
42 | + if (!$this->_file) { |
|
43 | + throw new NotFoundHttpException('File not found.'); |
|
44 | + } |
|
42 | 45 | |
43 | 46 | } |
44 | 47 | |
@@ -50,8 +53,9 @@ discard block |
||
50 | 53 | { |
51 | 54 | $this->_file->alt = $this->alt; |
52 | 55 | |
53 | - if (!$this->_file->save()) |
|
54 | - throw new BadRequestHttpException('Unable to save file.'); |
|
56 | + if (!$this->_file->save()) { |
|
57 | + throw new BadRequestHttpException('Unable to save file.'); |
|
58 | + } |
|
55 | 59 | |
56 | 60 | return $this->alt; |
57 | 61 | } |
@@ -30,8 +30,9 @@ discard block |
||
30 | 30 | $this->width = $width; |
31 | 31 | $this->webp = $webp; |
32 | 32 | |
33 | - if (!$this->model->isImage() && !$this->model->isVideo()) |
|
34 | - throw new ErrorException('File is not an image or video.'); |
|
33 | + if (!$this->model->isImage() && !$this->model->isVideo()) { |
|
34 | + throw new ErrorException('File is not an image or video.'); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | |
37 | 38 | /** |
@@ -41,8 +42,9 @@ discard block |
||
41 | 42 | */ |
42 | 43 | public function getUrl() |
43 | 44 | { |
44 | - if ($this->model->isSvg()) |
|
45 | - return $this->model->getRootPath(); |
|
45 | + if ($this->model->isSvg()) { |
|
46 | + return $this->model->getRootPath(); |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $cachePath = Yii::$app->getModule('files')->cacheFullPath; |
48 | 50 | $jpegName = $this->model->makeNameWithSize($this->model->filename, $this->width); |
@@ -56,21 +58,25 @@ discard block |
||
56 | 58 | $sourceImagePath = $this->model->rootPath; |
57 | 59 | if ($this->model->isVideo()) { |
58 | 60 | $sourceImagePath = $this->fileName . '.jpeg'; |
59 | - if (!is_file($sourceImagePath)) |
|
60 | - Yii::createObject(VideoFrameExtractor::class, [ |
|
61 | + if (!is_file($sourceImagePath)) { |
|
62 | + Yii::createObject(VideoFrameExtractor::class, [ |
|
61 | 63 | $this->model->rootPath, |
62 | 64 | $sourceImagePath |
63 | 65 | ])->extract(); |
66 | + } |
|
64 | 67 | } |
65 | 68 | |
66 | - if (!is_file($this->fileName) || filesize($this->fileName) == 0) |
|
67 | - $this->createPreview($sourceImagePath, $this->model->getWatermark()); |
|
69 | + if (!is_file($this->fileName) || filesize($this->fileName) == 0) { |
|
70 | + $this->createPreview($sourceImagePath, $this->model->getWatermark()); |
|
71 | + } |
|
68 | 72 | |
69 | - if ($this->webp && !file_exists($this->fileNameWebp)) |
|
70 | - $this->createPreviewWebp(); |
|
73 | + if ($this->webp && !file_exists($this->fileNameWebp)) { |
|
74 | + $this->createPreviewWebp(); |
|
75 | + } |
|
71 | 76 | |
72 | - if ($this->webp) |
|
73 | - return $this->fileNameWebp; |
|
77 | + if ($this->webp) { |
|
78 | + return $this->fileNameWebp; |
|
79 | + } |
|
74 | 80 | |
75 | 81 | return $this->fileName; |
76 | 82 | } |
@@ -80,19 +86,23 @@ discard block |
||
80 | 86 | */ |
81 | 87 | protected function prepareFolder() |
82 | 88 | { |
83 | - if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) |
|
84 | - mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
89 | + if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) { |
|
90 | + mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
91 | + } |
|
85 | 92 | $lastFolder = '/'; |
86 | 93 | $explodes = explode('/', $this->fileName); |
87 | 94 | array_pop($explodes); |
88 | - if (empty($explodes)) |
|
89 | - return; |
|
95 | + if (empty($explodes)) { |
|
96 | + return; |
|
97 | + } |
|
90 | 98 | foreach ($explodes as $folder) { |
91 | - if (empty($folder)) |
|
92 | - continue; |
|
99 | + if (empty($folder)) { |
|
100 | + continue; |
|
101 | + } |
|
93 | 102 | $lastFolder = $lastFolder . $folder . '/'; |
94 | - if (!file_exists($lastFolder)) |
|
95 | - mkdir($lastFolder); |
|
103 | + if (!file_exists($lastFolder)) { |
|
104 | + mkdir($lastFolder); |
|
105 | + } |
|
96 | 106 | } |
97 | 107 | } |
98 | 108 | |
@@ -106,8 +116,9 @@ discard block |
||
106 | 116 | $img = new SimpleImage(); |
107 | 117 | $img->load($sourceImagePath); |
108 | 118 | |
109 | - if ($watermarkInPng) |
|
110 | - $img->watermark($watermarkInPng); |
|
119 | + if ($watermarkInPng) { |
|
120 | + $img->watermark($watermarkInPng); |
|
121 | + } |
|
111 | 122 | |
112 | 123 | $imgWidth = $img->getWidth(); |
113 | 124 | $imgHeight = $img->getHeight(); |
@@ -35,21 +35,24 @@ discard block |
||
35 | 35 | |
36 | 36 | $this->_onlyUploaded = $onlyUploaded; |
37 | 37 | |
38 | - if (!isset($data['attribute']) || !$data['attribute'] || !isset($data['modelClass']) || !$data['modelClass']) |
|
39 | - throw new BadRequestHttpException("Attribute or class name not set."); |
|
38 | + if (!isset($data['attribute']) || !$data['attribute'] || !isset($data['modelClass']) || !$data['modelClass']) { |
|
39 | + throw new BadRequestHttpException("Attribute or class name not set."); |
|
40 | + } |
|
40 | 41 | |
41 | 42 | // Загружаем полученные данные |
42 | 43 | $this->_instance = $file; |
43 | 44 | $this->_attribute = $data['attribute']; |
44 | 45 | |
45 | - if (!file_exists($this->_instance->tempName)) |
|
46 | - throw new ErrorException("Tmp file not found on disk."); |
|
46 | + if (!file_exists($this->_instance->tempName)) { |
|
47 | + throw new ErrorException("Tmp file not found on disk."); |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Инициализируем класс владельца файла для валидаций и ставим сценарий |
49 | 51 | $this->_owner = new $data['modelClass']; |
50 | 52 | |
51 | - if (isset($data['scenario'])) |
|
52 | - $this->_owner->setScenario($data['scenario']); |
|
53 | + if (isset($data['scenario'])) { |
|
54 | + $this->_owner->setScenario($data['scenario']); |
|
55 | + } |
|
53 | 56 | |
54 | 57 | |
55 | 58 | if (isset($this->_owner->behaviors['files']->attributes[$this->_attribute]['validator'])) { |
@@ -58,8 +61,9 @@ discard block |
||
58 | 61 | throw new BadRequestHttpException('The maximum number of files has been exceeded: ' . $validator->maxFiles); |
59 | 62 | } |
60 | 63 | |
61 | - if (!$validator->validate($this->_instance, $error)) |
|
62 | - throw new BadRequestHttpException($error); |
|
64 | + if (!$validator->validate($this->_instance, $error)) { |
|
65 | + throw new BadRequestHttpException($error); |
|
66 | + } |
|
63 | 67 | } |
64 | 68 | |
65 | 69 | } |
@@ -75,10 +79,12 @@ discard block |
||
75 | 79 | $this->_model->content_type = \yii\helpers\FileHelper::getMimeType($this->_instance->tempName); |
76 | 80 | $this->_model->size = $this->_instance->size; |
77 | 81 | $this->_model->type = $this->detectType(); |
78 | - if ($identity) |
|
79 | - $this->_model->user_id = $identity->getId(); |
|
80 | - if ($this->_model->type == FileType::VIDEO) |
|
81 | - $this->_model->video_status = 0; |
|
82 | + if ($identity) { |
|
83 | + $this->_model->user_id = $identity->getId(); |
|
84 | + } |
|
85 | + if ($this->_model->type == FileType::VIDEO) { |
|
86 | + $this->_model->video_status = 0; |
|
87 | + } |
|
82 | 88 | |
83 | 89 | //Генерируем полный новый адрес сохранения файла |
84 | 90 | $this->_fullPath = Yii::$app->getModule('files')->storageFullPath . DIRECTORY_SEPARATOR . $this->_model->filename; |
@@ -90,10 +96,12 @@ discard block |
||
90 | 96 | public function detectType() |
91 | 97 | { |
92 | 98 | $contentTypeArray = explode('/', $this->_model->content_type); |
93 | - if ($contentTypeArray[0] == 'image') |
|
94 | - return FileType::IMAGE; |
|
95 | - if ($contentTypeArray[0] == 'video') |
|
96 | - return FileType::VIDEO; |
|
99 | + if ($contentTypeArray[0] == 'image') { |
|
100 | + return FileType::IMAGE; |
|
101 | + } |
|
102 | + if ($contentTypeArray[0] == 'video') { |
|
103 | + return FileType::VIDEO; |
|
104 | + } |
|
97 | 105 | return FileType::FILE; |
98 | 106 | } |
99 | 107 | |
@@ -106,10 +114,11 @@ discard block |
||
106 | 114 | $path = Yii::$app->getModule('files')->storageFullPath . $this->_model->filename; |
107 | 115 | |
108 | 116 | if ($this->_model->save()) { |
109 | - if (!$this->_onlyUploaded) |
|
110 | - copy($this->_instance->tempName, $this->_fullPath); |
|
111 | - else |
|
112 | - $this->_instance->saveAs($this->_fullPath, false); |
|
117 | + if (!$this->_onlyUploaded) { |
|
118 | + copy($this->_instance->tempName, $this->_fullPath); |
|
119 | + } else { |
|
120 | + $this->_instance->saveAs($this->_fullPath, false); |
|
121 | + } |
|
113 | 122 | } |
114 | 123 | |
115 | 124 | if ($this->_model->type == FileType::IMAGE) { |
@@ -88,29 +88,37 @@ discard block |
||
88 | 88 | { |
89 | 89 | $icon = IconHelper::FILE; |
90 | 90 | |
91 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') |
|
92 | - $icon = IconHelper::FILE_WORD; |
|
91 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { |
|
92 | + $icon = IconHelper::FILE_WORD; |
|
93 | + } |
|
93 | 94 | |
94 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') |
|
95 | - $icon = IconHelper::FILE_EXCEL; |
|
95 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') { |
|
96 | + $icon = IconHelper::FILE_EXCEL; |
|
97 | + } |
|
96 | 98 | |
97 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') |
|
98 | - $icon = IconHelper::FILE_POWERPOINT; |
|
99 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') { |
|
100 | + $icon = IconHelper::FILE_POWERPOINT; |
|
101 | + } |
|
99 | 102 | |
100 | - if ($this->content_type == 'application/x-zip-compressed') |
|
101 | - $icon = IconHelper::FILE_ARCHIVE; |
|
103 | + if ($this->content_type == 'application/x-zip-compressed') { |
|
104 | + $icon = IconHelper::FILE_ARCHIVE; |
|
105 | + } |
|
102 | 106 | |
103 | - if ($this->content_type == 'application/octet-stream') |
|
104 | - $icon = IconHelper::FILE_ARCHIVE; |
|
107 | + if ($this->content_type == 'application/octet-stream') { |
|
108 | + $icon = IconHelper::FILE_ARCHIVE; |
|
109 | + } |
|
105 | 110 | |
106 | - if (preg_match('/audio/', $this->content_type)) |
|
107 | - $icon = IconHelper::FILE_AUDIO; |
|
111 | + if (preg_match('/audio/', $this->content_type)) { |
|
112 | + $icon = IconHelper::FILE_AUDIO; |
|
113 | + } |
|
108 | 114 | |
109 | - if (preg_match('/pdf/', $this->content_type)) |
|
110 | - $icon = IconHelper::FILE_PDF; |
|
115 | + if (preg_match('/pdf/', $this->content_type)) { |
|
116 | + $icon = IconHelper::FILE_PDF; |
|
117 | + } |
|
111 | 118 | |
112 | - if ($this->type == FileType::VIDEO) |
|
113 | - $icon = IconHelper::FILE_VIDEO; |
|
119 | + if ($this->type == FileType::VIDEO) { |
|
120 | + $icon = IconHelper::FILE_VIDEO; |
|
121 | + } |
|
114 | 122 | |
115 | 123 | return $icon; |
116 | 124 | } |
@@ -227,8 +235,9 @@ discard block |
||
227 | 235 | |
228 | 236 | public function getRootPreviewPath() |
229 | 237 | { |
230 | - if ($this->isSvg()) |
|
231 | - return $this->getRootPath(); |
|
238 | + if ($this->isSvg()) { |
|
239 | + return $this->getRootPath(); |
|
240 | + } |
|
232 | 241 | |
233 | 242 | return Yii::$app->getModule('files')->storageFullPath . $this->filename . '.jpg'; |
234 | 243 | } |
@@ -343,8 +352,9 @@ discard block |
||
343 | 352 | isset($owner->behaviors['files']) && |
344 | 353 | isset($owner->behaviors['files']->attributes[$this->field]) && |
345 | 354 | isset($owner->behaviors['files']->attributes[$this->field]['watermark']) |
346 | - ) |
|
347 | - return $owner->behaviors['files']->attributes[$this->field]['watermark']; |
|
355 | + ) { |
|
356 | + return $owner->behaviors['files']->attributes[$this->field]['watermark']; |
|
357 | + } |
|
348 | 358 | } |
349 | 359 | |
350 | 360 | /** |
@@ -364,17 +374,20 @@ discard block |
||
364 | 374 | */ |
365 | 375 | public function getPreviewWebPath(int $width = 0, bool $webp = false) |
366 | 376 | { |
367 | - if (!file_exists($this->getRootPath())) |
|
368 | - return null; |
|
377 | + if (!file_exists($this->getRootPath())) { |
|
378 | + return null; |
|
379 | + } |
|
369 | 380 | |
370 | - if (!$this->isVideo() && !$this->isImage()) |
|
371 | - throw new ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
381 | + if (!$this->isVideo() && !$this->isImage()) { |
|
382 | + throw new ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
383 | + } |
|
372 | 384 | |
373 | - if (Yii::$app->getModule('files')->hostStatic) |
|
374 | - return |
|
385 | + if (Yii::$app->getModule('files')->hostStatic) { |
|
386 | + return |
|
375 | 387 | Yii::$app->getModule('files')->hostStatic . |
376 | 388 | $this->makeNameWithSize($this->filename, $width, $webp) . |
377 | 389 | "?hash={$this->hash}&width={$width}&webp=" . intval($webp); |
390 | + } |
|
378 | 391 | |
379 | 392 | return Url::toRoute(['/files/default/image', 'hash' => $this->hash, 'width' => $width, 'webp' => $webp]); |
380 | 393 | } |
@@ -410,8 +423,9 @@ discard block |
||
410 | 423 | */ |
411 | 424 | public function getPreviewRootPath($width = 0, $webp = false) |
412 | 425 | { |
413 | - if (!$this->isVideo() && !$this->isImage()) |
|
414 | - throw new ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
426 | + if (!$this->isVideo() && !$this->isImage()) { |
|
427 | + throw new ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
428 | + } |
|
415 | 429 | return $this->makeNameWithSize($this->rootPath, $width, $webp); |
416 | 430 | } |
417 | 431 |