1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Entity; |
6
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity; |
8
|
|
|
use Chamilo\UserBundle\Entity\User; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\Common\Collections\Collection; |
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ORM\Table(name="agenda_event_invitation") |
15
|
|
|
* Add @ to the next lineactivating the agenda_collective_invitations configuration setting. |
16
|
|
|
* ORM\Entity() |
17
|
|
|
* ORM\InheritanceType("SINGLE_TABLE") |
18
|
|
|
* ORM\DiscriminatorColumn(name="type", type="string") |
19
|
|
|
* ORM\DiscriminatorMap({ |
20
|
|
|
* "invitation" = "Chamilo\CoreBundle\Entity\AgendaEventInvitation", |
21
|
|
|
* "subscription" = "Chamilo\CoreBundle\Entity\AgendaEventSubscription" |
22
|
|
|
* }) |
23
|
|
|
*/ |
24
|
|
|
class AgendaEventInvitation |
25
|
|
|
{ |
26
|
|
|
use TimestampableTypedEntity; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
* |
31
|
|
|
* @ORM\Id() |
32
|
|
|
* @ORM\Column(type="bigint") |
33
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
34
|
|
|
*/ |
35
|
|
|
protected $id; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Collection<int, AgendaEventInvitee> |
39
|
|
|
* |
40
|
|
|
* @ORM\OneToMany(targetEntity="AgendaEventInvitee", mappedBy="invitation", cascade={"persist", "remove"}, orphanRemoval=true) |
41
|
|
|
*/ |
42
|
|
|
protected $invitees; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var User |
46
|
|
|
* |
47
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="resourceNodes") |
48
|
|
|
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true, onDelete="CASCADE") |
49
|
|
|
*/ |
50
|
|
|
protected $creator; |
51
|
|
|
|
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
$this->invitees = new ArrayCollection(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getId(): int |
58
|
|
|
{ |
59
|
|
|
return $this->id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getInvitees(): Collection |
63
|
|
|
{ |
64
|
|
|
return $this->invitees; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setInvitees(Collection $invitees): AgendaEventInvitation |
68
|
|
|
{ |
69
|
|
|
$this->invitees = $invitees; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function addInvitee(AgendaEventInvitee $invitee): AgendaEventInvitation |
75
|
|
|
{ |
76
|
|
|
$invitee->setInvitation($this); |
77
|
|
|
$this->invitees->add($invitee); |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function removeInviteeUser(User $user): AgendaEventInvitation |
83
|
|
|
{ |
84
|
|
|
/** @var AgendaEventInvitee $invitee */ |
85
|
|
|
$invitee = $this |
86
|
|
|
->invitees |
87
|
|
|
->filter(function (AgendaEventInvitee $invitee) use ($user) { |
88
|
|
|
return $invitee->getUser() === $user; |
89
|
|
|
}) |
90
|
|
|
->first(); |
91
|
|
|
|
92
|
|
|
if ($invitee) { |
|
|
|
|
93
|
|
|
$this->invitees->removeElement($invitee); |
94
|
|
|
$invitee->setInvitation(null); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getCreator(): User |
101
|
|
|
{ |
102
|
|
|
return $this->creator; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setCreator(User $creator): self |
106
|
|
|
{ |
107
|
|
|
$this->creator = $creator; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function hasUserAsInvitee(User $user): bool |
113
|
|
|
{ |
114
|
|
|
return $this->invitees->exists( |
115
|
|
|
function (int $key, AgendaEventInvitee $invitee) use ($user) { |
116
|
|
|
return $invitee->getUser() === $user; |
117
|
|
|
} |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|