|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\PluginBundle\Zoom; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\PluginBundle\Zoom\API\RecordingMeeting; |
|
8
|
|
|
use Database; |
|
9
|
|
|
use DateInterval; |
|
10
|
|
|
use DateTime; |
|
11
|
|
|
use DateTimeZone; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use Exception; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class RecordingEntity. |
|
17
|
|
|
* |
|
18
|
|
|
* @ORM\Entity(repositoryClass="Chamilo\PluginBundle\Zoom\RecordingRepository") |
|
19
|
|
|
* @ORM\Table( |
|
20
|
|
|
* name="plugin_zoom_recording", |
|
21
|
|
|
* indexes={ |
|
22
|
|
|
* @ORM\Index(name="meeting_id_index", columns={"meeting_id"}), |
|
23
|
|
|
* } |
|
24
|
|
|
* ) |
|
25
|
|
|
* @ORM\HasLifecycleCallbacks |
|
26
|
|
|
*/ |
|
27
|
|
|
class Recording |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var DateTime */ |
|
30
|
|
|
public $startDateTime; |
|
31
|
|
|
|
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
public $formattedStartTime; |
|
34
|
|
|
|
|
35
|
|
|
/** @var DateInterval */ |
|
36
|
|
|
public $durationInterval; |
|
37
|
|
|
|
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
public $formattedDuration; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
* @ORM\Column(type="integer") |
|
44
|
|
|
* @ORM\Id |
|
45
|
|
|
* @ORM\GeneratedValue() |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $id; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string |
|
51
|
|
|
* @ORM\Column(type="string") |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $uuid; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var Meeting |
|
57
|
|
|
* @ORM\ManyToOne(targetEntity="Meeting", inversedBy="recordings") |
|
58
|
|
|
* @ORM\JoinColumn(name="meeting_id") |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $meeting; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var string |
|
64
|
|
|
* @ORM\Column(type="text", name="recording_meeting_json", nullable=true) |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $recordingMeetingJson; |
|
67
|
|
|
|
|
68
|
|
|
/** @var RecordingMeeting */ |
|
69
|
|
|
protected $recordingMeeting; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $name |
|
73
|
|
|
* |
|
74
|
|
|
* @throws Exception |
|
75
|
|
|
* |
|
76
|
|
|
* @return mixed |
|
77
|
|
|
*/ |
|
78
|
|
|
public function __get($name) |
|
79
|
|
|
{ |
|
80
|
|
|
$object = $this->getRecordingMeeting(); |
|
81
|
|
|
if (property_exists($object, $name)) { |
|
82
|
|
|
return $object->$name; |
|
83
|
|
|
} |
|
84
|
|
|
throw new Exception(sprintf('%s does not know property %s', $this, $name)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __toString() |
|
91
|
|
|
{ |
|
92
|
|
|
return sprintf('Recording %d', $this->uuid); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return Meeting |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getMeeting() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->meeting; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @throws Exception |
|
105
|
|
|
* |
|
106
|
|
|
* @return RecordingMeeting |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getRecordingMeeting() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->recordingMeeting; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param Meeting $meeting |
|
115
|
|
|
* |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setMeeting($meeting) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->meeting = $meeting; |
|
121
|
|
|
$this->meeting->getRecordings()->add($this); |
|
122
|
|
|
|
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param RecordingMeeting $recordingMeeting |
|
128
|
|
|
* |
|
129
|
|
|
* @return Recording |
|
130
|
|
|
*@throws Exception |
|
131
|
|
|
* |
|
132
|
|
|
*/ |
|
133
|
|
|
public function setRecordingMeeting($recordingMeeting) |
|
134
|
|
|
{ |
|
135
|
|
|
if (null === $this->uuid) { |
|
136
|
|
|
$this->uuid = $recordingMeeting->uuid; |
|
137
|
|
|
} elseif ($this->uuid !== $recordingMeeting->uuid) { |
|
138
|
|
|
throw new Exception('the RecordingEntity identifier differs from the RecordingMeeting identifier'); |
|
139
|
|
|
} |
|
140
|
|
|
if (null === $this->meeting) { |
|
141
|
|
|
$this->meeting = Database::getManager()->getRepository(Meeting::class)->find($recordingMeeting->id); |
|
142
|
|
|
} elseif ($this->meeting->getId() != $recordingMeeting->id) { |
|
143
|
|
|
// $this->meeting remains null when the remote RecordingMeeting refers to a deleted meeting. |
|
144
|
|
|
throw new Exception('The RecordingEntity meeting id differs from the RecordingMeeting meeting id'); |
|
145
|
|
|
} |
|
146
|
|
|
$this->recordingMeeting = $recordingMeeting; |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @ORM\PostLoad |
|
153
|
|
|
* |
|
154
|
|
|
* @throws Exception |
|
155
|
|
|
*/ |
|
156
|
|
|
public function postLoad() |
|
157
|
|
|
{ |
|
158
|
|
|
if (null !== $this->recordingMeetingJson) { |
|
159
|
|
|
$this->recordingMeeting = RecordingMeeting::fromJson($this->recordingMeetingJson); |
|
160
|
|
|
} |
|
161
|
|
|
$this->initializeExtraProperties(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @ORM\PreFlush |
|
166
|
|
|
*/ |
|
167
|
|
|
public function preFlush() |
|
168
|
|
|
{ |
|
169
|
|
|
if (null !== $this->recordingMeeting) { |
|
170
|
|
|
$this->recordingMeetingJson = json_encode($this->recordingMeeting); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @throws Exception |
|
176
|
|
|
*/ |
|
177
|
|
|
public function initializeExtraProperties() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->startDateTime = new DateTime($this->recordingMeeting->start_time); |
|
180
|
|
|
$this->startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
181
|
|
|
$this->formattedStartTime = $this->startDateTime->format('Y-m-d H:i'); |
|
182
|
|
|
|
|
183
|
|
|
$now = new DateTime(); |
|
184
|
|
|
$later = new DateTime(); |
|
185
|
|
|
$later->add(new DateInterval('PT'.$this->recordingMeeting->duration.'M')); |
|
186
|
|
|
$this->durationInterval = $later->diff($now); |
|
|
|
|
|
|
187
|
|
|
$this->formattedDuration = $this->durationInterval->format(get_lang('DurationFormat')); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.