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="licenses") |
27
|
|
|
*/ |
28
|
|
|
private $bookables; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Collection |
32
|
|
|
* @ORM\ManyToMany(targetEntity="User", inversedBy="licenses") |
33
|
|
|
*/ |
34
|
|
|
private $users; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
*/ |
39
|
5 |
|
public function __construct() |
40
|
|
|
{ |
41
|
5 |
|
$this->bookables = new ArrayCollection(); |
42
|
5 |
|
$this->users = new ArrayCollection(); |
43
|
5 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return Collection |
47
|
|
|
*/ |
48
|
1 |
|
public function getBookables(): Collection |
49
|
|
|
{ |
50
|
1 |
|
return $this->bookables; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Add bookable |
55
|
|
|
* |
56
|
|
|
* @param Bookable $bookable |
57
|
|
|
*/ |
58
|
1 |
|
public function addBookable(Bookable $bookable): void |
59
|
|
|
{ |
60
|
1 |
|
if (!$this->bookables->contains($bookable)) { |
61
|
1 |
|
$this->bookables->add($bookable); |
62
|
1 |
|
$bookable->licenseAdded($this); |
63
|
|
|
} |
64
|
1 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return Collection |
68
|
|
|
*/ |
69
|
1 |
|
public function getUsers(): Collection |
70
|
|
|
{ |
71
|
1 |
|
return $this->users; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Add user |
76
|
|
|
* |
77
|
|
|
* @param user $user |
78
|
|
|
*/ |
79
|
1 |
|
public function addUser(User $user): void |
80
|
|
|
{ |
81
|
1 |
|
if (!$this->users->contains($user)) { |
82
|
1 |
|
$this->users->add($user); |
83
|
1 |
|
$user->licenseAdded($this); |
84
|
|
|
} |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Remove user |
89
|
|
|
* |
90
|
|
|
* @param user $user |
91
|
|
|
*/ |
92
|
1 |
|
public function removeUser(User $user): void |
93
|
|
|
{ |
94
|
1 |
|
$this->users->removeElement($user); |
95
|
1 |
|
$user->licenseRemoved($this); |
96
|
1 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Remove bookable |
100
|
|
|
* |
101
|
|
|
* @param Bookable $bookable |
102
|
|
|
*/ |
103
|
1 |
|
public function removeBookable(Bookable $bookable): void |
104
|
|
|
{ |
105
|
1 |
|
$this->bookables->removeElement($bookable); |
106
|
1 |
|
$bookable->licenseRemoved($this); |
107
|
1 |
|
} |
108
|
|
|
} |
109
|
|
|
|