1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenG\LaravelPhotoGallery\Entities; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use JeroenG\LaravelPhotoGallery\Contracts; |
7
|
|
|
use JeroenG\LaravelPhotoGallery\Traits\Editable; |
8
|
|
|
use JeroenG\LaravelPhotoGallery\Traits\Mappable; |
9
|
|
|
|
10
|
|
|
class Album implements Contracts\Album |
11
|
|
|
{ |
12
|
|
|
use Mappable, Editable; |
13
|
|
|
|
14
|
|
|
private $metadata; |
15
|
|
|
private $photos; |
16
|
|
|
|
17
|
|
|
public function getId() |
18
|
|
|
{ |
19
|
|
|
return $this->metadata['id']; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getName() |
23
|
|
|
{ |
24
|
|
|
return $this->metadata['name']; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getDescription() |
28
|
|
|
{ |
29
|
|
|
return $this->metadata['description']; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getOrder() |
33
|
|
|
{ |
34
|
|
|
return $this->metadata['order']; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getMetadata($attribute) |
38
|
|
|
{ |
39
|
|
|
return $this->metadata[$attribute]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function metadataContains($attribute) |
43
|
|
|
{ |
44
|
|
|
return isset($this->metadata[$attribute]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getPhotos() |
48
|
|
|
{ |
49
|
|
|
return Collection::make($this->photos); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function addPhotos($data) |
53
|
|
|
{ |
54
|
|
|
if (is_array($data)) { |
55
|
|
|
foreach ($data as $photo) { |
56
|
|
|
$this->addPhoto($photo); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function addPhoto(Contracts\Photo $photo) |
62
|
|
|
{ |
63
|
|
|
$this->photos[$photo->getId()] = $photo; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function removePhotos($data) |
67
|
|
|
{ |
68
|
|
|
if (is_array($data)) { |
69
|
|
|
foreach ($data as $photo) { |
70
|
|
|
$this->removePhoto($photo); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function removePhoto(Contracts\Photo $photo) |
76
|
|
|
{ |
77
|
|
|
if(array_key_exists($photo->getId(), $this->photos)) { |
78
|
|
|
unset($this->photos[$photo->getId()]); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function rename($newName) |
83
|
|
|
{ |
84
|
|
|
return $this->metadata['name'] = $newName; |
85
|
|
|
} |
86
|
|
|
} |