ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  protected $member_records = array();
14  protected $position = 0;
15  protected $iass;
16 
17  const FIELD_FIRSTNAME = 'firstname';
18  const FIELD_LASTNAME = 'lastname';
19  const FIELD_LOGIN = 'login';
20  const FIELD_USR_ID = 'usr_id';
21  const FIELD_LEARNING_PROGRESS = 'learning_progress';
22  const FIELD_EXAMINER_ID = 'examiner_id';
23  const FIELD_EXAMINER_FIRSTNAME = 'examiner_firstname';
24  const FIELD_EXAMINER_LASTNAME = 'examiner_lastname';
25  const FIELD_RECORD = 'record';
26  const FIELD_INTERNAL_NOTE = 'internal_note';
27  const FIELD_NOTIFY = 'notify';
28  const FIELD_FINALIZED = 'finalized';
29  const FIELD_NOTIFICATION_TS = 'notification_ts';
30 
35 
37  $this->iass = $iass;
38  }
39 
43  public function count() {
44  return count($this->member_records);
45  }
46 
50  public function current() {
51  return current($this->member_records);
52  }
53 
54  public function key() {
55  return key($this->member_records);
56  }
57 
58  public function next() {
59  $this->position++;
60  next($this->member_records);
61  }
62 
63  public function rewind() {
64  $this->position = 0;
65  reset($this->member_records);
66  }
67 
68  public function valid() {
69  return $this->position < count($this->member_records);
70  }
71 
77  public function referencedObject() {
78  return $this->iass;
79  }
80 
87  public function recordOK(array $record) {
88  if(isset($record[self::FIELD_USR_ID])) {
89  if(!$this->userExists($record[self::FIELD_USR_ID])
90  || $this->userAllreadyMemberByUsrId($record[self::FIELD_USR_ID])) {
91  return false;
92  }
93  }
94  if(!in_array($record[self::FIELD_LEARNING_PROGRESS],
95  array(self::LP_NOT_ATTEMPTED, self::LP_FAILED, self::LP_COMPLETED, self::LP_IN_PROGRESS))) {
96  return false;
97  }
98  return true;
99  }
100 
107  public function userAllreadyMemberByUsrId($usr_id) {
108  return isset($this->member_records[$usr_id]);
109  }
110 
117  public function userAllreadyMember(ilObjUser $usr) {
118  return $this->userAllreadyMemberByUsrId($usr->getId());
119  }
120 
121  protected function userExists($usr_id) {
122  return ilObjUser::_exists($usr_id,false,'usr');
123  }
124 
132  public function withAdditionalRecord(array $record) {
133  if($this->recordOK($record)) {
134  $clone = clone $this;
135  $clone->member_records[$record[self::FIELD_USR_ID]] = $record;
136  return $clone;
137  }
138  throw new ilIndividualAssessmentException('illdefined record');
139  }
140 
148  public function withAdditionalUser(ilObjUser $usr) {
149  if(!$this->userAllreadyMember($usr)) {
150  $clone = clone $this;
151  $clone->member_records[$usr->getId()] = $this->buildNewRecordOfUser($usr);
152  return $clone;
153  }
154  throw new ilIndividualAssessmentException('User allready member');
155  }
156 
157  protected function buildNewRecordOfUser(ilObjUser $usr) {
158  return array(
159  self::FIELD_USR_ID => $usr->getId()
160  , self::FIELD_RECORD => $this->iass->getSettings()->recordTemplate()
161  , self::FIELD_NOTIFY => 0
162  , self::FIELD_FIRSTNAME => $usr->getFirstname()
163  , self::FIELD_LASTNAME => $usr->getLastname()
164  , self::FIELD_LOGIN => $usr->getLogin()
165  , self::FIELD_LEARNING_PROGRESS => self::LP_NOT_ATTEMPTED
166  , self::FIELD_EXAMINER_ID => null
167  , self::FIELD_EXAMINER_FIRSTNAME => null
168  , self::FIELD_EXAMINER_LASTNAME => null
169  , self::FIELD_INTERNAL_NOTE => null
170  , self::FIELD_FINALIZED => 0
171  );
172  }
173 
181  public function withoutPresentUser(ilObjUser $usr) {
182  $usr_id = $usr->getId();
183  if(isset($this->member_records[$usr_id]) && (string)$this->member_records[$usr_id][self::FIELD_FINALIZED] !== "1") {
184  $clone = clone $this;
185  unset($clone->member_records[$usr->getId()]);
186  return $clone;
187  }
188  throw new ilIndividualAssessmentException('User not member or allready finished');
189  }
190 
191 
197  public function membersIds() {
198  return array_keys($this->member_records);
199  }
200 
208  $current = $storage->loadMembers($this->referencedObject());
209  $iass = $this->referencedObject();
210  foreach($this as $usr_id => $record) {
211  if(!$current->userAllreadyMemberByUsrId($usr_id)) {
212  $storage->insertMembersRecord($this->referencedObject(),$record);
213  $access_handler->assignUserToMemberRole(new ilObjUser($usr_id),$iass);
214  }
215  }
216  foreach($current as $usr_id => $record) {
217  if(!$this->userAllreadyMemberByUsrId($usr_id)) {
218  $storage->removeMembersRecord($this->referencedObject(),$record);
219  $access_handler->deassignUserFromMemberRole(new ilObjUser($usr_id),$iass);
220  }
221  }
222  }
223 }
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
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. ...
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.
Create styles array
The data for the language used.
const LP_STATUS_NOT_ATTEMPTED_NUM
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.
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.
const LP_STATUS_FAILED_NUM