Issues (141)

server/Application/Model/Collection.php (1 issue)

Severity
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;
0 ignored issues
show
The private property $parent is not used, and could be removed.
Loading history...
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 10
    public function __construct()
69
    {
70 10
        $this->children = new ArrayCollection();
71 10
        $this->users = new ArrayCollection();
72
    }
73
74
    /**
75
     * Return whether this is publicly available to only to member, or only administrators, or only owner.
76
     */
77 1
    public function getVisibility(): CollectionVisibility
78
    {
79 1
        return $this->visibility;
80
    }
81
82
    /**
83
     * Set whether this is publicly available to only to member, or only administrators, or only owner.
84
     */
85 1
    public function setVisibility(CollectionVisibility $visibility): void
86
    {
87 1
        $this->visibility = $visibility;
88
    }
89
90
    /**
91
     * Set description.
92
     */
93
    public function setDescription(string $description): void
94
    {
95
        $this->description = $description;
96
    }
97
98
    /**
99
     * Get description.
100
     */
101
    public function getDescription(): string
102
    {
103
        return $this->description;
104
    }
105
106
    /**
107
     * Returns whether the collection is a source ("main" collection).
108
     */
109
    public function isSource(): bool
110
    {
111
        return $this->isSource;
112
    }
113
114
    /**
115
     * Set whether the collection is a source ("main" collection).
116
     */
117
    public function setIsSource(bool $isSource): void
118
    {
119
        $this->isSource = $isSource;
120
    }
121
122
    /**
123
     * Set copyrights.
124
     */
125
    public function setCopyrights(string $copyrights): void
126
    {
127
        $this->copyrights = $copyrights;
128
    }
129
130
    /**
131
     * Get copyrights.
132
     */
133
    public function getCopyrights(): string
134
    {
135
        return $this->copyrights;
136
    }
137
138
    /**
139
     * Set usageRights.
140
     *
141
     * @param string $usageRights
142
     */
143
    public function setUsageRights($usageRights): void
144
    {
145
        $this->usageRights = $usageRights;
146
    }
147
148
    /**
149
     * Get usageRights.
150
     */
151
    public function getUsageRights(): string
152
    {
153
        return $this->usageRights;
154
    }
155
156
    /**
157
     * Get users.
158
     */
159 3
    public function getUsers(): DoctrineCollection
160
    {
161 3
        return $this->users;
162
    }
163
164
    /**
165
     * Add User.
166
     */
167
    public function addUser(User $user): void
168
    {
169
        if (!$this->users->contains($user)) {
170
            $this->users[] = $user;
171
        }
172
    }
173
174
    /**
175
     * Remove User.
176
     */
177
    public function removeUser(User $user): void
178
    {
179
        $this->users->removeElement($user);
180
    }
181
182
    public function hasUsers(): bool
183
    {
184
        return count($this->users) > 0;
185
    }
186
}
187