Passed
Pull Request — 1.11.x (#4151)
by Angel Fernando Quiroz
09:24
created

Registrant::getSignature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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="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 int
34
     * @ORM\Column(type="integer", name="id")
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
    /**
73
     * @var Signature|null
74
     *
75
     * @ORM\OneToOne(targetEntity="Chamilo\PluginBundle\Zoom\Signature", mappedBy="registrant", orphanRemoval=true)
76
     */
77
    protected $signature;
78
79
    /** @var CreatedRegistration */
80
    protected $createdRegistration;
81
82
    /** @var MeetingRegistrant */
83
    protected $meetingRegistrant;
84
85
    /** @var MeetingRegistrantListItem */
86
    protected $meetingRegistrantListItem;
87
88
    /**
89
     * @return string
90
     */
91
    public function __toString()
92
    {
93
        return sprintf('Registrant %d', $this->id);
94
    }
95
96
    /**
97
     * @return Meeting
98
     */
99
    public function getMeeting()
100
    {
101
        return $this->meeting;
102
    }
103
104
    /**
105
     * @param Meeting $meeting
106
     *
107
     * @return $this
108
     */
109
    public function setMeeting($meeting)
110
    {
111
        $this->meeting = $meeting;
112
        $this->meeting->getRegistrants()->add($this);
113
114
        return $this;
115
    }
116
117
    /**
118
     * @return User
119
     */
120
    public function getUser()
121
    {
122
        return $this->user;
123
    }
124
125
    /**
126
     * @param User $user
127
     *
128
     * @return $this
129
     */
130
    public function setUser($user)
131
    {
132
        $this->user = $user;
133
134
        return $this;
135
    }
136
137
    /**
138
     * @throws Exception
139
     *
140
     * @return MeetingRegistrantListItem
141
     */
142
    public function getMeetingRegistrantListItem()
143
    {
144
        return $this->meetingRegistrantListItem;
145
    }
146
147
    /**
148
     * @param MeetingRegistrantListItem $meetingRegistrantListItem
149
     *
150
     * @throws Exception
151
     *
152
     * @return $this
153
     */
154
    public function setMeetingRegistrantListItem($meetingRegistrantListItem)
155
    {
156
        if (!is_null($this->meeting) && $this->meeting->getId() != $meetingRegistrantListItem->id) {
157
            throw new Exception('RegistrantEntity meeting id differs from MeetingRegistrantListItem id');
158
        }
159
        $this->meetingRegistrantListItem = $meetingRegistrantListItem;
160
        $this->computeFullName();
161
162
        return $this;
163
    }
164
165
    public function computeFullName()
166
    {
167
        $this->fullName = api_get_person_name(
168
            $this->meetingRegistrant->first_name,
169
            $this->meetingRegistrant->last_name
170
        );
171
    }
172
173
    public function getJoinUrl()
174
    {
175
        if (!$this->createdRegistration) {
176
            return '';
177
        }
178
179
        return $this->createdRegistration->join_url;
180
    }
181
182
    /**
183
     * @throws Exception
184
     *
185
     * @return CreatedRegistration
186
     */
187
    public function getCreatedRegistration()
188
    {
189
        return $this->createdRegistration;
190
    }
191
192
    /**
193
     * @param CreatedRegistration $createdRegistration
194
     *
195
     * @throws Exception
196
     *
197
     * @return $this
198
     */
199
    public function setCreatedRegistration($createdRegistration)
200
    {
201
        if (null === $this->id) {
202
            $this->id = $createdRegistration->registrant_id;
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type integer, but $createdRegistration->registrant_id is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
203
        } elseif ($this->id != $createdRegistration->registrant_id) {
204
            throw new Exception('RegistrantEntity id differs from CreatedRegistration identifier');
205
        }
206
        $this->createdRegistration = $createdRegistration;
207
208
        return $this;
209
    }
210
211
    /**
212
     * @throws Exception
213
     *
214
     * @return MeetingRegistrant
215
     */
216
    public function getMeetingRegistrant()
217
    {
218
        return $this->meetingRegistrant;
219
    }
220
221
    /**
222
     * @param MeetingRegistrant $meetingRegistrant
223
     *
224
     * @throws Exception
225
     *
226
     * @return $this
227
     */
228
    public function setMeetingRegistrant($meetingRegistrant)
229
    {
230
        $this->meetingRegistrant = $meetingRegistrant;
231
        $this->computeFullName();
232
233
        return $this;
234
    }
235
236
    /**
237
     * @ORM\PostLoad
238
     *
239
     * @throws Exception
240
     */
241
    public function postLoad()
242
    {
243
        if (null !== $this->meetingRegistrantJson) {
244
            $this->meetingRegistrant = MeetingRegistrant::fromJson($this->meetingRegistrantJson);
245
        }
246
        if (null !== $this->createdRegistrationJson) {
247
            $this->createdRegistration = CreatedRegistration::fromJson($this->createdRegistrationJson);
248
        }
249
        if (null !== $this->meetingRegistrantListItemJson) {
250
            $this->meetingRegistrantListItem = MeetingRegistrantListItem::fromJson(
251
                $this->meetingRegistrantListItemJson
252
            );
253
        }
254
        $this->computeFullName();
255
    }
256
257
    /**
258
     * @ORM\PreFlush
259
     */
260
    public function preFlush()
261
    {
262
        if (null !== $this->meetingRegistrant) {
263
            $this->meetingRegistrantJson = json_encode($this->meetingRegistrant);
264
        }
265
        if (null !== $this->createdRegistration) {
266
            $this->createdRegistrationJson = json_encode($this->createdRegistration);
267
        }
268
        if (null !== $this->meetingRegistrantListItem) {
269
            $this->meetingRegistrantListItemJson = json_encode($this->meetingRegistrantListItem);
270
        }
271
    }
272
273
    public function setSignature(Signature $signature): void
274
    {
275
        $this->signature = $signature;
276
277
        $signature->setRegistrant($this);
278
    }
279
280
    public function getSignature(): ?Signature
281
    {
282
        return $this->signature;
283
    }
284
}
285