ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIndividualAssessmentMembersStorageDB.php
Go to the documentation of this file.
1 <?php
2 require_once 'Modules/IndividualAssessment/interfaces/Members/interface.ilIndividualAssessmentMembersStorage.php';
3 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembers.php';
4 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMember.php';
5 require_once 'Modules/IndividualAssessment/classes/class.ilObjIndividualAssessment.php';
15 {
16  const MEMBERS_TABLE = "iass_members";
17 
18  protected $db;
19 
20  public function __construct($ilDB)
21  {
22  $this->db = $ilDB;
23  }
24 
28  public function loadMembers(ilObjIndividualAssessment $obj)
29  {
30  $members = new ilIndividualAssessmentMembers($obj);
31  $obj_id = $obj->getId();
32  $sql = $this->loadMembersQuery($obj_id);
33  $res = $this->db->query($sql);
34  while ($rec = $this->db->fetchAssoc($res)) {
35  $members = $members->withAdditionalRecord($rec);
36  }
37  return $members;
38  }
39 
43  public function loadMembersAsSingleObjects(
45  string $filter = null,
46  string $sort = null
47  ) : array {
48  $members = [];
49  $sql = $this->loadMemberQuery();
50  $sql .= " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
51 
52  if (!is_null($filter)) {
53  $sql .= $this->getWhereFromFilter($filter);
54  }
55 
56  if (!is_null($sort)) {
57  $sql .= $this->getOrderByFromSort($sort);
58  }
59  $res = $this->db->query($sql);
60  while ($rec = $this->db->fetchAssoc($res)) {
61  $usr = new ilObjUser($rec["usr_id"]);
62  $members[] = $this->createAssessmentMember($obj, $usr, $rec);
63  }
64  return $members;
65  }
66 
70  public function loadMember(ilObjIndividualAssessment $obj, ilObjUser $usr)
71  {
72  $obj_id = $obj->getId();
73  $usr_id = $usr->getId();
74  $sql = $this->loadMemberQuery();
75  $sql .= " WHERE obj_id = " . $this->db->quote($obj_id, 'integer') . "\n"
76  . " AND iassme.usr_id = " . $this->db->quote($usr_id, 'integer');
77 
78  $rec = $this->db->fetchAssoc($this->db->query($sql));
79  if ($rec) {
80  return $this->createAssessmentMember($obj, $usr, $rec);
81  } else {
82  throw new ilIndividualAssessmentException("invalid usr-obj combination");
83  }
84  }
85 
86  protected function createAssessmentMember(
88  ilObjUser $usr,
89  array $record
92  if (!is_null($changer_id)) {
93  $changer_id = (int) $changer_id;
94  }
95  $change_time = null;
96  $change_time_db = $record[ilIndividualAssessmentMembers::FIELD_CHANGE_TIME];
97  if (!is_null($change_time_db)) {
98  $change_time = new DateTime($change_time_db);
99  }
100  $examiner_id = $record[ilIndividualAssessmentMembers::FIELD_EXAMINER_ID];
101  if (!is_null($examiner_id)) {
102  $examiner_id = (int) $examiner_id;
103  }
104  return new ilIndividualAssessmentMember(
105  $obj,
106  $usr,
107  $this->createGrading($record, $usr->getFullname()),
108  $examiner_id,
110  $changer_id,
111  $change_time
112  );
113  }
114 
115  protected function createGrading(array $record, string $user_fullname) : ilIndividualAssessmentUserGrading
116  {
117  $event_time = null;
118  $event_time_db = $record[ilIndividualAssessmentMembers::FIELD_EVENTTIME];
119  if (!is_null($event_time_db)) {
120  $event_time = new DateTimeImmutable();
121  $event_time = $event_time->setTimestamp($event_time_db);
122  }
124  $user_fullname,
131  $event_time,
134  );
135  }
136 
141  {
142  $where = array("obj_id" => array("integer", $member->assessmentId())
143  , "usr_id" => array("integer", $member->id())
144  );
145  $event_time = $member->eventTime();
146  if (!is_null($event_time)) {
147  $event_time = $event_time->getTimestamp();
148  }
149 
150  $values = [
152  ilIndividualAssessmentMembers::FIELD_EXAMINER_ID => array("integer", $member->examinerId()),
153  ilIndividualAssessmentMembers::FIELD_RECORD => array("text", $member->record()),
155  ilIndividualAssessmentMembers::FIELD_PLACE => array("text", $member->place()),
156  ilIndividualAssessmentMembers::FIELD_EVENTTIME => array("integer", $event_time),
157  ilIndividualAssessmentMembers::FIELD_NOTIFY => array("integer", $member->notify()),
158  ilIndividualAssessmentMembers::FIELD_FINALIZED => array("integer", $member->finalized()),
160  ilIndividualAssessmentMembers::FIELD_FILE_NAME => array("text", $member->fileName()),
161  ilIndividualAssessmentMembers::FIELD_USER_VIEW_FILE => array("integer", $member->viewFile()),
162  ilIndividualAssessmentMembers::FIELD_CHANGER_ID => array("integer", $member->changerId()),
163  ilIndividualAssessmentMembers::FIELD_CHANGE_TIME => array("string", date("Y-m-d H:i:s"))
164  ];
165 
166  $this->db->update(self::MEMBERS_TABLE, $values, $where);
167  }
168 
173  {
174  $sql = "DELETE FROM " . self::MEMBERS_TABLE . " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
175  $this->db->manipulate($sql);
176  }
177 
178  protected function loadMemberQuery()
179  {
180  return "SELECT "
181  . "iassme.obj_id,"
182  . "iassme.usr_id,"
183  . "iassme.examiner_id,"
184  . "iassme.record,"
185  . "iassme.internal_note,"
186  . "iassme.notify,"
187  . "iassme.notification_ts,"
188  . "iassme.learning_progress,"
189  . "iassme.finalized,"
190  . "iassme.place,"
191  . "iassme.event_time,"
192  . "iassme.user_view_file,"
193  . "iassme.file_name,"
194  . "iassme.changer_id,"
195  . "iassme.change_time,"
196  . "usr.lastname AS user_lastname,"
197  . "ex.login AS examiner_login"
198  . " FROM " . self::MEMBERS_TABLE . " iassme\n"
199  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
200  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
201  ;
202  }
203 
207  protected function loadMembersQuery($obj_id)
208  {
209  return "SELECT ex.firstname as " . ilIndividualAssessmentMembers::FIELD_EXAMINER_FIRSTNAME
213  . " ,usr.firstname as " . ilIndividualAssessmentMembers::FIELD_FIRSTNAME
214  . " ,usr.lastname as " . ilIndividualAssessmentMembers::FIELD_LASTNAME
215  . " ,usr.login as " . ilIndividualAssessmentMembers::FIELD_LOGIN
217  . " ,iassme.obj_id, iassme.usr_id, iassme.examiner_id, iassme.record, iassme.internal_note, iassme.notify"
218  . " ,iassme.notification_ts, iassme.learning_progress, iassme.finalized,iassme.place"
219  . " ,iassme.event_time, iassme.changer_id, iassme.change_time\n"
220  . " FROM iass_members iassme"
221  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id"
222  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id"
223  . " LEFT JOIN usr_data ud ON iassme.changer_id = ud.usr_id"
224  . " WHERE obj_id = " . $this->db->quote($obj_id, 'integer');
225  }
226 
230  public function insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
231  {
232  $values = array("obj_id" => array("integer", $iass->getId())
233  , "usr_id" => array("integer", $record[ilIndividualAssessmentMembers::FIELD_USR_ID])
241  , ilIndividualAssessmentMembers::FIELD_FINALIZED => array("integer", 0)
247  );
248 
249  $this->db->insert(self::MEMBERS_TABLE, $values);
250  }
251 
255  public function removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
256  {
257  $sql = "DELETE FROM " . self::MEMBERS_TABLE . "\n"
258  . " WHERE obj_id = " . $this->db->quote($iass->getId(), 'integer') . "\n"
259  . " AND usr_id = " . $this->db->quote($record[ilIndividualAssessmentMembers::FIELD_USR_ID], 'integer');
260 
261  $this->db->manipulate($sql);
262  }
263 
267  protected function getWhereFromFilter($filter) : string
268  {
269  switch ($filter) {
271  return " AND finalized = 0 AND examiner_id IS NULL\n";
272  break;
274  return " AND finalized = 0 AND examiner_id IS NOT NULL\n";
275  break;
277  return " AND finalized = 1 AND learning_progress = 2\n";
278  break;
280  return " AND finalized = 1 AND learning_progress = 3\n";
281  break;
282  }
283  }
284 
285  protected function getOrderByFromSort(string $sort) : string
286  {
287  $vals = explode(":", $sort);
288 
289  return " ORDER BY " . $vals[0] . " " . $vals[1];
290  }
291 }
createAssessmentMember(ilObjIndividualAssessment $obj, ilObjUser $usr, array $record)
loadMember(ilObjIndividualAssessment $obj, ilObjUser $usr)
Get ilIndividualAssessmentMember-object containing meberinfo associated with $obj and $usr...
deleteMembers(ilObjIndividualAssessment $obj)
Delete entries associated with members-object.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
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...
insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
Create a membership inside storage.$record
loadMembers(ilObjIndividualAssessment $obj)
Get ilIndividualAssessmentMembers-object containing meberinfo associated with $obj.ilIndividualAssessmentMembers
updateMember(ilIndividualAssessmentMember $member)
Create a new storage entry for member-object.
foreach($_POST as $key=> $value) $res
getId()
get object id public
Edit the record of a user, set LP.
getFullname($a_max_strlen=0)
get fullname public
global $ilDB
Member administration related logic, add and remove members, get the list of all members, etc.