Passed
Pull Request — 1.11.x (#4088)
by Angel Fernando Quiroz
10:36
created

AgendaEventInvitation   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 25
c 1
b 0
f 0
dl 0
loc 86
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreator() 0 3 1
A getInvitees() 0 3 1
A setCreator() 0 5 1
A removeInviteeUser() 0 16 2
A getId() 0 3 1
A setInvitees() 0 5 1
A addInvitee() 0 6 1
A __construct() 0 3 1
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
 * Add @ to the next lineactivating the agenda_collective_invitations configuration setting.
15
 * ORM\Entity().
16
 *
17
 * @ORM\Table(name="agenda_event_invitation")
18
 */
19
class AgendaEventInvitation
20
{
21
    use TimestampableTypedEntity;
22
23
    /**
24
     * @var int
25
     *
26
     * @ORM\Id()
27
     * @ORM\Column(type="bigint")
28
     * @ORM\GeneratedValue(strategy="AUTO")
29
     */
30
    protected $id;
31
32
    /**
33
     * @var Collection<int, AgendaEventInvitee>
34
     *
35
     * @ORM\OneToMany(targetEntity="AgendaEventInvitee", mappedBy="invitation", cascade={"persist", "remove"}, orphanRemoval=true)
36
     */
37
    protected $invitees;
38
39
    /**
40
     * @var User
41
     *
42
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="resourceNodes")
43
     * @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
44
     */
45
    protected $creator;
46
47
    public function __construct()
48
    {
49
        $this->invitees = new ArrayCollection();
50
    }
51
52
    public function getId(): int
53
    {
54
        return $this->id;
55
    }
56
57
    public function getInvitees(): Collection
58
    {
59
        return $this->invitees;
60
    }
61
62
    public function setInvitees(Collection $invitees): AgendaEventInvitation
63
    {
64
        $this->invitees = $invitees;
65
66
        return $this;
67
    }
68
69
    public function addInvitee(AgendaEventInvitee $invitee): AgendaEventInvitation
70
    {
71
        $invitee->setInvitation($this);
72
        $this->invitees->add($invitee);
73
74
        return $this;
75
    }
76
77
    public function removeInviteeUser(User $user): AgendaEventInvitation
78
    {
79
        /** @var AgendaEventInvitee $invitee */
80
        $invitee = $this
81
            ->invitees
82
            ->filter(function (AgendaEventInvitee $invitee) use ($user) {
83
                return $invitee->getUser() === $user;
84
            })
85
            ->first();
86
87
        if ($invitee) {
0 ignored issues
show
introduced by
$invitee is of type Chamilo\CoreBundle\Entity\AgendaEventInvitee, thus it always evaluated to true.
Loading history...
88
            $this->invitees->removeElement($invitee);
89
            $invitee->setInvitation(null);
90
        }
91
92
        return $this;
93
    }
94
95
    public function getCreator(): User
96
    {
97
        return $this->creator;
98
    }
99
100
    public function setCreator(User $creator): AgendaEventInvitation
101
    {
102
        $this->creator = $creator;
103
104
        return $this;
105
    }
106
}
107