1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
namespace Chamilo\PluginBundle\Zoom; |
5
|
|
|
|
6
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
7
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
8
|
|
|
use Chamilo\CourseBundle\Entity\CGroupInfo; |
9
|
|
|
use Chamilo\PageBundle\Entity\User; |
10
|
|
|
use DateTime; |
11
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Doctrine\Common\Collections\Collection; |
13
|
|
|
use Doctrine\Common\Collections\Criteria; |
14
|
|
|
use Doctrine\ORM\EntityRepository; |
15
|
|
|
use Doctrine\ORM\QueryBuilder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class MeetingRepository. |
19
|
|
|
*/ |
20
|
|
|
class MeetingRepository extends EntityRepository |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Retrieves information about meetings having a start_time between two dates. |
24
|
|
|
* |
25
|
|
|
* @param DateTime $startDate |
26
|
|
|
* @param DateTime $endDate |
27
|
|
|
* |
28
|
|
|
* @return Meeting[] |
29
|
|
|
*/ |
30
|
|
|
public function periodMeetings($startDate, $endDate) |
31
|
|
|
{ |
32
|
|
|
$matching = []; |
33
|
|
|
$all = $this->findAll(); |
34
|
|
|
|
35
|
|
|
/** @var Meeting $candidate */ |
36
|
|
|
foreach ($all as $candidate) { |
37
|
|
|
if (API\Meeting::TYPE_INSTANT === $candidate->getMeetingInfoGet()->type) { |
38
|
|
|
continue; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$cantidateEndDate = clone $candidate->startDateTime; |
42
|
|
|
$cantidateEndDate->add($candidate->durationInterval); |
43
|
|
|
|
44
|
|
|
if (($candidate->startDateTime >= $startDate && $candidate->startDateTime <= $endDate) |
45
|
|
|
|| ($candidate->startDateTime <= $startDate && $cantidateEndDate >= $startDate) |
46
|
|
|
) { |
47
|
|
|
$matching[] = $candidate; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $matching; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ArrayCollection|Collection|Meeting[] |
56
|
|
|
*/ |
57
|
|
|
public function globalMeetings() |
58
|
|
|
{ |
59
|
|
|
return $this->matching( |
60
|
|
|
Criteria::create()->where( |
61
|
|
|
Criteria::expr()->andX( |
62
|
|
|
Criteria::expr()->eq('course', null), |
63
|
|
|
Criteria::expr()->eq('user', null) |
64
|
|
|
) |
65
|
|
|
) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return ArrayCollection|Collection|Meeting[] |
71
|
|
|
*/ |
72
|
|
|
public function unfinishedGlobalMeetings() |
73
|
|
|
{ |
74
|
|
|
return $this->globalMeetings()->filter( |
75
|
|
|
function ($meeting) { |
76
|
|
|
return 'finished' !== $meeting->getMeetingInfoGet()->status; |
77
|
|
|
} |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns either a user's meetings or all user meetings. |
83
|
|
|
* |
84
|
|
|
* @param User|null $user |
85
|
|
|
* |
86
|
|
|
* @return QueryBuilder |
87
|
|
|
*/ |
88
|
|
|
public function userMeetings($user = null) |
89
|
|
|
{ |
90
|
|
|
$qb = $this->createQueryBuilder('m'); |
91
|
|
|
$qb |
92
|
|
|
->select('m') |
93
|
|
|
->leftJoin('m.registrants', 'r'); |
94
|
|
|
|
95
|
|
|
//$qb->select('m'); |
96
|
|
|
/*$criteria = Criteria::create()->where( |
97
|
|
|
Criteria::expr()->andX( |
98
|
|
|
Criteria::expr()->isNull('course'), |
99
|
|
|
Criteria::expr()->orX( |
100
|
|
|
Criteria::expr()->isNull('user'), |
101
|
|
|
Criteria::expr()->eq('user', $user) |
102
|
|
|
) |
103
|
|
|
));*/ |
104
|
|
|
|
105
|
|
|
/*$qb->where(Criteria::expr()->andX( |
106
|
|
|
Criteria::expr()->isNull('course'), |
107
|
|
|
Criteria::expr()->orX( |
108
|
|
|
Criteria::expr()->isNull('user'), |
109
|
|
|
Criteria::expr()->eq('user', $user) |
110
|
|
|
) |
111
|
|
|
));*/ |
112
|
|
|
|
113
|
|
|
$qb |
114
|
|
|
->andWhere('m.course IS NULL') |
115
|
|
|
->andWhere('m.user IS NULL OR m.user = :user OR r.user = :user'); |
116
|
|
|
|
117
|
|
|
$qb->setParameters(['user' => $user]); |
118
|
|
|
|
119
|
|
|
return $qb; |
120
|
|
|
|
121
|
|
|
/*return $this->matching( |
122
|
|
|
, |
123
|
|
|
Criteria::expr()->andX( |
124
|
|
|
Criteria::expr()->eq('registrants', null), |
125
|
|
|
Criteria::expr()->orX( |
126
|
|
|
Criteria::expr()->eq('user', null), |
127
|
|
|
Criteria::expr()->eq('user', $user) |
128
|
|
|
) |
129
|
|
|
) |
130
|
|
|
) |
131
|
|
|
);*/ |
132
|
|
|
|
133
|
|
|
/*return $this->matching( |
134
|
|
|
Criteria::create()->where( |
135
|
|
|
Criteria::expr()->andX( |
136
|
|
|
Criteria::expr()->eq('course', null), |
137
|
|
|
Criteria::expr()->orX( |
138
|
|
|
Criteria::expr()->eq('user', null), |
139
|
|
|
Criteria::expr()->eq('user', $user) |
140
|
|
|
) |
141
|
|
|
) |
142
|
|
|
) |
143
|
|
|
);*/ |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param User|null $user |
148
|
|
|
* |
149
|
|
|
* @return Meeting[] |
150
|
|
|
*/ |
151
|
|
|
public function unfinishedUserMeetings($user = null) |
152
|
|
|
{ |
153
|
|
|
/*return $this->userMeetings($user)->filter( |
154
|
|
|
function ($meeting) { |
155
|
|
|
return 'finished' !== $meeting->getMeetingInfoGet()->status; |
156
|
|
|
} |
157
|
|
|
);*/ |
158
|
|
|
|
159
|
|
|
$results = @$this->userMeetings($user)->getQuery()->getResult(); |
160
|
|
|
$list = []; |
161
|
|
|
foreach ($results as $meeting) { |
162
|
|
|
if ('finished' === $meeting->getMeetingInfoGet()->status) { |
163
|
|
|
$list[] = $meeting; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return $list; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param DateTime $start |
172
|
|
|
* @param DateTime $end |
173
|
|
|
* @param User $user |
174
|
|
|
* |
175
|
|
|
* @return ArrayCollection|Collection|Meeting[] |
176
|
|
|
*/ |
177
|
|
|
public function periodUserMeetings($start, $end, $user = null) |
178
|
|
|
{ |
179
|
|
|
/*return $this->userMeetings($user)->filter( |
180
|
|
|
function ($meeting) use ($start, $end) { |
181
|
|
|
return $meeting->startDateTime >= $start && $meeting->startDateTime <= $end; |
182
|
|
|
} |
183
|
|
|
);*/ |
184
|
|
|
|
185
|
|
|
$results = @$this->userMeetings($user)->getQuery()->getResult(); |
186
|
|
|
$list = []; |
187
|
|
|
if ($results) { |
188
|
|
|
foreach ($results as $meeting) { |
189
|
|
|
if ($meeting->startDateTime >= $start && $meeting->startDateTime <= $end) { |
190
|
|
|
$list[] = $meeting; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $list; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns either a course's meetings or all course meetings. |
200
|
|
|
* |
201
|
|
|
* @return ArrayCollection|Collection|Meeting[] |
202
|
|
|
*/ |
203
|
|
|
public function courseMeetings(Course $course, CGroupInfo $group = null, Session $session = null) |
204
|
|
|
{ |
205
|
|
|
return $this->matching( |
206
|
|
|
Criteria::create()->where( |
207
|
|
|
Criteria::expr()->andX( |
208
|
|
|
Criteria::expr()->eq('group', $group), |
209
|
|
|
Criteria::expr()->eq('course', $course), |
210
|
|
|
Criteria::expr()->eq('session', $session) |
211
|
|
|
) |
212
|
|
|
) |
213
|
|
|
); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|