Passed
Push — 1.11.x ( e0d749...b55e79 )
by Julito
23:19
created

RegistrantEntity::joinUrl()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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="Chamilo\PluginBundle\Zoom\RegistrantEntityRepository")
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 RegistrantEntity
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", nullable=false)
44
     */
45
    protected $user;
46
47
    /**
48
     * @var MeetingEntity
49
     * @ORM\ManyToOne(
50
     *     targetEntity="MeetingEntity",
51
     *     inversedBy="registrants",
52
     * )
53
     * @ORM\JoinColumn(name="meeting_id")
54
     */
55
    protected $meeting;
56
57
    /**
58
     * @var string
59
     * @ORM\Column(type="text", name="created_registration_json", nullable=true)
60
     */
61
    protected $createdRegistrationJson;
62
63
    /**
64
     * @var string
65
     * @ORM\Column(type="text", name="meeting_registrant_list_item_json", nullable=true)
66
     */
67
    protected $meetingRegistrantListItemJson;
68
69
    /**
70
     * @var string
71
     * @ORM\Column(type="text", name="meeting_registrant_json", nullable=true)
72
     */
73
    protected $meetingRegistrantJson;
74
75
    /** @var CreatedRegistration */
76
    protected $createdRegistration;
77
78
    /** @var MeetingRegistrant */
79
    protected $meetingRegistrant;
80
81
    /** @var MeetingRegistrantListItem */
82
    protected $meetingRegistrantListItem;
83
84
    /**
85
     * @return string
86
     */
87
    public function __toString()
88
    {
89
        return sprintf('Registrant %d', $this->id);
90
    }
91
92
    /**
93
     * @return MeetingEntity
94
     */
95
    public function getMeeting()
96
    {
97
        return $this->meeting;
98
    }
99
100
    /**
101
     * @param MeetingEntity $meeting
102
     *
103
     * @return $this
104
     */
105
    public function setMeeting($meeting)
106
    {
107
        $this->meeting = $meeting;
108
        $this->meeting->getRegistrants()->add($this);
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return User
115
     */
116
    public function getUser()
117
    {
118
        return $this->user;
119
    }
120
121
    /**
122
     * @param User $user
123
     *
124
     * @return $this
125
     */
126
    public function setUser($user)
127
    {
128
        $this->user = $user;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return MeetingRegistrantListItem
135
     * @throws Exception
136
     *
137
     */
138
    public function getMeetingRegistrantListItem()
139
    {
140
        return $this->meetingRegistrantListItem;
141
    }
142
143
    /**
144
     * @param MeetingRegistrantListItem $meetingRegistrantListItem
145
     *
146
     * @return $this
147
     * @throws Exception
148
     *
149
     */
150
    public function setMeetingRegistrantListItem($meetingRegistrantListItem)
151
    {
152
        if (!is_null($this->meeting) && $this->meeting->getId() != $meetingRegistrantListItem->id) {
153
            throw new Exception('RegistrantEntity meeting id differs from MeetingRegistrantListItem id');
154
        }
155
        $this->meetingRegistrantListItem = $meetingRegistrantListItem;
156
        $this->computeFullName();
157
158
        return $this;
159
    }
160
161
    public function computeFullName()
162
    {
163
        $this->fullName = api_get_person_name(
164
            $this->meetingRegistrant->first_name,
165
            $this->meetingRegistrant->last_name
166
        );
167
    }
168
169
    public function joinUrl()
170
    {
171
       return $this->meetingRegistrant->join_url;
172
    }
173
174
    /**
175
     * @return CreatedRegistration
176
     * @throws Exception
177
     *
178
     */
179
    public function getCreatedRegistration()
180
    {
181
        return $this->createdRegistration;
182
    }
183
184
    /**
185
     * @param CreatedRegistration $createdRegistration
186
     *
187
     * @return $this
188
     * @throws Exception
189
     *
190
     */
191
    public function setCreatedRegistration($createdRegistration)
192
    {
193
        if (null === $this->id) {
194
            $this->id = $createdRegistration->registrant_id;
195
        } elseif ($this->id != $createdRegistration->registrant_id) {
196
            throw new Exception('RegistrantEntity id differs from CreatedRegistration identifier');
197
        }
198
        $this->createdRegistration = $createdRegistration;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return MeetingRegistrant
205
     * @throws Exception
206
     *
207
     */
208
    public function getMeetingRegistrant()
209
    {
210
        return $this->meetingRegistrant;
211
    }
212
213
    /**
214
     * @param MeetingRegistrant $meetingRegistrant
215
     *
216
     * @return $this
217
     * @throws Exception
218
     *
219
     */
220
    public function setMeetingRegistrant($meetingRegistrant)
221
    {
222
        $this->meetingRegistrant = $meetingRegistrant;
223
        $this->computeFullName();
224
225
        return $this;
226
    }
227
228
    /**
229
     * @ORM\PostLoad
230
     *
231
     * @throws Exception
232
     */
233
    public function postLoad()
234
    {
235
        if (null !== $this->meetingRegistrantJson) {
236
            $this->meetingRegistrant = MeetingRegistrant::fromJson($this->meetingRegistrantJson);
237
        }
238
        if (null !== $this->createdRegistrationJson) {
239
            $this->createdRegistration = CreatedRegistration::fromJson($this->createdRegistrationJson);
240
        }
241
        if (null !== $this->meetingRegistrantListItemJson) {
242
            $this->meetingRegistrantListItem = MeetingRegistrantListItem::fromJson(
243
                $this->meetingRegistrantListItemJson
244
            );
245
        }
246
        $this->computeFullName();
247
    }
248
249
    /**
250
     * @ORM\PreFlush
251
     */
252
    public function preFlush()
253
    {
254
        if (null !== $this->meetingRegistrant) {
255
            $this->meetingRegistrantJson = json_encode($this->meetingRegistrant);
256
        }
257
        if (null !== $this->createdRegistration) {
258
            $this->createdRegistrationJson = json_encode($this->createdRegistration);
259
        }
260
        if (null !== $this->meetingRegistrantListItem) {
261
            $this->meetingRegistrantListItemJson = json_encode($this->meetingRegistrantListItem);
262
        }
263
    }
264
}
265