-
-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathCreateTagAlbum.php
More file actions
56 lines (49 loc) · 1.14 KB
/
CreateTagAlbum.php
File metadata and controls
56 lines (49 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace App\Actions\Album;
use App\Exceptions\ModelDBException;
use App\Exceptions\UnauthenticatedException;
use App\Models\Tag;
use App\Models\TagAlbum;
use Illuminate\Support\Facades\Auth;
class CreateTagAlbum
{
/**
* Create a new smart album based on tags.
*
* @param string $title
* @param string[] $show_tags
*
* @return TagAlbum
*
* @throws ModelDBException
* @throws UnauthenticatedException
*/
public function create(string $title, array $show_tags): TagAlbum
{
/** @var int */
$user_id = Auth::id() ?? throw new UnauthenticatedException();
$album = new TagAlbum();
$album->title = $title;
$album->show_tags = Tag::from($show_tags)->all();
$album->owner_id = $user_id;
$album->save();
$this->setStatistics($album);
return $album;
}
private function setStatistics(TagAlbum $album): void
{
$album->statistics()->create([
'album_id' => $album->id,
'photo_id' => null,
'visit_count' => 0,
'download_count' => 0,
'favourite_count' => 0,
'shared_count' => 0,
]);
}
}