|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Livewire; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Post; |
|
6
|
|
|
use Livewire\Component; |
|
7
|
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media; |
|
8
|
|
|
|
|
9
|
|
|
class GalleryImagesParameters extends Component |
|
10
|
|
|
{ |
|
11
|
|
|
public $model; |
|
12
|
|
|
public $image; |
|
13
|
|
|
|
|
14
|
|
|
public $image_description; |
|
15
|
|
|
public $image_video_url; |
|
16
|
|
|
public $image_caption; // String shown on image hover |
|
17
|
|
|
public $image_gallery; // The name of the gallery to assign the image to |
|
18
|
|
|
public $snippet; //the snippet to copy\paste in blog articles to show the image |
|
19
|
|
|
|
|
20
|
|
|
public $showModal = false; |
|
21
|
|
|
|
|
22
|
|
|
protected $rules = [ |
|
23
|
|
|
'image_description' => 'string', |
|
24
|
|
|
'image_video_url' => 'string', |
|
25
|
|
|
'image_caption' => 'string', |
|
26
|
|
|
'image_gallery' => 'string', |
|
27
|
|
|
'snippet' => 'string', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function mount($model) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->model = $model; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function render() |
|
36
|
|
|
{ |
|
37
|
|
|
$galleries = self::getGalleryNames(); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
return view('livewire.gallery-images-parameters', ['galleries' => $galleries]); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function edit($imageId) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->showModal = true; |
|
45
|
|
|
$this->image = Media::find($imageId); |
|
46
|
|
|
|
|
47
|
|
|
$this->image_description = $this->image->getCustomProperty('image_description'); |
|
|
|
|
|
|
48
|
|
|
$this->image_video_url = $this->image->getCustomProperty('image_video_url'); |
|
49
|
|
|
$this->image_caption = $this->image->getCustomProperty('image_caption'); |
|
50
|
|
|
$this->image_gallery = $this->image->getCustomProperty('image_gallery'); |
|
51
|
|
|
$this->snippet = self::getImageSnippet($imageId); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function save() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->image->setCustomProperty('image_description', $this->image_description); |
|
57
|
|
|
$this->image->setCustomProperty('image_video_url', $this->image_video_url); |
|
58
|
|
|
$this->image->setCustomProperty('image_caption', $this->image_caption); |
|
59
|
|
|
$this->image->setCustomProperty('image_gallery', lcfirst($this->image_gallery)); |
|
60
|
|
|
$this->image->save(); |
|
61
|
|
|
|
|
62
|
|
|
$this->showModal = false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function close() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->showModal = false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Return the array with the gallery names. |
|
73
|
|
|
* The gallery names are set as an image property. |
|
74
|
|
|
* |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getGalleryNames() |
|
78
|
|
|
{ |
|
79
|
|
|
$galleries = []; |
|
80
|
|
|
foreach ($this->model->getMedia('images') as $image) { |
|
81
|
|
|
$galleries[$image->getCustomProperty('image_gallery')] = $image->getCustomProperty('image_gallery'); |
|
82
|
|
|
} |
|
83
|
|
|
$ret = array_values($galleries); |
|
84
|
|
|
|
|
85
|
|
|
return $ret; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Create the image snippet string |
|
90
|
|
|
* |
|
91
|
|
|
* The width is expressed with a Tailwind class. |
|
92
|
|
|
* |
|
93
|
|
|
* @param int $imageId |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getImageSnippet(int $imageId): string |
|
98
|
|
|
{ |
|
99
|
|
|
return "{# image id=[" . $imageId . "] alignment=[left] width=[w-48] show_caption=[true] zoom=[true] #}"; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|