ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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(ilObjIndividualAssessment $obj, string $filter = null, string $sort = null)
44  {
45  $members = [];
46  $sql = $this->loadMemberQuery();
47  $sql .= " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
48 
49  if (!is_null($filter)) {
50  $sql .= $this->getWhereFromFilter($filter);
51  }
52 
53  if (!is_null($sort)) {
54  $sql .= $this->getOrderByFromSort($sort);
55  }
56  $res = $this->db->query($sql);
57  while ($rec = $this->db->fetchAssoc($res)) {
58  $usr = new ilObjUser($rec["usr_id"]);
59  $members[] = new ilIndividualAssessmentMember($obj, $usr, $rec);
60  }
61  return $members;
62  }
63 
67  public function loadMember(ilObjIndividualAssessment $obj, ilObjUser $usr)
68  {
69  $obj_id = $obj->getId();
70  $usr_id = $usr->getId();
71  $sql = $this->loadMemberQuery();
72  $sql .= " WHERE obj_id = " . $this->db->quote($obj_id, 'integer') . "\n"
73  . " AND iassme.usr_id = " . $this->db->quote($usr_id, 'integer');
74 
75  $rec = $this->db->fetchAssoc($this->db->query($sql));
76  if ($rec) {
77  $member = new ilIndividualAssessmentMember($obj, $usr, $rec);
78  return $member;
79  } else {
80  throw new ilIndividualAssessmentException("invalid usr-obj combination");
81  }
82  }
83 
87  public function updateMember(ilIndividualAssessmentMember $member)
88  {
89  $where = array("obj_id" => array("integer", $member->assessmentId())
90  , "usr_id" => array("integer", $member->id())
91  );
92 
94  , ilIndividualAssessmentMembers::FIELD_EXAMINER_ID => array("integer", $member->examinerId())
95  , ilIndividualAssessmentMembers::FIELD_RECORD => array("text", $member->record())
97  , ilIndividualAssessmentMembers::FIELD_PLACE => array("text", $member->place())
98  , ilIndividualAssessmentMembers::FIELD_EVENTTIME => array("integer", $member->eventTime()->get(IL_CAL_UNIX))
99  , ilIndividualAssessmentMembers::FIELD_NOTIFY => array("integer", $member->notify() ? 1 : 0)
100  , ilIndividualAssessmentMembers::FIELD_FINALIZED => array("integer", $member->finalized() ? 1 : 0)
102  , ilIndividualAssessmentMembers::FIELD_FILE_NAME => array("text", $member->fileName())
103  , ilIndividualAssessmentMembers::FIELD_USER_VIEW_FILE => array("integer", $member->viewFile() ? 1 : 0)
104  , ilIndividualAssessmentMembers::FIELD_CHANGER_ID => array("integer", $member->changerId())
106  );
107 
108  $this->db->update(self::MEMBERS_TABLE, $values, $where);
109  }
110 
115  {
116  $sql = "DELETE FROM " . self::MEMBERS_TABLE . " WHERE obj_id = " . $this->db->quote($obj->getId(), 'integer');
117  $this->db->manipulate($sql);
118  }
119 
120  protected function loadMemberQuery()
121  {
122  return "SELECT "
123  . "iassme.obj_id,"
124  . "iassme.usr_id,"
125  . "iassme.examiner_id,"
126  . "iassme.record,"
127  . "iassme.internal_note,"
128  . "iassme.notify,"
129  . "iassme.notification_ts,"
130  . "iassme.learning_progress,"
131  . "iassme.finalized,"
132  . "iassme.place,"
133  . "iassme.event_time,"
134  . "iassme.user_view_file,"
135  . "iassme.file_name,"
136  . "iassme.changer_id,"
137  . "iassme.change_time,"
138  . "usr.lastname AS user_lastname,"
139  . "ex.login AS examiner_login"
140  . " FROM " . self::MEMBERS_TABLE . " iassme\n"
141  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id\n"
142  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id\n"
143  ;
144  }
145 
149  protected function loadMembersQuery($obj_id)
150  {
151  return "SELECT ex.firstname as " . ilIndividualAssessmentMembers::FIELD_EXAMINER_FIRSTNAME
155  . " ,usr.firstname as " . ilIndividualAssessmentMembers::FIELD_FIRSTNAME
156  . " ,usr.lastname as " . ilIndividualAssessmentMembers::FIELD_LASTNAME
157  . " ,usr.login as " . ilIndividualAssessmentMembers::FIELD_LOGIN
159  . " ,iassme.obj_id, iassme.usr_id, iassme.examiner_id, iassme.record, iassme.internal_note, iassme.notify"
160  . " ,iassme.notification_ts, iassme.learning_progress, iassme.finalized,iassme.place"
161  . " ,iassme.event_time, iassme.changer_id, iassme.change_time\n"
162  . " FROM iass_members iassme"
163  . " JOIN usr_data usr ON iassme.usr_id = usr.usr_id"
164  . " LEFT JOIN usr_data ex ON iassme.examiner_id = ex.usr_id"
165  . " LEFT JOIN usr_data ud ON iassme.changer_id = ud.usr_id"
166  . " WHERE obj_id = " . $this->db->quote($obj_id, 'integer');
167  }
168 
172  public function insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
173  {
174  $values = array("obj_id" => array("integer", $iass->getId())
175  , "usr_id" => array("integer", $record[ilIndividualAssessmentMembers::FIELD_USR_ID])
183  , ilIndividualAssessmentMembers::FIELD_FINALIZED => array("integer", 0)
189  );
190 
191  $this->db->insert(self::MEMBERS_TABLE, $values);
192  }
193 
197  public function removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
198  {
199  $sql = "DELETE FROM " . self::MEMBERS_TABLE . "\n"
200  . " WHERE obj_id = " . $this->db->quote($iass->getId(), 'integer') . "\n"
201  . " AND usr_id = " . $this->db->quote($record[ilIndividualAssessmentMembers::FIELD_USR_ID], 'integer');
202 
203  $this->db->manipulate($sql);
204  }
205 
209  protected function getWhereFromFilter($filter) : string
210  {
211  switch ($filter) {
213  return " AND finalized = 0 AND examiner_id IS NULL\n";
214  break;
216  return " AND finalized = 0 AND examiner_id IS NOT NULL\n";
217  break;
219  return " AND finalized = 1 AND learning_progress = 2\n";
220  break;
222  return " AND finalized = 1 AND learning_progress = 3\n";
223  break;
224  }
225  }
226 
227  protected function getOrderByFromSort(string $sort) : string
228  {
229  $vals = explode(":", $sort);
230 
231  return " ORDER BY " . $vals[0] . " " . $vals[1];
232  }
233 }
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...
const IL_CAL_DATETIME
removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
Remove a membership associated with a IndividualAssessment object inside storage.$record ...
examinerId()
Get the user id of the examiner.
loadMembersAsSingleObjects(ilObjIndividualAssessment $obj, string $filter=null, string $sort=null)
Get ilIndividualAssessmentMember-object for each obj member associated with $obj.ilIndividualAssessme...
const IL_CAL_UNIX
notificationTS()
Get the timestamp, at which the notification was sent.
finalized()
Is this membership allready finalized?
changerId()
Get the user id of the changer.
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
$values
Date and time handling
viewFile()
Can user see the uploaded file.
Edit the record of a user, set LP.
notify()
Will the user be notified after finalization?
fileName()
Get the name of the uploaded file.
global $ilDB
assessmentId()
Get the ilObjIndividualAssessment id corresponding to this membership.
id()
Get the user id corresponding to this membership.
Member administration related logic, add and remove members, get the list of all members, etc.
LPStatus()
Get the LP-status corresponding to this membership.