ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIndividualAssessmentMembers.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
27  public const FIELD_FIRSTNAME = 'firstname';
28  public const FIELD_LASTNAME = 'lastname';
29  public const FIELD_LOGIN = 'login';
30  public const FIELD_USR_ID = 'usr_id';
31  public const FIELD_LEARNING_PROGRESS = 'learning_progress';
32  public const FIELD_EXAMINER_ID = 'examiner_id';
33  public const FIELD_EXAMINER_FIRSTNAME = 'examiner_firstname';
34  public const FIELD_EXAMINER_LASTNAME = 'examiner_lastname';
35  public const FIELD_CHANGER_ID = "changer_id";
36  public const FIELD_CHANGER_FIRSTNAME = "changer_firstname";
37  public const FIELD_CHANGER_LASTNAME = "changer_lastname";
38  public const FIELD_CHANGE_TIME = "change_time";
39  public const FIELD_RECORD = 'record';
40  public const FIELD_INTERNAL_NOTE = 'internal_note';
41  public const FIELD_NOTIFY = 'notify';
42  public const FIELD_FINALIZED = 'finalized';
43  public const FIELD_NOTIFICATION_TS = 'notification_ts';
44  public const FIELD_PLACE = "place";
45  public const FIELD_EVENTTIME = "event_time";
46  public const FIELD_FILE_NAME = "file_name";
47  public const FIELD_USER_VIEW_FILE = "user_view_file";
48 
53  public const LP_ASSESSMENT_NOT_COMPLETED = "not_completed";
54 
55  protected array $member_records = array();
56  protected int $position = 0;
58 
59  public function __construct(ilObjIndividualAssessment $iass)
60  {
61  $this->iass = $iass;
62  }
63 
67  public function count(): int
68  {
69  return count($this->member_records);
70  }
71 
76  public function current()
77  {
78  return current($this->member_records);
79  }
80 
84  public function key()
85  {
86  return key($this->member_records);
87  }
88 
89  public function next(): void
90  {
91  $this->position++;
92  next($this->member_records);
93  }
94 
95  public function rewind(): void
96  {
97  $this->position = 0;
98  reset($this->member_records);
99  }
100 
101  public function valid(): bool
102  {
103  return $this->position < count($this->member_records);
104  }
105 
110  {
111  return $this->iass;
112  }
113 
120  public function recordOK(array $record): bool
121  {
122  if (isset($record[self::FIELD_USR_ID])) {
123  if (
124  !$this->userExists((int) $record[self::FIELD_USR_ID]) ||
125  $this->userAllreadyMemberByUsrId($record[self::FIELD_USR_ID])
126  ) {
127  return false;
128  }
129  }
130  if (!in_array(
131  $record[self::FIELD_LEARNING_PROGRESS],
132  array(self::LP_NOT_ATTEMPTED, self::LP_FAILED, self::LP_COMPLETED, self::LP_IN_PROGRESS)
133  )
134  ) {
135  return false;
136  }
137  return true;
138  }
139 
146  public function userAllreadyMemberByUsrId($usr_id): bool
147  {
148  return isset($this->member_records[$usr_id]);
149  }
150 
154  public function userAllreadyMember(ilObjUser $usr): bool
155  {
156  return $this->userAllreadyMemberByUsrId($usr->getId());
157  }
158 
159  protected function userExists(int $usr_id): bool
160  {
161  return ilObjUser::_exists($usr_id, false, 'usr');
162  }
163 
169  public function withAdditionalRecord(array $record): ilIndividualAssessmentMembers
170  {
171  if ($this->recordOK($record)) {
172  $clone = clone $this;
173  $clone->member_records[$record[self::FIELD_USR_ID]] = $record;
174  return $clone;
175  }
176  throw new ilIndividualAssessmentException('Ill defined record.');
177  }
178 
183  {
184  if (!$this->userAllreadyMember($usr)) {
185  $clone = clone $this;
186  $clone->member_records[$usr->getId()] = $this->buildNewRecordOfUser($usr);
187  return $clone;
188  }
189  throw new ilIndividualAssessmentException('User allready member');
190  }
191 
192  protected function buildNewRecordOfUser(ilObjUser $usr): array
193  {
194  return [
195  self::FIELD_USR_ID => $usr->getId(),
196  self::FIELD_RECORD => $this->iass->getSettings()->getRecordTemplate(),
197  self::FIELD_NOTIFY => 0,
198  self::FIELD_FIRSTNAME => $usr->getFirstname(),
199  self::FIELD_LASTNAME => $usr->getLastname(),
200  self::FIELD_LOGIN => $usr->getLogin(),
201  self::FIELD_LEARNING_PROGRESS => self::LP_NOT_ATTEMPTED,
202  self::FIELD_EXAMINER_ID => null,
203  self::FIELD_EXAMINER_FIRSTNAME => null,
204  self::FIELD_EXAMINER_LASTNAME => null,
205  self::FIELD_INTERNAL_NOTE => null,
206  self::FIELD_FILE_NAME => null,
207  self::FIELD_USER_VIEW_FILE => false,
208  self::FIELD_FINALIZED => 0,
209  self::FIELD_CHANGER_ID => null,
210  self::FIELD_CHANGER_FIRSTNAME => null,
211  self::FIELD_CHANGER_LASTNAME => null
212  ];
213  }
214 
219  {
220  $usr_id = $usr->getId();
221  if (isset($this->member_records[$usr_id]) && (string) $this->member_records[$usr_id][self::FIELD_FINALIZED] !== "1") {
222  $clone = clone $this;
223  unset($clone->member_records[$usr->getId()]);
224  return $clone;
225  }
226  throw new ilIndividualAssessmentException('User not member or allready finished');
227  }
228 
232  public function withOnlyUsersByIds(array $keep_users_ids): ilIndividualAssessmentMembers
233  {
234  $clone = clone $this;
235 
236  $remove = array_diff($this->membersIds(), $keep_users_ids);
237  foreach ($remove as $id) {
238  unset($clone->member_records[$id]);
239  }
240 
241  return $clone;
242  }
243 
248  public function withAccessHandling(
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(): array
268  {
269  return array_keys($this->member_records);
270  }
271 
278  public function updateStorageAndRBAC(
280  IndividualAssessmentAccessHandler $access_handler
281  ): void {
282  $current = $storage->loadMembers($this->referencedObject());
283  $iass = $this->referencedObject();
284  foreach ($this as $usr_id => $record) {
285  if (!$current->userAllreadyMemberByUsrId($usr_id)) {
286  $storage->insertMembersRecord($this->referencedObject(), $record);
287  $access_handler->assignUserToMemberRole(new ilObjUser($usr_id), $iass);
288  }
289  }
290  foreach ($current as $usr_id => $record) {
291  if (!$this->userAllreadyMemberByUsrId($usr_id)) {
292  $storage->removeMembersRecord($this->referencedObject(), $record);
293  $access_handler->deassignUserFromMemberRole(new ilObjUser($usr_id), $iass);
294  }
295  }
296  }
297 }
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
referencedObject()
Get the Individual assessment object that is corresponding to this.
const LP_STATUS_IN_PROGRESS_NUM
withAdditionalRecord(array $record)
Clone this and add a record.
removeMembersRecord(ilObjIndividualAssessment $iass, array $record)
Remove a membership associated with a IndividualAssessment object inside storage. ...
Interface ilOrgUnitPositionAndRBACAccessHandler Provides access checks due to a users OrgUnit-Positio...
recordOK(array $record)
Check the validity of a record before adding it to this.
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...
withoutPresentUser(ilObjUser $usr)
Clone this and remove record corresponding to user.
filterUserIdsByRbacOrPositionOfCurrentUser(string $rbac_perm, string $pos_perm, int $ref_id, array $user_ids)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
insertMembersRecord(ilObjIndividualAssessment $iass, array $record)
Create a membership inside storage.
withOnlyUsersByIds(array $keep_users_ids)
Remove all users that do not exist in list of given ids.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withAdditionalUser(ilObjUser $usr)
Clone this and add a record created for user.
updateStorageAndRBAC(ilIndividualAssessmentMembersStorage $storage, IndividualAssessmentAccessHandler $access_handler)
Store the data to a persistent medium.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
loadMembers(ilObjIndividualAssessment $obj)
Get ilIndividualAssessmentMembers-object containing member info associated with $obj.
userAllreadyMemberByUsrId($usr_id)
Check if a user with user_id is member of this.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
membersIds()
Get the ids of all the users being member in this iass.
const LP_STATUS_FAILED_NUM