|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Traits\HasName; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Doctrine\Common\Collections\Collection; |
|
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* A license that is required for a booking and can be owned by a user. |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\LicenseRepository") |
|
16
|
|
|
* @ORM\Table(uniqueConstraints={ |
|
17
|
|
|
* @ORM\UniqueConstraint(name="unique_name", columns={"name"}) |
|
18
|
|
|
* }) |
|
19
|
|
|
*/ |
|
20
|
|
|
class License extends AbstractModel |
|
21
|
|
|
{ |
|
22
|
|
|
use HasName; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Collection |
|
26
|
|
|
* @ORM\ManyToMany(targetEntity="Bookable", inversedBy="tags") |
|
27
|
|
|
*/ |
|
28
|
|
|
private $bookables; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Collection |
|
32
|
|
|
* @ORM\ManyToMany(targetEntity="Application\Model\User", inversedBy="licenses") |
|
33
|
|
|
*/ |
|
34
|
|
|
private $users; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->bookables = new ArrayCollection(); |
|
42
|
|
|
$this->users = new ArrayCollection(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return Collection |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getBookables(): Collection |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->bookables; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Add bookable |
|
55
|
|
|
* |
|
56
|
|
|
* @param Bookable $bookable |
|
57
|
|
|
*/ |
|
58
|
|
|
public function addBookable(Bookable $bookable): void |
|
59
|
|
|
{ |
|
60
|
|
|
if (!$this->bookables->contains($bookable)) { |
|
61
|
|
|
$this->bookables->add($bookable); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return Collection |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getUsers(): Collection |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->users; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Add user |
|
75
|
|
|
* |
|
76
|
|
|
* @param user $user |
|
77
|
|
|
*/ |
|
78
|
|
|
public function addUser(User $user): void |
|
79
|
|
|
{ |
|
80
|
|
|
if (!$this->users->contains($user)) { |
|
81
|
|
|
$this->users->add($user); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Remove user |
|
87
|
|
|
* |
|
88
|
|
|
* @param user $user |
|
89
|
|
|
*/ |
|
90
|
|
|
public function removeUser(User $user): void |
|
91
|
|
|
{ |
|
92
|
|
|
$this->users->removeElement($user); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Remove bookable |
|
97
|
|
|
* |
|
98
|
|
|
* @param Bookable $bookable |
|
99
|
|
|
*/ |
|
100
|
|
|
public function removeBookable(Bookable $bookable): void |
|
101
|
|
|
{ |
|
102
|
|
|
$this->bookables->removeElement($bookable); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|