ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilIndividualAssessmentMembers.php
Go to the documentation of this file.
1 <?php
8 require_once 'Services/User/classes/class.ilObjUser.php';
9 require_once 'Modules/IndividualAssessment/classes/class.ilObjIndividualAssessment.php';
10 require_once 'Services/Tracking/classes/class.ilLPStatus.php';
11 
13 {
14  protected $member_records = array();
15  protected $position = 0;
16  protected $iass;
17 
18  const FIELD_FIRSTNAME = 'firstname';
19  const FIELD_LASTNAME = 'lastname';
20  const FIELD_LOGIN = 'login';
21  const FIELD_USR_ID = 'usr_id';
22  const FIELD_LEARNING_PROGRESS = 'learning_progress';
23  const FIELD_EXAMINER_ID = 'examiner_id';
24  const FIELD_EXAMINER_FIRSTNAME = 'examiner_firstname';
25  const FIELD_EXAMINER_LASTNAME = 'examiner_lastname';
26  const FIELD_CHANGER_ID = "changer_id";
27  const FIELD_CHANGER_FIRSTNAME = "changer_firstname";
28  const FIELD_CHANGER_LASTNAME = "changer_lastname";
29  const FIELD_CHANGE_TIME = "change_time";
30  const FIELD_RECORD = 'record';
31  const FIELD_INTERNAL_NOTE = 'internal_note';
32  const FIELD_NOTIFY = 'notify';
33  const FIELD_FINALIZED = 'finalized';
34  const FIELD_NOTIFICATION_TS = 'notification_ts';
35  const FIELD_PLACE = "place";
36  const FIELD_EVENTTIME = "event_time";
37  const FIELD_FILE_NAME = "file_name";
38  const FIELD_USER_VIEW_FILE = "user_view_file";
39 
44  const LP_ASSESSMENT_NOT_COMPLETED = "not_completed";
45 
47  {
48  $this->iass = $iass;
49  }
50 
54  public function count()
55  {
56  return count($this->member_records);
57  }
58 
62  public function current()
63  {
64  return current($this->member_records);
65  }
66 
67  public function key()
68  {
69  return key($this->member_records);
70  }
71 
72  public function next()
73  {
74  $this->position++;
75  next($this->member_records);
76  }
77 
78  public function rewind()
79  {
80  $this->position = 0;
81  reset($this->member_records);
82  }
83 
84  public function valid()
85  {
86  return $this->position < count($this->member_records);
87  }
88 
94  public function referencedObject()
95  {
96  return $this->iass;
97  }
98 
105  public function recordOK(array $record)
106  {
107  if (isset($record[self::FIELD_USR_ID])) {
108  if (!$this->userExists($record[self::FIELD_USR_ID])
109  || $this->userAllreadyMemberByUsrId($record[self::FIELD_USR_ID])) {
110  return false;
111  }
112  }
113  if (!in_array(
114  $record[self::FIELD_LEARNING_PROGRESS],
115  array(self::LP_NOT_ATTEMPTED, self::LP_FAILED, self::LP_COMPLETED, self::LP_IN_PROGRESS)
116  )) {
117  return false;
118  }
119  return true;
120  }
121 
128  public function userAllreadyMemberByUsrId($usr_id)
129  {
130  return isset($this->member_records[$usr_id]);
131  }
132 
139  public function userAllreadyMember(ilObjUser $usr)
140  {
141  return $this->userAllreadyMemberByUsrId($usr->getId());
142  }
143 
144  protected function userExists($usr_id)
145  {
146  return ilObjUser::_exists($usr_id, false, 'usr');
147  }
148 
156  public function withAdditionalRecord(array $record)
157  {
158  if ($this->recordOK($record)) {
159  $clone = clone $this;
160  $clone->member_records[$record[self::FIELD_USR_ID]] = $record;
161  return $clone;
162  }
163  throw new ilIndividualAssessmentException('illdefined record');
164  }
165 
173  public function withAdditionalUser(ilObjUser $usr)
174  {
175  if (!$this->userAllreadyMember($usr)) {
176  $clone = clone $this;
177  $clone->member_records[$usr->getId()] = $this->buildNewRecordOfUser($usr);
178  return $clone;
179  }
180  throw new ilIndividualAssessmentException('User allready member');
181  }
182 
183  protected function buildNewRecordOfUser(ilObjUser $usr)
184  {
185  return array(
186  self::FIELD_USR_ID => $usr->getId()
187  , self::FIELD_RECORD => $this->iass->getSettings()->recordTemplate()
188  , self::FIELD_NOTIFY => 0
189  , self::FIELD_FIRSTNAME => $usr->getFirstname()
190  , self::FIELD_LASTNAME => $usr->getLastname()
191  , self::FIELD_LOGIN => $usr->getLogin()
192  , self::FIELD_LEARNING_PROGRESS => self::LP_NOT_ATTEMPTED
193  , self::FIELD_EXAMINER_ID => null
194  , self::FIELD_EXAMINER_FIRSTNAME => null
195  , self::FIELD_EXAMINER_LASTNAME => null
196  , self::FIELD_INTERNAL_NOTE => null
197  , self::FIELD_FILE_NAME => null
198  , self::FIELD_USER_VIEW_FILE => false
199  , self::FIELD_FINALIZED => 0
200  , self::FIELD_CHANGER_ID => null
201  , self::FIELD_CHANGER_FIRSTNAME => null
202  , self::FIELD_CHANGER_LASTNAME => null
203  );
204  }
205 
213  public function withoutPresentUser(ilObjUser $usr)
214  {
215  $usr_id = $usr->getId();
216  if (isset($this->member_records[$usr_id]) && (string) $this->member_records[$usr_id][self::FIELD_FINALIZED] !== "1") {
217  $clone = clone $this;
218  unset($clone->member_records[$usr->getId()]);
219  return $clone;
220  }
221  throw new ilIndividualAssessmentException('User not member or allready finished');
222  }
223 
230  public function withOnlyUsersByIds($keep_users_ids)
231  {
232  $clone = clone $this;
233 
234  $remove = array_diff($this->membersIds(), $keep_users_ids);
235  foreach ($remove as $id) {
236  unset($clone->member_records[$id]);
237  }
238 
239  return $clone;
240  }
241 
250  {
251  return $this->withOnlyUsersByIds(
253  "read_learning_progress",
254  "read_learning_progress",
255  $this->referencedObject()->getRefId(),
256  $this->membersIds()
257  )
258  );
259  }
260 
261 
267  public function membersIds()
268  {
269  return array_keys($this->member_records);
270  }
271 
279  {
280  $current = $storage->loadMembers($this->referencedObject());
281  $iass = $this->referencedObject();
282  foreach ($this as $usr_id => $record) {
283  if (!$current->userAllreadyMemberByUsrId($usr_id)) {
284  $storage->insertMembersRecord($this->referencedObject(), $record);
285  $access_handler->assignUserToMemberRole(new ilObjUser($usr_id), $iass);
286  }
287  }
288  foreach ($current as $usr_id => $record) {
289  if (!$this->userAllreadyMemberByUsrId($usr_id)) {
290  $storage->removeMembersRecord($this->referencedObject(), $record);
291  $access_handler->deassignUserFromMemberRole(new ilObjUser($usr_id), $iass);
292  }
293  }
294  }
295 }
const LP_STATUS_COMPLETED_NUM
__construct(ilObjIndividualAssessment $iass)
assignUserToMemberRole(ilObjUser $usr, ilObjIndividualAssessment $iass)
Assign a user to the member role at an Individual assessment.
deassignUserFromMemberRole(ilObjUser $usr, ilObjIndividualAssessment $iass)
Deasign a user from the member role at an Individual assessment.
userAllreadyMember(ilObjUser $usr)
Check if a user is member of this.
getLogin()
get login / username public
For the purpose of streamlining the grading and learning-process status definition outside of tests...
getFirstname()
get firstname public
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
referencedObject()
Get the Individual assessment object that is corresponding to this.
const LP_STATUS_IN_PROGRESS_NUM
if(!array_key_exists('StateId', $_REQUEST)) $id
withAdditionalRecord(array $record)
Clone this and add an additional record.
removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
Remove a membership associated with a IndividualAssessment object inside storage. ...
Interface ilOrgUnitPositionAndRBACAccessHandler.
recordOK(array $record)
Check the validity of a record before adding it to this.
Mechanic regarding the access controll and roles of an objcet goes here.
withoutPresentUser(ilObjUser $usr)
Clone this andremove record corresponding to user.
getLastname()
get lastname public
getId()
get object id public
insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
Create a membership inside storage.
const LP_STATUS_NOT_ATTEMPTED_NUM
withAccessHandling(ilOrgUnitPositionAndRBACAccessHandler $access_handler)
Get a collection like this, but only including users that are visible according to the supplied acces...
withAdditionalUser(ilObjUser $usr)
Clone this and add an additional record created for user.
updateStorageAndRBAC(ilIndividualAssessmentMembersStorage $storage, IndividualAssessmentAccessHandler $access_handler)
Store the data to a persistent medium.
loadMembers(ilObjIndividualAssessment $obj)
Get ilIndividualAssessmentMembers-object containing meberinfo associated with $obj.
withOnlyUsersByIds($keep_users_ids)
Remove all users that do no exist in list of given ids.
userAllreadyMemberByUsrId($usr_id)
Check if a user with user_id is member of this.
Member administration related logic, add and remove members, get the list of all members, etc.
membersIds()
Get the ids of all the users being member in this iass.
filterUserIdsByRbacOrPositionOfCurrentUser($rbac_perm, $pos_perm, $ref_id, array $user_ids)
const LP_STATUS_FAILED_NUM