Passed
Push — 1.11.x ( b4ce57...e435f5 )
by Julito
09:28
created

Registrant::getCreatedRegistration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\Zoom;
6
7
use Chamilo\PluginBundle\Zoom\API\CreatedRegistration;
8
use Chamilo\PluginBundle\Zoom\API\MeetingRegistrant;
9
use Chamilo\PluginBundle\Zoom\API\MeetingRegistrantListItem;
10
use Chamilo\UserBundle\Entity\User;
11
use Doctrine\ORM\Mapping as ORM;
12
use Exception;
13
14
/**
15
 * Class RegistrantEntity.
16
 *
17
 * @ORM\Entity(repositoryClass="RegistrantRepository")
18
 * @ORM\Table(
19
 *     name="plugin_zoom_registrant",
20
 *     indexes={
21
 *         @ORM\Index(name="user_id_index", columns={"user_id"}),
22
 *         @ORM\Index(name="meeting_id_index", columns={"meeting_id"}),
23
 *     }
24
 * )
25
 * @ORM\HasLifecycleCallbacks
26
 */
27
class Registrant
28
{
29
    /** @var string */
30
    public $fullName;
31
32
    /**
33
     * @var string
34
     * @ORM\Column(type="integer")
35
     * @ORM\Id
36
     * @ORM\GeneratedValue(strategy="AUTO")
37
     */
38
    protected $id;
39
40
    /**
41
     * @var User
42
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
43
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
44
     */
45
    protected $user;
46
47
    /**
48
     * @var Meeting
49
     * @ORM\ManyToOne(targetEntity="Meeting", inversedBy="registrants")
50
     * @ORM\JoinColumn(name="meeting_id", referencedColumnName="id")
51
     */
52
    protected $meeting;
53
54
    /**
55
     * @var string
56
     * @ORM\Column(type="text", name="created_registration_json", nullable=true)
57
     */
58
    protected $createdRegistrationJson;
59
60
    /**
61
     * @var string
62
     * @ORM\Column(type="text", name="meeting_registrant_list_item_json", nullable=true)
63
     */
64
    protected $meetingRegistrantListItemJson;
65
66
    /**
67
     * @var string
68
     * @ORM\Column(type="text", name="meeting_registrant_json", nullable=true)
69
     */
70
    protected $meetingRegistrantJson;
71
72
    /** @var CreatedRegistration */
73
    protected $createdRegistration;
74
75
    /** @var MeetingRegistrant */
76
    protected $meetingRegistrant;
77
78
    /** @var MeetingRegistrantListItem */
79
    protected $meetingRegistrantListItem;
80
81
    /**
82
     * @return string
83
     */
84
    public function __toString()
85
    {
86
        return sprintf('Registrant %d', $this->id);
87
    }
88
89
    /**
90
     * @return Meeting
91
     */
92
    public function getMeeting()
93
    {
94
        return $this->meeting;
95
    }
96
97
    /**
98
     * @param Meeting $meeting
99
     *
100
     * @return $this
101
     */
102
    public function setMeeting($meeting)
103
    {
104
        $this->meeting = $meeting;
105
        $this->meeting->getRegistrants()->add($this);
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return User
112
     */
113
    public function getUser()
114
    {
115
        return $this->user;
116
    }
117
118
    /**
119
     * @param User $user
120
     *
121
     * @return $this
122
     */
123
    public function setUser($user)
124
    {
125
        $this->user = $user;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @throws Exception
132
     *
133
     * @return MeetingRegistrantListItem
134
     */
135
    public function getMeetingRegistrantListItem()
136
    {
137
        return $this->meetingRegistrantListItem;
138
    }
139
140
    /**
141
     * @param MeetingRegistrantListItem $meetingRegistrantListItem
142
     *
143
     * @throws Exception
144
     *
145
     * @return $this
146
     */
147
    public function setMeetingRegistrantListItem($meetingRegistrantListItem)
148
    {
149
        if (!is_null($this->meeting) && $this->meeting->getId() != $meetingRegistrantListItem->id) {
150
            throw new Exception('RegistrantEntity meeting id differs from MeetingRegistrantListItem id');
151
        }
152
        $this->meetingRegistrantListItem = $meetingRegistrantListItem;
153
        $this->computeFullName();
154
155
        return $this;
156
    }
157
158
    public function computeFullName()
159
    {
160
        $this->fullName = api_get_person_name(
161
            $this->meetingRegistrant->first_name,
162
            $this->meetingRegistrant->last_name
163
        );
164
    }
165
166
    public function getJoinUrl()
167
    {
168
        if (!$this->createdRegistration) {
169
            return '';
170
        }
171
172
        return $this->createdRegistration->join_url;
173
    }
174
175
    /**
176
     * @throws Exception
177
     *
178
     * @return CreatedRegistration
179
     */
180
    public function getCreatedRegistration()
181
    {
182
        return $this->createdRegistration;
183
    }
184
185
    /**
186
     * @param CreatedRegistration $createdRegistration
187
     *
188
     * @throws Exception
189
     *
190
     * @return $this
191
     */
192
    public function setCreatedRegistration($createdRegistration)
193
    {
194
        if (null === $this->id) {
195
            $this->id = $createdRegistration->registrant_id;
196
        } elseif ($this->id != $createdRegistration->registrant_id) {
197
            throw new Exception('RegistrantEntity id differs from CreatedRegistration identifier');
198
        }
199
        $this->createdRegistration = $createdRegistration;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @throws Exception
206
     *
207
     * @return MeetingRegistrant
208
     */
209
    public function getMeetingRegistrant()
210
    {
211
        return $this->meetingRegistrant;
212
    }
213
214
    /**
215
     * @param MeetingRegistrant $meetingRegistrant
216
     *
217
     * @throws Exception
218
     *
219
     * @return $this
220
     */
221
    public function setMeetingRegistrant($meetingRegistrant)
222
    {
223
        $this->meetingRegistrant = $meetingRegistrant;
224
        $this->computeFullName();
225
226
        return $this;
227
    }
228
229
    /**
230
     * @ORM\PostLoad
231
     *
232
     * @throws Exception
233
     */
234
    public function postLoad()
235
    {
236
        if (null !== $this->meetingRegistrantJson) {
237
            $this->meetingRegistrant = MeetingRegistrant::fromJson($this->meetingRegistrantJson);
238
        }
239
        if (null !== $this->createdRegistrationJson) {
240
            $this->createdRegistration = CreatedRegistration::fromJson($this->createdRegistrationJson);
241
        }
242
        if (null !== $this->meetingRegistrantListItemJson) {
243
            $this->meetingRegistrantListItem = MeetingRegistrantListItem::fromJson(
244
                $this->meetingRegistrantListItemJson
245
            );
246
        }
247
        $this->computeFullName();
248
    }
249
250
    /**
251
     * @ORM\PreFlush
252
     */
253
    public function preFlush()
254
    {
255
        if (null !== $this->meetingRegistrant) {
256
            $this->meetingRegistrantJson = json_encode($this->meetingRegistrant);
257
        }
258
        if (null !== $this->createdRegistration) {
259
            $this->createdRegistrationJson = json_encode($this->createdRegistration);
260
        }
261
        if (null !== $this->meetingRegistrantListItem) {
262
            $this->meetingRegistrantListItemJson = json_encode($this->meetingRegistrantListItem);
263
        }
264
    }
265
}
266