|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Api\Input\Operator\ExcludeSelfAndDescendantsOperatorType; |
|
8
|
|
|
use Application\Enum\CollectionVisibility; |
|
9
|
|
|
use Application\Repository\CollectionRepository; |
|
10
|
|
|
use Application\Traits\HasInstitution; |
|
11
|
|
|
use Application\Traits\HasParent; |
|
12
|
|
|
use Application\Traits\HasParentInterface; |
|
13
|
|
|
use Application\Traits\HasSite; |
|
14
|
|
|
use Application\Traits\HasSiteInterface; |
|
15
|
|
|
use Application\Traits\HasSorting; |
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection as DoctrineCollection; |
|
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
19
|
|
|
use Ecodev\Felix\Model\Traits\HasName; |
|
20
|
|
|
use GraphQL\Doctrine\Attribute as API; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* A collection of cards. |
|
24
|
|
|
*/ |
|
25
|
|
|
#[ORM\Index(name: 'collection_name_idx', columns: ['name'])] |
|
26
|
|
|
#[API\Filter(field: 'custom', operator: ExcludeSelfAndDescendantsOperatorType::class, type: 'id')] |
|
27
|
|
|
#[ORM\Entity(CollectionRepository::class)] |
|
28
|
|
|
class Collection extends AbstractModel implements HasParentInterface, HasSiteInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use HasInstitution; |
|
31
|
|
|
use HasName; |
|
32
|
|
|
use HasParent; |
|
33
|
|
|
use HasSite; |
|
34
|
|
|
use HasSorting; |
|
35
|
|
|
|
|
36
|
|
|
#[ORM\Column(type: 'enum', options: ['default' => CollectionVisibility::Private])] |
|
37
|
|
|
private CollectionVisibility $visibility = CollectionVisibility::Private; |
|
38
|
|
|
|
|
39
|
|
|
#[ORM\Column(type: 'text')] |
|
40
|
|
|
private string $description = ''; |
|
41
|
|
|
|
|
42
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => false])] |
|
43
|
|
|
private bool $isSource = false; |
|
44
|
|
|
|
|
45
|
|
|
#[ORM\Column(type: 'string', length: 191)] |
|
46
|
|
|
private string $copyrights = ''; |
|
47
|
|
|
|
|
48
|
|
|
#[ORM\Column(type: 'string', length: 191)] |
|
49
|
|
|
private string $usageRights = ''; |
|
50
|
|
|
|
|
51
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
52
|
|
|
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
|
53
|
|
|
private ?self $parent = null; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var DoctrineCollection<Collection> |
|
57
|
|
|
*/ |
|
58
|
|
|
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] |
|
59
|
|
|
#[ORM\OrderBy(['name' => 'ASC', 'id' => 'ASC'])] |
|
60
|
|
|
private DoctrineCollection $children; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var DoctrineCollection<User> |
|
64
|
|
|
*/ |
|
65
|
|
|
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'collections')] |
|
66
|
|
|
private DoctrineCollection $users; |
|
67
|
|
|
|
|
68
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => false])] |
|
69
|
|
|
private bool $isHistoric = false; |
|
70
|
|
|
|
|
71
|
10 |
|
public function __construct() |
|
72
|
|
|
{ |
|
73
|
10 |
|
$this->children = new ArrayCollection(); |
|
74
|
10 |
|
$this->users = new ArrayCollection(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Return whether this is publicly available to only to member, or only administrators, or only owner. |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getVisibility(): CollectionVisibility |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->visibility; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Set whether this is publicly available to only to member, or only administrators, or only owner. |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function setVisibility(CollectionVisibility $visibility): void |
|
89
|
|
|
{ |
|
90
|
1 |
|
$this->visibility = $visibility; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Set description. |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setDescription(string $description): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->description = $description; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get description. |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getDescription(): string |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->description; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Returns whether the collection is a source ("main" collection). |
|
111
|
|
|
*/ |
|
112
|
|
|
public function isSource(): bool |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->isSource; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Set whether the collection is a source ("main" collection). |
|
119
|
|
|
*/ |
|
120
|
|
|
public function setIsSource(bool $isSource): void |
|
121
|
|
|
{ |
|
122
|
|
|
$this->isSource = $isSource; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set copyrights. |
|
127
|
|
|
*/ |
|
128
|
|
|
public function setCopyrights(string $copyrights): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->copyrights = $copyrights; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Get copyrights. |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getCopyrights(): string |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->copyrights; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Set usageRights. |
|
143
|
|
|
* |
|
144
|
|
|
* @param string $usageRights |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setUsageRights($usageRights): void |
|
147
|
|
|
{ |
|
148
|
|
|
$this->usageRights = $usageRights; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Get usageRights. |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getUsageRights(): string |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->usageRights; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get users. |
|
161
|
|
|
*/ |
|
162
|
3 |
|
public function getUsers(): DoctrineCollection |
|
163
|
|
|
{ |
|
164
|
3 |
|
return $this->users; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Add User. |
|
169
|
|
|
*/ |
|
170
|
|
|
public function addUser(User $user): void |
|
171
|
|
|
{ |
|
172
|
|
|
if (!$this->users->contains($user)) { |
|
173
|
|
|
$this->users[] = $user; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Remove User. |
|
179
|
|
|
*/ |
|
180
|
|
|
public function removeUser(User $user): void |
|
181
|
|
|
{ |
|
182
|
|
|
$this->users->removeElement($user); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function hasUsers(): bool |
|
186
|
|
|
{ |
|
187
|
|
|
return count($this->users) > 0; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Returns whether the collection is historic (shows icon). |
|
192
|
|
|
*/ |
|
193
|
|
|
public function isHistoric(): bool |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->isHistoric; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Set whether the collection is historic (shows icon). |
|
200
|
|
|
*/ |
|
201
|
|
|
public function setIsHistoric(bool $isHistoric): void |
|
202
|
|
|
{ |
|
203
|
|
|
$this->isHistoric = $isHistoric; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Return whether this collections is an historic collection. |
|
208
|
|
|
*/ |
|
209
|
|
|
public function getShowHistoric(): bool |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->isHistoric() && $this->isSource(); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|