ILIAS  release_8 Revision v8.24
class.ilIndividualAssessmentMembersTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25
30{
32 protected ilLanguage $lng;
33 protected ilCtrl $ctrl;
35 protected Factory $factory;
37 protected int $current_user_id;
40 protected array $data = [];
41
42 public function __construct(
51 ) {
52 $this->parent = $parent;
53 $this->lng = $lng;
54 $this->ctrl = $ctrl;
55 $this->iass_access = $iass_access;
56 $this->factory = $factory;
57 $this->renderer = $renderer;
58 $this->current_user_id = $current_user->getId();
59 $this->current_user = $current_user;
60 $this->date_formatter = $date_formatter;
61 }
62
66 public function setData(array $data): void
67 {
68 $this->data = array_filter(
69 $data,
70 fn ($record) =>
71 $this->iass_access->mayEditMembers()
72 || $this->iass_access->mayGradeUser($record->id())
73 || $this->iass_access->mayViewUser($record->id())
74 );
75 }
76
82 public function render(array $view_constrols, int $offset = 0, int $limit = null): string
83 {
84 $ptable = $this->factory->table()->presentation(
85 "",
86 $view_constrols,
87 function (
88 PresentationRow $row,
90 Factory $ui,
91 $environment
92 ) {
93 return $row
94 ->withHeadline($this->getHeadline($record))
95 ->withSubheadline($this->getSubheadline($record))
96 ->withImportantFields($this->getImportantInfos($record))
97 ->withContent($ui->listing()->descriptive($this->getContent($record)))
98 ->withFurtherFieldsHeadline($this->txt("iass_further_field_headline"))
99 ->withFurtherFields($this->getFurtherFields($record))
100 ->withAction($this->getAction($record, $ui));
101 }
102 );
103
104 $data = array_slice($this->data, $offset, $limit);
105 return $this->renderer->render($ptable->withData($data));
106 }
107
111 protected function getHeadline(ilIndividualAssessmentMember $record): string
112 {
113 return $record->lastname() . ", " . $record->firstname() . " [" . $record->login() . "]";
114 }
115
119 protected function getSubheadline(ilIndividualAssessmentMember $record): string
120 {
121 if (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id())) {
122 return "";
123 }
124
125 $examiner_id = $record->examinerId();
126 return $this->txt("grading") . ": " . $this->getStatus($record->finalized(), $record->LPStatus(), $examiner_id);
127 }
128
134 protected function getImportantInfos(ilIndividualAssessmentMember $record, bool $finalized_only = true): array
135 {
136 if (
137 (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id()))
138 ||
139 (!$record->finalized() && $finalized_only)
140 ) {
141 return [];
142 }
143
144 return array_merge(
145 $this->getGradedInformation($record->eventTime()),
146 $this->getGradedByInformation($record->examinerId()),
147 $this->getChangedByInformation($record->changerId(), $record->changeTime())
148 );
149 }
150
151 protected function getGradedByInformation(?int $graded_by_id): array
152 {
153 if (is_null($graded_by_id)) {
154 return [];
155 }
156
157 if (!ilObjUser::userExists([$graded_by_id])) {
158 return [$this->txt('iass_graded_by') . ":" => $this->txt("user_deleted")];
159 }
160
161 $full_name = $this->getFullNameFor($graded_by_id);
162 if (!$this->hasPublicProfile($graded_by_id)) {
163 return [$this->txt('iass_graded_by') . ":" => $full_name];
164 }
165
166 return [
167 $this->txt('iass_graded_by') . ":" => $this->getProfileLink($full_name, $graded_by_id)
168 ];
169 }
170
171 protected function getChangedByInformation(?int $changed_by_id, ?DateTimeImmutable $change_date): array
172 {
173 if (is_null($changed_by_id)) {
174 return [];
175 }
176
177 $changed_date_str = "";
178 if (!is_null($change_date)) {
179 $changed_date_str = $this->date_formatter->format($this->current_user, $change_date);
180 }
181
182 $full_name = $this->getFullNameFor($changed_by_id);
183 if (!$this->hasPublicProfile($changed_by_id)) {
184 return [$this->txt('iass_changed_by') => $full_name . ' ' . $changed_date_str];
185 }
186
187 return [
188 $this->txt('iass_changed_by') => $this->getProfileLink($full_name, $changed_by_id) . ' ' . $changed_date_str
189 ];
190 }
191
197 protected function getContent(ilIndividualAssessmentMember $record): array
198 {
199 $examiner_id = $record->examinerId();
200 if (
201 !$this->checkEditable($record->finalized(), $record->id(), $examiner_id)
202 && !$this->checkAmendable($record->finalized())
203 && !$this->iass_access->mayViewUser($record->id())
204 && !$this->iass_access->mayGradeUser($record->id())
205 ) {
206 return [];
207 }
208
209 $usr_id = $record->id();
210
211 if (
212 !$this->iass_access->mayViewUser($usr_id)
213 && !$record->finalized()
214 && $examiner_id !== $this->current_user_id
215 ) {
216 return [];
217 }
218
219 $file_name = $record->fileName();
220
221 return array_merge(
222 $this->getRecordNote($record->record()),
223 $this->getInternalRecordNote($record->internalNote()),
224 $this->checkDownloadFile($usr_id, $file_name)
225 ? $this->getFileDownloadLink($usr_id)
226 : []
227 );
228 }
229
235 protected function getFurtherFields(ilIndividualAssessmentMember $record): array
236 {
237 if (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id())) {
238 return [];
239 }
240
241 return array_merge(
242 $record->LPStatus() ? [$this->txt("grading") . ":" => $this->getEntryForStatus($record->LPStatus())] : [],
243 $this->getImportantInfos($record, false),
244 $this->getLocationInfos(
245 $record->finalized(),
246 $record->id(),
247 $record->place(),
248 $record->examinerId()
249 )
250 );
251 }
252
256 protected function getAction(ilIndividualAssessmentMember $record, Factory $ui_factory): Dropdown
257 {
258 $items = [];
259
260 $examiner_id = $record->examinerId();
261 $usr_id = $record->id();
262 $finalized = $record->finalized();
263 $file_name = $record->fileName();
264
265 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
266
267 if ($this->checkEditable($finalized, $usr_id, $examiner_id)) {
268 $target = $this->ctrl->getLinkTargetByClass(ilIndividualAssessmentMemberGUI::class, 'edit');
269 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_edit'), $target);
270 }
271
272 if ($this->checkUserRemoveable($finalized)) {
273 $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', $usr_id);
274 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMembersGUI', 'removeUserConfirmation');
275 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_remove'), $target);
276 $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', null);
277 }
278
279 if ($this->checkAmendable($finalized)) {
280 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'amend');
281 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_amend'), $target);
282 }
283
284 if ($this->checkDownloadFile($usr_id, $file_name)) {
285 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'downloadFile');
286 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_download_attachment'), $target);
287 }
288 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
289
290 return $ui_factory->dropdown()->standard($items)->withLabel($this->txt("actions"));
291 }
292
296 protected function getStatus(bool $finalized, int $status, int $examiner_id = null): string
297 {
298 if ($status == 0) {
300 }
301
302 if (!$finalized && !is_null($examiner_id)) {
303 return $this->txt('iass_assessment_not_completed');
304 }
305
306 return $this->getEntryForStatus($status);
307 }
308
314 protected function getGradedInformation(?DateTimeImmutable $event_time): array
315 {
316 if (is_null($event_time)) {
317 return [];
318 }
319 $event_time_str = $this->date_formatter->format($this->current_user, $event_time, true);
320 return [$this->txt("iass_event_time") . ": " => $event_time_str];
321 }
322
326 protected function getFullNameFor(int $user_id = null): string
327 {
328 if (is_null($user_id)) {
329 return "";
330 }
331
332 $name_fields = ilObjUser::_lookupName($user_id);
333 return $name_fields["lastname"] . ", " . $name_fields["firstname"] . " [" . $name_fields["login"] . "]";
334 }
335
336 protected function getProfileLink(string $full_name, int $user_id): string
337 {
338 $back_url = $this->ctrl->getLinkTarget($this->parent, "view");
339 $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user_id', $user_id);
340 $this->ctrl->setParameterByClass('ilpublicuserprofilegui', "back_url", rawurlencode($back_url));
341 $link = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
342 $link = $this->factory->link()->standard($full_name, $link);
343
344 return $this->renderer->render($link);
345 }
346
347 protected function hasPublicProfile(int $examiner_id): bool
348 {
349 $user = ilObjectFactory::getInstanceByObjId($examiner_id);
350 return (
351 ($user->getPref('public_profile') == 'y') ||
352 $user->getPref('public_profile') == 'g'
353 );
354 }
355
361 protected function getLocationInfos(
362 bool $finalized,
363 int $usr_id,
364 string $location = null,
365 int $examiner_id = null
366 ): array {
367 if (!$this->mayViewLocation($finalized, $usr_id, $examiner_id)) {
368 return [];
369 }
370
371 if ($location === "" || is_null($location)) {
372 return [];
373 }
374
375 return [$this->txt("iass_location") . ": " => $location];
376 }
377
383 protected function getRecordNote(string $record_note): array
384 {
385 if (is_null($record_note)) {
386 return [];
387 }
388
389 return [$this->txt("iass_record") => $record_note];
390 }
391
397 protected function getInternalRecordNote(string $internal_note = null): array
398 {
399 if (is_null($internal_note)) {
400 return [];
401 }
402
403 return [$this->txt("iass_internal_note") => $internal_note];
404 }
405
409 protected function getFileDownloadLink(int $usr_id): array
410 {
411 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
412 $target = $this->ctrl->getLinkTargetByClass(
413 'ilIndividualAssessmentMemberGUI',
415 );
416 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
417 $link = $this->factory->link()->standard($this->txt("iass_download"), $target);
418
419 return array(
420 $this->txt("iass_file") => $this->renderer->render($link)
421 );
422 }
423
427 protected function getEntryForStatus(int $a_status): string
428 {
429 switch ($a_status) {
431 return $this->txt('iass_status_pending');
433 return $this->txt('iass_status_completed');
435 return $this->txt('iass_status_failed');
436 default:
437 throw new ilIndividualAssessmentException("Invalid status: " . $a_status);
438 }
439 }
440
444 protected function mayViewLocation(bool $finalized, int $usr_id, int $examiner_id = null): bool
445 {
446 return
447 $this->checkEditable($finalized, $usr_id, $examiner_id) ||
448 $this->checkAmendable($finalized) ||
449 $this->iass_access->mayViewUser($usr_id)
450 ;
451 }
452
456 protected function checkEditable(bool $finalized, int $usr_id, int $examiner_id = null): bool
457 {
458 if ($finalized) {
459 return false;
460 }
461
462 return
463 (
464 $this->iass_access->mayGradeUser($usr_id)
465 &&
466 $this->wasEditedByViewer($examiner_id)
467 );
468 }
469
473 protected function checkAmendable(bool $finalized): bool
474 {
475 if (
476 ($this->iass_access->isSystemAdmin() && $finalized) ||
477 ($finalized && $this->iass_access->mayAmendAllUsers())
478 ) {
479 return true;
480 }
481
482 return false;
483 }
484
488 protected function checkUserRemoveable(bool $finalized): bool
489 {
490 if (($this->iass_access->isSystemAdmin() && !$finalized) || (!$finalized && $this->iass_access->mayEditMembers())) {
491 return true;
492 }
493
494 return false;
495 }
496
500 protected function checkDownloadFile(int $usr_id, string $file_name = null): bool
501 {
502 if ((!is_null($file_name) && $file_name !== '')
503 && ($this->iass_access->isSystemAdmin() || $this->userMayDownloadAttachment($usr_id))
504 ) {
505 return true;
506 }
507
508 return false;
509 }
510
511 protected function userMayDownloadAttachment(int $usr_id): bool
512 {
513 return $this->iass_access->mayViewUser($usr_id) || $this->iass_access->mayGradeUser($usr_id);
514 }
515
516 protected function wasEditedByViewer(int $examiner_id = null): bool
517 {
518 return $examiner_id === $this->current_user_id || null === $examiner_id;
519 }
520
521 protected function txt(string $code): string
522 {
523 return $this->lng->txt($code);
524 }
525}
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
Class ilCtrl provides processing control methods.
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...
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
checkAmendable(bool $finalized)
Check the current user has amended permission on record.
checkDownloadFile(int $usr_id, string $file_name=null)
Check the current user is allowed to download the record file.
getContent(ilIndividualAssessmentMember $record)
Return all content elements for each row.
__construct(ilIndividualAssessmentMembersGUI $parent, ilLanguage $lng, ilCtrl $ctrl, IndividualAssessmentAccessHandler $iass_access, Factory $factory, Renderer $renderer, ilObjUser $current_user, ilIndividualAssessmentDateFormatter $date_formatter)
getGradedInformation(?DateTimeImmutable $event_time)
Returns information about the grading.
getChangedByInformation(?int $changed_by_id, ?DateTimeImmutable $change_date)
getAction(ilIndividualAssessmentMember $record, Factory $ui_factory)
Return the ui control with executable actions.
mayViewLocation(bool $finalized, int $usr_id, int $examiner_id=null)
Check user may view the location.
getFullNameFor(int $user_id=null)
Returns login of examiner.
getLocationInfos(bool $finalized, int $usr_id, string $location=null, int $examiner_id=null)
Returns the location of assessment.
getSubheadline(ilIndividualAssessmentMember $record)
Returns the sub headline for each row.
render(array $view_constrols, int $offset=0, int $limit=null)
Renders the presentation table.
checkEditable(bool $finalized, int $usr_id, int $examiner_id=null)
Check the current user has edit permission on record.
checkUserRemoveable(bool $finalized)
Check the current user is allowed to remove the user.
getHeadline(ilIndividualAssessmentMember $record)
Returns the headline for each row.
getFurtherFields(ilIndividualAssessmentMember $record)
Returns all information needed for further information for each row.
getImportantInfos(ilIndividualAssessmentMember $record, bool $finalized_only=true)
Returns all information needed for important row.
getFileDownloadLink(int $usr_id)
Get the link for download of file.
getInternalRecordNote(string $internal_note=null)
Returns information out of internal record note.
getRecordNote(string $record_note)
Returns information out of record note.
getStatus(bool $finalized, int $status, int $examiner_id=null)
Returns readable status.
language handling
User class.
static _lookupName(int $a_user_id)
lookup user name
static userExists(array $a_usr_ids=array())
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:35
This describes a Row used in Presentation Table.
withHeadline(string $headline)
Get a row like this with the given headline.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...