ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIndividualAssessmentMembersStorageDB.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 {
26  public const MEMBERS_TABLE = "iass_members";
27 
28  protected ilDBInterface $db;
29 
30  public function __construct(ilDBInterface $ilDB)
31  {
32  $this->db = $ilDB;
33  }
34 
39  {
40  $members = new ilIndividualAssessmentMembers($obj);
41  $obj_id = $obj->getId();
42  $sql = $this->loadMembersQuery($obj_id);
43  $res = $this->db->query($sql);
44  while ($rec = $this->db->fetchAssoc($res)) {
45  $members = $members->withAdditionalRecord($rec);
46  }
47  return $members;
48  }
49 
53  public function loadMembersAsSingleObjects(
55  string $filter = null,
56  string $sort = null
57  ): array {
58  $members = [];
59  $sql = $this->loadMemberQuery();
60  $sql .= " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
61 
62  if (!is_null($filter)) {
63  $sql .= $this->getWhereFromFilter($filter);
64  }
65 
66  if (!is_null($sort)) {
67  $sql .= $this->getOrderByFromSort($sort);
68  }
69  $res = $this->db->query($sql);
70  while ($rec = $this->db->fetchAssoc($res)) {
71  $usr = new ilObjUser((int)$rec["usr_id"]);
72  $members[] = $this->createAssessmentMember($obj, $usr, $rec);
73  }
74  return $members;
75  }
76 
81  {
82  $obj_id = $obj->getId();
83  $usr_id = $usr->getId();
84  $sql = $this->loadMemberQuery();
85  $sql .= " WHERE obj_id = " . $this->db->quote($obj_id, 'integer') . "\n"
86  . " AND iassme.usr_id = " . $this->db->quote($usr_id, 'integer');
87 
88  $rec = $this->db->fetchAssoc($this->db->query($sql));
89  if ($rec) {
90  return $this->createAssessmentMember($obj, $usr, $rec);
91  } else {
92  throw new ilIndividualAssessmentException("invalid usr-obj combination");
93  }
94  }
95 
96  protected function createAssessmentMember(
98  ilObjUser $usr,
99  array $record
102  if (!is_null($changer_id)) {
103  $changer_id = (int) $changer_id;
104  }
105  $change_time = null;
106  $change_time_db = $record[ilIndividualAssessmentMembers::FIELD_CHANGE_TIME];
107  if (!is_null($change_time_db)) {
108  $change_time = new DateTimeImmutable($change_time_db);
109  }
110  $examiner_id = $record[ilIndividualAssessmentMembers::FIELD_EXAMINER_ID];
111  if (!is_null($examiner_id)) {
112  $examiner_id = (int) $examiner_id;
113  }
114  return new ilIndividualAssessmentMember(
115  $obj,
116  $usr,
117  $this->createGrading($record, $usr->getFullname()),
119  $examiner_id,
120  $changer_id,
121  $change_time
122  );
123  }
124 
125  protected function createGrading(array $record, string $user_fullname): ilIndividualAssessmentUserGrading
126  {
127  $event_time = null;
128  $event_time_db = $record[ilIndividualAssessmentMembers::FIELD_EVENTTIME];
129  if (!is_null($event_time_db)) {
130  $event_time = new DateTimeImmutable();
131  $event_time = $event_time->setTimestamp((int) $event_time_db);
132  }
134  $user_fullname,
141  $event_time,
144  );
145  }
146 
150  public function updateMember(ilIndividualAssessmentMember $member): void
151  {
152  $where = [
153  "obj_id" => ["integer", $member->assessmentId()],
154  "usr_id" => ["integer", $member->id()]
155  ];
156 
157  $event_time = $member->eventTime();
158  if (!is_null($event_time)) {
159  $event_time = $event_time->getTimestamp();
160  }
161 
162  $values = [
164  ilIndividualAssessmentMembers::FIELD_EXAMINER_ID => ["integer", $member->examinerId() ?? "NULL"],
165  ilIndividualAssessmentMembers::FIELD_RECORD => ["text", $member->record()],
167  ilIndividualAssessmentMembers::FIELD_PLACE => ["text", $member->place()],
168  ilIndividualAssessmentMembers::FIELD_EVENTTIME => ["integer", $event_time],
169  ilIndividualAssessmentMembers::FIELD_NOTIFY => ["integer", $member->notify()],
176  ];
177 
178  $this->db->update(self::MEMBERS_TABLE, $values, $where);
179  }
180 
181  protected function getActualDateTime(): string
182  {
183  return date("Y-m-d H:i:s");
184  }
185 
189  public function deleteMembers(ilObjIndividualAssessment $obj): void
190  {
191  $sql = "DELETE FROM " . self::MEMBERS_TABLE . " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
192  $this->db->manipulate($sql);
193  }
194 
195  protected function loadMemberQuery(): string
196  {
197  return "SELECT "
198  . "iassme.obj_id,"
199  . "iassme.usr_id,"
200  . "iassme.examiner_id,"
201  . "iassme.record,"
202  . "iassme.internal_note,"
203  . "iassme.notify,"
204  . "iassme.notification_ts,"
205  . "iassme.learning_progress,"
206  . "iassme.finalized,"
207  . "iassme.place,"
208  . "iassme.event_time,"
209  . "iassme.user_view_file,"
210  . "iassme.file_name,"
211  . "iassme.changer_id,"
212  . "iassme.change_time,"
213  . "usr.login AS user_login,"
214  . "ex.login AS examiner_login"
215  . " FROM " . self::MEMBERS_TABLE . " iassme\n"
216  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
217  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
218  ;
219  }
220 
221  protected function loadMembersQuery(int $obj_id): string
222  {
223  return "SELECT ex.firstname as " . ilIndividualAssessmentMembers::FIELD_EXAMINER_FIRSTNAME
227  . " ,usr.firstname as " . ilIndividualAssessmentMembers::FIELD_FIRSTNAME
228  . " ,usr.lastname as " . ilIndividualAssessmentMembers::FIELD_LASTNAME
229  . " ,usr.login as " . ilIndividualAssessmentMembers::FIELD_LOGIN
231  . " ,iassme.obj_id, iassme.usr_id, iassme.examiner_id, iassme.record, iassme.internal_note, iassme.notify"
232  . " ,iassme.notification_ts, iassme.learning_progress, iassme.finalized,iassme.place"
233  . " ,iassme.event_time, iassme.changer_id, iassme.change_time\n"
234  . " FROM iass_members iassme"
235  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id"
236  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id"
237  . " LEFT JOIN usr_data ud ON iassme.changer_id = ud.usr_id"
238  . " WHERE obj_id = " . $this->db->quote($obj_id, 'integer');
239  }
240 
244  public function insertMembersRecord(ilObjIndividualAssessment $iass, array $record): void
245  {
246  $values = [
247  "obj_id" => [
248  "integer",
249  $iass->getId()
250  ],
251  "usr_id" => [
252  "integer",
254  ],
256  "text",
258  ],
260  "integer",
262  ],
264  "integer",
265  0
266  ],
268  "integer",
269  -1
270  ]
271  ];
272 
275  [
276  "integer",
278  ];
279  }
280  if (isset($record[ilIndividualAssessmentMembers::FIELD_RECORD])) {
282  [
283  "text",
285  ];
286  }
289  [
290  "text",
292  ];
293  }
294  if (isset($record[ilIndividualAssessmentMembers::FIELD_PLACE])) {
296  [
297  "text",
299  ];
300  }
303  [
304  "integer",
306  ];
307  }
310  [
311  "text",
313  ];
314  }
317  [
318  "integer",
320  ];
321  }
324  [
325  "integer",
327  ];
328  }
331  [
332  "text",
334  ];
335  }
336 
337  $this->db->insert(self::MEMBERS_TABLE, $values);
338  }
339 
343  public function removeMembersRecord(ilObjIndividualAssessment $iass, array $record): void
344  {
345  $sql =
346  "DELETE FROM " . self::MEMBERS_TABLE . PHP_EOL
347  . "WHERE obj_id = " . $this->db->quote($iass->getId(), 'integer') . PHP_EOL
348  . "AND usr_id = " . $this->db->quote($record[ilIndividualAssessmentMembers::FIELD_USR_ID], 'integer') . PHP_EOL
349  ;
350 
351  $this->db->manipulate($sql);
352  }
353 
357  protected function getWhereFromFilter($filter): string
358  {
359  switch ($filter) {
361  return " AND finalized = 0 AND examiner_id IS NULL\n";
363  return " AND finalized = 0 AND examiner_id IS NOT NULL\n";
365  return " AND finalized = 1 AND learning_progress = 2\n";
367  return " AND finalized = 1 AND learning_progress = 3\n";
368  default:
369  return "";
370  }
371  }
372 
373  protected function getOrderByFromSort(string $sort): string
374  {
375  $vals = explode(":", $sort);
376 
377  return " ORDER BY " . $vals[0] . " " . $vals[1];
378  }
379 }
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:69
deleteMembers(ilObjIndividualAssessment $obj)
Delete entries associated with members-object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
Remove a membership associated with a IndividualAssessment object inside storage.$record ...
loadMembersAsSingleObjects(ilObjIndividualAssessment $obj, string $filter=null, string $sort=null)
Get ilIndividualAssessmentMember-object for each obj member associated with $obj.ilIndividualAssessme...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...