Registrant::getUser()   A
last analyzed

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
 * @ORM\InheritanceType("SINGLE_TABLE")
27
 * @ORM\DiscriminatorColumn(name="type", type="string")
28
 * @ORM\DiscriminatorMap({"registrant" = "Chamilo\PluginBundle\Zoom\Registrant", "presenter" = "Chamilo\PluginBundle\Zoom\Presenter"})
29
 */
30
class Registrant
31
{
32
    /** @var string */
33
    public $fullName;
34
35
    /**
36
     * @var int
37
     * @ORM\Column(type="integer", name="id")
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="AUTO")
40
     */
41
    protected $id;
42
43
    /**
44
     * @var User
45
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
46
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
47
     */
48
    protected $user;
49
50
    /**
51
     * @var Meeting
52
     * @ORM\ManyToOne(targetEntity="Meeting", inversedBy="registrants")
53
     * @ORM\JoinColumn(name="meeting_id", referencedColumnName="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
    /**
76
     * @var Signature|null
77
     *
78
     * @ORM\OneToOne(targetEntity="Chamilo\PluginBundle\Zoom\Signature", mappedBy="registrant", orphanRemoval=true)
79
     */
80
    protected $signature;
81
82
    /** @var CreatedRegistration */
83
    protected $createdRegistration;
84
85
    /** @var MeetingRegistrant */
86
    protected $meetingRegistrant;
87
88
    /** @var MeetingRegistrantListItem */
89
    protected $meetingRegistrantListItem;
90
91
    /**
92
     * @return string
93
     */
94
    public function __toString()
95
    {
96
        return sprintf('Registrant %d', $this->id);
97
    }
98
99
    /**
100
     * @return Meeting
101
     */
102
    public function getMeeting()
103
    {
104
        return $this->meeting;
105
    }
106
107
    /**
108
     * @param Meeting $meeting
109
     *
110
     * @return $this
111
     */
112
    public function setMeeting($meeting)
113
    {
114
        $this->meeting = $meeting;
115
        $this->meeting->getRegistrants()->add($this);
116
117
        return $this;
118
    }
119
120
    /**
121
     * @return User
122
     */
123
    public function getUser()
124
    {
125
        return $this->user;
126
    }
127
128
    /**
129
     * @param User $user
130
     *
131
     * @return $this
132
     */
133
    public function setUser($user)
134
    {
135
        $this->user = $user;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @throws Exception
142
     *
143
     * @return MeetingRegistrantListItem
144
     */
145
    public function getMeetingRegistrantListItem()
146
    {
147
        return $this->meetingRegistrantListItem;
148
    }
149
150
    /**
151
     * @param MeetingRegistrantListItem $meetingRegistrantListItem
152
     *
153
     * @throws Exception
154
     *
155
     * @return $this
156
     */
157
    public function setMeetingRegistrantListItem($meetingRegistrantListItem)
158
    {
159
        if (!is_null($this->meeting) && $this->meeting->getId() != $meetingRegistrantListItem->id) {
160
            throw new Exception('RegistrantEntity meeting id differs from MeetingRegistrantListItem id');
161
        }
162
        $this->meetingRegistrantListItem = $meetingRegistrantListItem;
163
        $this->computeFullName();
164
165
        return $this;
166
    }
167
168
    public function computeFullName()
169
    {
170
        $this->fullName = api_get_person_name(
171
            $this->meetingRegistrant->first_name,
172
            $this->meetingRegistrant->last_name
173
        );
174
    }
175
176
    public function getJoinUrl()
177
    {
178
        if (!$this->createdRegistration) {
179
            return '';
180
        }
181
182
        return $this->createdRegistration->join_url;
183
    }
184
185
    /**
186
     * @throws Exception
187
     *
188
     * @return CreatedRegistration
189
     */
190
    public function getCreatedRegistration()
191
    {
192
        return $this->createdRegistration;
193
    }
194
195
    /**
196
     * @param CreatedRegistration $createdRegistration
197
     *
198
     * @throws Exception
199
     *
200
     * @return $this
201
     */
202
    public function setCreatedRegistration($createdRegistration)
203
    {
204
        if (null === $this->id) {
205
            $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...
206
        } elseif ($this->id != $createdRegistration->registrant_id) {
207
            throw new Exception('RegistrantEntity id differs from CreatedRegistration identifier');
208
        }
209
        $this->createdRegistration = $createdRegistration;
210
211
        return $this;
212
    }
213
214
    /**
215
     * @throws Exception
216
     *
217
     * @return MeetingRegistrant
218
     */
219
    public function getMeetingRegistrant()
220
    {
221
        return $this->meetingRegistrant;
222
    }
223
224
    /**
225
     * @throws Exception
226
     */
227
    public function setMeetingRegistrant(API\RegistrantSchema $meetingRegistrant): Registrant
228
    {
229
        $this->meetingRegistrant = $meetingRegistrant;
0 ignored issues
show
Documentation Bug introduced by
$meetingRegistrant is of type Chamilo\PluginBundle\Zoom\API\RegistrantSchema, but the property $meetingRegistrant was declared to be of type Chamilo\PluginBundle\Zoom\API\MeetingRegistrant. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
230
        $this->computeFullName();
231
232
        return $this;
233
    }
234
235
    /**
236
     * @ORM\PostLoad
237
     *
238
     * @throws Exception
239
     */
240
    public function postLoad()
241
    {
242
        if (null !== $this->meetingRegistrantJson) {
243
            $this->meetingRegistrant = MeetingRegistrant::fromJson($this->meetingRegistrantJson);
244
        }
245
        if (null !== $this->createdRegistrationJson) {
246
            $this->createdRegistration = CreatedRegistration::fromJson($this->createdRegistrationJson);
247
        }
248
        if (null !== $this->meetingRegistrantListItemJson) {
249
            $this->meetingRegistrantListItem = MeetingRegistrantListItem::fromJson(
250
                $this->meetingRegistrantListItemJson
251
            );
252
        }
253
        $this->computeFullName();
254
    }
255
256
    /**
257
     * @ORM\PreFlush
258
     */
259
    public function preFlush()
260
    {
261
        if (null !== $this->meetingRegistrant) {
262
            $this->meetingRegistrantJson = json_encode($this->meetingRegistrant);
263
        }
264
        if (null !== $this->createdRegistration) {
265
            $this->createdRegistrationJson = json_encode($this->createdRegistration);
266
        }
267
        if (null !== $this->meetingRegistrantListItem) {
268
            $this->meetingRegistrantListItemJson = json_encode($this->meetingRegistrantListItem);
269
        }
270
    }
271
272
    public function setSignature(Signature $signature): void
273
    {
274
        $this->signature = $signature;
275
276
        $signature->setRegistrant($this);
277
    }
278
279
    public function getSignature(): ?Signature
280
    {
281
        return $this->signature;
282
    }
283
}
284