1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Concerns\Storage\Attachment; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Illuminate\Http\UploadedFile; |
7
|
|
|
use Mostafaznv\Larupload\Actions\Cover\SetCoverAction; |
8
|
|
|
use Mostafaznv\Larupload\DTOs\CoverActionData; |
9
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadFileType; |
10
|
|
|
use Mostafaznv\Larupload\Larupload; |
11
|
|
|
|
12
|
|
|
trait CoverAttachment |
13
|
|
|
{ |
14
|
|
|
public function updateCover(UploadedFile $file): bool |
15
|
|
|
{ |
16
|
|
|
file_is_valid($file, $this->name, 'cover'); |
17
|
|
|
|
18
|
|
|
if ($this->output['type']) { |
19
|
|
|
$this->uploaded = false; |
|
|
|
|
20
|
|
|
$this->cover = $file; |
|
|
|
|
21
|
|
|
$this->type = LaruploadFileType::from($this->output['type']); |
|
|
|
|
22
|
|
|
|
23
|
|
|
return true; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return false; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function detachCover(): bool |
30
|
|
|
{ |
31
|
|
|
if ($this->output['type']) { |
32
|
|
|
$this->uploaded = false; |
|
|
|
|
33
|
|
|
$this->cover = LARUPLOAD_NULL; |
|
|
|
|
34
|
|
|
$this->type = LaruploadFileType::from($this->output['type']); |
|
|
|
|
35
|
|
|
|
36
|
|
|
return true; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return false; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set cover photo |
45
|
|
|
* Generate cover photo automatically from photos and videos, if cover file was null |
46
|
|
|
* |
47
|
|
|
* @param $id |
48
|
|
|
*/ |
49
|
|
|
protected function setCover($id): void |
50
|
|
|
{ |
51
|
|
|
$path = $this->getBasePath($id, Larupload::COVER_FOLDER); |
|
|
|
|
52
|
|
|
$data = CoverActionData::make( |
53
|
|
|
disk: $this->disk, |
54
|
|
|
namingMethod: $this->namingMethod, |
55
|
|
|
lang: $this->lang, |
56
|
|
|
style: $this->coverStyle, |
|
|
|
|
57
|
|
|
type: $this->type, |
58
|
|
|
generateCover: $this->generateCover, |
59
|
|
|
withDominantColor: $this->dominantColor, |
60
|
|
|
dominantColorQuality: $this->dominantColorQuality, |
61
|
|
|
imageProcessingLibrary: $this->imageProcessingLibrary, |
62
|
|
|
output: $this->output |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->output = SetCoverAction::make($this->file ?? null, $this->cover, $data)->run($path); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|