ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilIndividualAssessmentMembersStorageDB.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  public const MEMBERS_TABLE = "iass_members";
29 
30  public function __construct(
31  protected ilDBInterface $db,
32  protected IRSS $irss,
33  protected ilIndividualAssessmentGradingStakeholder $stakeholder
34  ) {
35  }
36 
41  {
42  $members = new ilIndividualAssessmentMembers($obj);
43  $obj_id = $obj->getId();
44  $sql = $this->loadMembersQuery($obj_id);
45  $res = $this->db->query($sql);
46  while ($rec = $this->db->fetchAssoc($res)) {
47  $members = $members->withAdditionalRecord($rec);
48  }
49  return $members;
50  }
51 
55  public function loadMembersAsSingleObjects(
57  ?string $filter = null,
58  ?string $sort = null
59  ): array {
60  $members = [];
61  $sql = $this->loadMemberQuery();
62  $sql .= " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
63 
64  if (!is_null($filter)) {
65  $sql .= $this->getWhereFromFilter($filter);
66  }
67 
68  if (!is_null($sort)) {
69  $sql .= $this->getOrderByFromSort($sort);
70  }
71  $res = $this->db->query($sql);
72  while ($rec = $this->db->fetchAssoc($res)) {
73  $usr = new ilObjUser((int) $rec["usr_id"]);
74  $members[] = $this->createAssessmentMember($obj, $usr, $rec);
75  }
76  return $members;
77  }
78 
83  {
84  $obj_id = $obj->getId();
85  $usr_id = $usr->getId();
86  $sql = $this->loadMemberQuery();
87  $sql .= " WHERE obj_id = " . $this->db->quote($obj_id, 'integer') . "\n"
88  . " AND iassme.usr_id = " . $this->db->quote($usr_id, 'integer');
89 
90  $rec = $this->db->fetchAssoc($this->db->query($sql));
91  if ($rec) {
92  return $this->createAssessmentMember($obj, $usr, $rec);
93  } else {
94  throw new ilIndividualAssessmentException("invalid usr-obj combination");
95  }
96  }
97 
98  protected function createAssessmentMember(
100  ilObjUser $usr,
101  array $record
104  if (!is_null($changer_id)) {
105  $changer_id = (int) $changer_id;
106  }
107  $change_time = null;
108  $change_time_db = $record[ilIndividualAssessmentMembers::FIELD_CHANGE_TIME];
109  if (!is_null($change_time_db)) {
110  $change_time = new DateTimeImmutable($change_time_db);
111  }
112  $examiner_id = $record[ilIndividualAssessmentMembers::FIELD_EXAMINER_ID];
113  if (!is_null($examiner_id)) {
114  $examiner_id = (int) $examiner_id;
115  }
116  return new ilIndividualAssessmentMember(
117  $obj,
118  $usr,
119  $this->createGrading($record, $usr->getFullname()),
121  $examiner_id,
122  $changer_id,
123  $change_time
124  );
125  }
126 
127  protected function createGrading(array $record, string $user_fullname): ilIndividualAssessmentUserGrading
128  {
129  $event_time = null;
130  $event_time_db = $record[ilIndividualAssessmentMembers::FIELD_EVENTTIME];
131  if (!is_null($event_time_db)) {
132  $event_time = new DateTimeImmutable();
133  $event_time = $event_time->setTimestamp((int) $event_time_db);
134  }
136  $user_fullname,
143  $event_time,
146  );
147  }
148 
152  public function updateMember(ilIndividualAssessmentMember $member): void
153  {
154  $where = [
155  "obj_id" => ["integer", $member->assessmentId()],
156  "usr_id" => ["integer", $member->id()]
157  ];
158 
159  $event_time = $member->eventTime();
160  if (!is_null($event_time)) {
161  $event_time = $event_time->getTimestamp();
162  }
163 
164  $values = [
166  ilIndividualAssessmentMembers::FIELD_EXAMINER_ID => ["integer", $member->examinerId() ?? "NULL"],
167  ilIndividualAssessmentMembers::FIELD_RECORD => ["text", $member->record()],
169  ilIndividualAssessmentMembers::FIELD_PLACE => ["text", $member->place()],
170  ilIndividualAssessmentMembers::FIELD_EVENTTIME => ["integer", $event_time],
171  ilIndividualAssessmentMembers::FIELD_NOTIFY => ["integer", $member->notify()],
178  ];
179 
180  $this->db->update(self::MEMBERS_TABLE, $values, $where);
181  }
182 
183  protected function getActualDateTime(): string
184  {
185  return date("Y-m-d H:i:s");
186  }
187 
191  public function deleteMembers(ilObjIndividualAssessment $obj): void
192  {
193  foreach ($this->loadMembers($obj) as $member) {
194  if ($identifier = $member[ilIndividualAssessmentMembers::FIELD_FILE_NAME]) {
195  $resource_id = $this->irss->manage()->find($identifier);
196  $this->irss->manage()->remove($resource_id, $this->stakeholder);
197  }
198  }
199 
200  $sql = "DELETE FROM " . self::MEMBERS_TABLE . " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
201  $this->db->manipulate($sql);
202  }
203 
204  protected function loadMemberQuery(): string
205  {
206  return "SELECT "
207  . "iassme.obj_id,"
208  . "iassme.usr_id,"
209  . "iassme.examiner_id,"
210  . "iassme.record,"
211  . "iassme.internal_note,"
212  . "iassme.notify,"
213  . "iassme.notification_ts,"
214  . "iassme.learning_progress,"
215  . "iassme.finalized,"
216  . "iassme.place,"
217  . "iassme.event_time,"
218  . "iassme.user_view_file,"
219  . "iassme.file_name,"
220  . "iassme.changer_id,"
221  . "iassme.change_time,"
222  . "usr.login AS user_login,"
223  . "ex.login AS examiner_login"
224  . " FROM " . self::MEMBERS_TABLE . " iassme\n"
225  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
226  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
227  ;
228  }
229 
230  protected function loadMembersQuery(int $obj_id): string
231  {
232  return "SELECT ex.firstname as " . ilIndividualAssessmentMembers::FIELD_EXAMINER_FIRSTNAME
236  . " ,usr.firstname as " . ilIndividualAssessmentMembers::FIELD_FIRSTNAME
237  . " ,usr.lastname as " . ilIndividualAssessmentMembers::FIELD_LASTNAME
238  . " ,usr.login as " . ilIndividualAssessmentMembers::FIELD_LOGIN
240  . " ,iassme.obj_id, iassme.usr_id, iassme.examiner_id, iassme.record, iassme.internal_note, iassme.notify"
241  . " ,iassme.notification_ts, iassme.learning_progress, iassme.finalized,iassme.place"
242  . " ,iassme.event_time, iassme.changer_id, iassme.change_time\n"
243  . " FROM iass_members iassme"
244  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id"
245  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id"
246  . " LEFT JOIN usr_data ud ON iassme.changer_id = ud.usr_id"
247  . " WHERE obj_id = " . $this->db->quote($obj_id, 'integer');
248  }
249 
253  public function insertMembersRecord(ilObjIndividualAssessment $iass, array $record): void
254  {
255  $values = [
256  "obj_id" => [
257  "integer",
258  $iass->getId()
259  ],
260  "usr_id" => [
261  "integer",
263  ],
265  "text",
267  ],
269  "integer",
271  ],
273  "integer",
274  0
275  ],
277  "integer",
278  -1
279  ]
280  ];
281 
284  [
285  "integer",
287  ];
288  }
289  if (isset($record[ilIndividualAssessmentMembers::FIELD_RECORD])) {
291  [
292  "text",
294  ];
295  }
298  [
299  "text",
301  ];
302  }
303  if (isset($record[ilIndividualAssessmentMembers::FIELD_PLACE])) {
305  [
306  "text",
308  ];
309  }
312  [
313  "integer",
315  ];
316  }
319  [
320  "text",
322  ];
323  }
326  [
327  "integer",
329  ];
330  }
333  [
334  "integer",
336  ];
337  }
340  [
341  "text",
343  ];
344  }
345 
346  $this->db->insert(self::MEMBERS_TABLE, $values);
347  }
348 
352  public function removeMembersRecord(ilObjIndividualAssessment $iass, array $record): void
353  {
354 
355  if (array_key_exists(ilIndividualAssessmentMembers::FIELD_FILE_NAME, $record)
356  && $identifier = $record[ilIndividualAssessmentMembers::FIELD_FILE_NAME]) {
357  $resource_id = $this->irss->manage()->find($identifier);
358  if (!is_null($resource_id)) {
359  $this->irss->manage()->remove($resource_id, $this->stakeholder);
360  }
361  }
362 
363  $sql =
364  "DELETE FROM " . self::MEMBERS_TABLE . PHP_EOL
365  . "WHERE obj_id = " . $this->db->quote($iass->getId(), 'integer') . PHP_EOL
366  . "AND usr_id = " . $this->db->quote($record[ilIndividualAssessmentMembers::FIELD_USR_ID], 'integer') . PHP_EOL
367  ;
368 
369  $this->db->manipulate($sql);
370  }
371 
375  protected function getWhereFromFilter($filter): string
376  {
377  switch ($filter) {
379  return " AND finalized = 0 AND examiner_id IS NULL\n";
381  return " AND finalized = 0 AND examiner_id IS NOT NULL\n";
383  return " AND finalized = 1 AND learning_progress = 2\n";
385  return " AND finalized = 1 AND learning_progress = 3\n";
386  default:
387  return "";
388  }
389  }
390 
391  protected function getOrderByFromSort(string $sort): string
392  {
393  $vals = explode(":", $sort);
394 
395  return " ORDER BY " . $vals[0] . " " . $vals[1];
396  }
397 }
createAssessmentMember(ilObjIndividualAssessment $obj, ilObjUser $usr, array $record)
loadMember(ilObjIndividualAssessment $obj, ilObjUser $usr)
Get ilIndividualAssessmentMember-object containing member info associated with $obj and $usr...
$res
Definition: ltiservices.php:66
deleteMembers(ilObjIndividualAssessment $obj)
Delete entries associated with members-object.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
__construct(protected ilDBInterface $db, protected IRSS $irss, protected ilIndividualAssessmentGradingStakeholder $stakeholder)
removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
Remove a membership associated with a IndividualAssessment object inside storage.$record ...
getFullname(int $a_max_strlen=0)
insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
Create a membership inside storage.$record
loadMembers(ilObjIndividualAssessment $obj)
Get ilIndividualAssessmentMembers-object containing member info associated with $obj.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
updateMember(ilIndividualAssessmentMember $member)
Create a new storage entry for member-object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadMembersAsSingleObjects(ilObjIndividualAssessment $obj, ?string $filter=null, ?string $sort=null)
Get ilIndividualAssessmentMember-object for each obj member associated with $obj.ilIndividualAssessme...
Edit the record of a user, set LP.
Member administration related logic, add and remove members, get the list of all members, etc ...