19 declare(strict_types=1);
42 SELECT COUNT(participants.user_fi) as number_of_participants 44 ({$this->getActiveParticipantsQuery()}) 46 ({$this->getInvitedParticipantsQuery()}) 49 [$where, $types, $values] = $this->
applyFilter($filter, [], [
'integer',
'integer'], [$test_id, $test_id]);
52 $where = join(
' AND ', $where);
53 $query .=
" WHERE $where";
56 $statement = $this->database->queryF($query, $types, $values);
57 $result = $this->database->fetchAssoc($statement);
59 return $result[
'number_of_participants'] ?? 0;
67 ?array $filter =
null,
75 [
'integer',
'integer'],
80 $where = join(
' AND ', $where);
81 $query .=
" WHERE {$where}";
86 if ($order_by !==
'') {
87 $query .=
" ORDER BY {$order_by}";
90 $query .=
" LIMIT {$range->getStart()}, {$range->getLength()}";
93 $statement = $this->database->queryF($query, $types, $values);
95 while ($row = $this->database->fetchAssoc($statement)) {
103 "{$this->getBaseQuery()} WHERE active_id = %s",
104 [
'integer',
'integer',
'integer'],
105 [$test_id, $test_id, $active_id]
112 "{$this->getBaseQuery()} WHERE user_fi = %s",
113 [
'integer',
'integer',
'integer'],
114 [$test_id, $test_id, $user_id]
120 $this->database->manipulatef(
121 "INSERT INTO tst_addtime (user_fi, test_fi, additionaltime, tstamp) VALUES (%s, %s, %s, %s) 122 ON DUPLICATE KEY UPDATE tstamp = %s, additionaltime = %s",
123 [
'integer',
'integer',
'integer',
'timestamp',
'timestamp',
'integer'],
133 foreach ($participants as $participant) {
134 $this->database->replace(
151 $result = $this->database->queryF(
152 'SELECT test_fi FROM tst_active WHERE active_id = %s',
157 if ($this->database->numRows($result) > 0) {
158 $row = $this->database->fetchAssoc($result);
159 $test_id = (
int) $row[
'test_fi'];
171 $this->database->manipulate(
172 "DELETE FROM tst_invited_user WHERE test_fi = {$selected_participants[0]->getTestId()} AND " 173 . $this->database->in(
177 $selected_participants
183 $this->database->manipulate(
184 "DELETE FROM tst_addtime WHERE test_fi = {$selected_participants[0]->getTestId()} AND " 185 . $this->database->in(
189 $selected_participants
199 $times = $this->database->fetchAssoc(
200 $this->database->queryF(
201 'SELECT MIN(started) AS first_access, MAX(finished) AS last_access ' 202 .
'FROM tst_times WHERE active_fi = %s',
209 if ($times[
'first_access'] !==
null) {
210 $start_time = new \DateTimeImmutable($times[
'first_access']);
214 if ($times[
'last_access'] !==
null) {
215 $end_time = new \DateTimeImmutable($times[
'last_access']);
218 return [
'first_access' => $start_time,
'last_access' => $end_time];
227 $statement = $this->database->queryF($query, $types, $values);
228 $row = $this->database->fetchAssoc($statement);
251 if ($filter ===
null) {
252 return [$where, $types, $values];
256 $where[] =
'(firstname LIKE %s OR lastname LIKE %s)';
257 $types = array_merge($types, [
'string',
'string']);
258 $values = array_merge($values, [
"%{$filter['name']}%",
"%{$filter['name']}%"]);
262 $where[] =
'(login LIKE %s)';
263 $types = array_merge($types, [
'string']);
264 $values = array_merge($values, [
"%{$filter['login']}%"]);
268 if ($filter[
'extra_time'] ===
'true') {
269 $where[] =
'(extra_time > 0 AND extra_time IS NOT NULL)';
271 $where[] =
'(extra_time = 0 OR extra_time IS NULL)';
276 $where[] =
'(ip_range_from LIKE %s OR ip_range_to LIKE %s)';
277 $types = array_merge($types, [
'string',
'string']);
278 $values = array_merge($values, [
"%{$filter['ip_range']}%",
"%{$filter['ip_range']}%"]);
281 return [$where, $types, $values];
286 if ($order ===
null) {
290 foreach ($order->
get() as $subject => $direction) {
291 $order_by[] = match ($subject) {
292 'name' =>
"lastname {$direction}, firstname {$direction}",
293 'login' =>
"login {$direction}",
294 'ip_range' =>
"ip_range_from {$direction}, ip_range_to {$direction}",
295 'total_attempts' =>
"tries {$direction}",
296 'extra_time' =>
"extra_time {$direction}",
300 return trim(join(
', ', array_filter($order_by)));
305 return isset($filter[$key]) && trim($filter[$key]) !==
"";
314 ({$this->getActiveParticipantsQuery()}) 316 ({$this->getInvitedParticipantsQuery()}) 327 $row[
'anonymous_id'],
328 $row[
'firstname'] ??
'',
329 $row[
'lastname'] ??
'',
331 $row[
'matriculation'] ??
'',
332 $row[
'extra_time'] ?? 0,
334 $row[
'ip_range_from'],
336 $row[
'invitation_date'],
337 $row[
'submitted'] === 1,
338 $row[
'last_started_pass'],
339 $row[
'last_finished_pass'],
340 $row[
'unfinished_attempts'] === 1,
358 ta.last_finished_pass, 359 ta.last_started_pass, 360 COALESCE(ta.last_started_pass, -1) <> COALESCE(ta.last_finished_pass, -1) as unfinished_attempts, 365 (SELECT MIN(started) FROM tst_times WHERE active_fi = ta.active_id) as first_access, 366 (SELECT MAX(finished) FROM tst_times WHERE active_fi = ta.active_id) as last_access, 367 tatime.additionaltime extra_time, 368 tinvited.ip_range_from, 369 tinvited.ip_range_to, 370 tinvited.tstamp as invitation_date 372 LEFT JOIN usr_data ud 373 ON ud.usr_id = ta.user_fi 374 LEFT JOIN tst_addtime tatime 375 ON tatime.user_fi = ta.user_fi 376 AND tatime.test_fi = ta.test_fi 377 LEFT JOIN tst_invited_user tinvited 378 ON tinvited.test_fi = ta.test_fi 379 AND tinvited.user_fi = ta.user_fi 380 WHERE ta.test_fi = %s 396 ta.last_finished_pass, 397 ta.last_started_pass, 398 COALESCE(ta.last_started_pass, -1) <> COALESCE(ta.last_finished_pass, -1) as unfinished_attempts, 403 NULL as first_access, 405 tatime.additionaltime extra_time, 406 tinvited.ip_range_from, 407 tinvited.ip_range_to, 408 tinvited.tstamp as invitation_date 409 FROM tst_invited_user tinvited 410 LEFT JOIN usr_data ud 411 ON ud.usr_id = tinvited.user_fi 412 LEFT JOIN tst_addtime tatime 413 ON tatime.user_fi = tinvited.user_fi 414 AND tatime.test_fi = tinvited.test_fi 415 LEFT JOIN tst_active ta 416 ON tinvited.test_fi = ta.test_fi 417 AND tinvited.user_fi = ta.user_fi 418 WHERE tinvited.test_fi = %s AND ta.active_id IS NULL 424 $in_user_fis = $this->database->in(
430 $this->database->manipulate(
"DELETE FROM tst_addtime WHERE test_fi = $test_id AND $in_user_fis");
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private readonly \ilDBInterface $database)
getParticipants(int $test_id, ?array $filter=null, ?Range $range=null, ?Order $order=null)
isFilterSet(array $filter, string $key)
updateExtraTime(Participant $participant)
applyFilter(?array $filter, array $where, array $types, array $values)
arrayToObject(array $row)
Both the subject and the direction need to be specified when expressing an order. ...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
removeExtraTimeByUserId(int $test_id, array $user_ids)
updateIpRange(array $participants)
getParticipantByActiveId(int $test_id, int $active_id)
applyOrder(?Order $order)
getFirstAndLastVisitForActiveId(int $active_id)
getParticipantByUserId(int $test_id, int $user_id)
fetchParticipant(string $query, array $types, array $values)
getActiveParticipantsQuery()
getInvitedParticipantsQuery()
A simple class to express a naive range of whole positive numbers.
lookupTestIdByActiveId(int $active_id)
removeParticipants(array $selected_participants)
countParticipants(int $test_id, ?array $filter)