ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilIndividualAssessmentMembersTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
31{
33 protected ilLanguage $lng;
34 protected ilCtrl $ctrl;
36 protected Factory $factory;
38 protected int $current_user_id;
41 protected array $data = [];
42
43 public function __construct(
52 ) {
53 $this->parent = $parent;
54 $this->lng = $lng;
55 $this->ctrl = $ctrl;
56 $this->iass_access = $iass_access;
57 $this->factory = $factory;
58 $this->renderer = $renderer;
59 $this->current_user_id = $current_user->getId();
60 $this->current_user = $current_user;
61 $this->date_formatter = $date_formatter;
62 }
63
67 public function setData(array $data): void
68 {
69 $this->data = array_filter(
70 $data,
71 fn($record) =>
72 $this->iass_access->mayEditMembers()
73 || $this->iass_access->mayGradeUser($record->id())
74 || $this->iass_access->mayViewUser($record->id())
75 );
76 }
77
83 public function render(array $view_constrols, int $offset = 0, ?int $limit = null): string
84 {
85 $ptable = $this->factory->table()->presentation(
86 "",
87 $view_constrols,
88 function (
89 PresentationRow $row,
91 Factory $ui,
92 $environment
93 ) {
94 return $row
95 ->withHeadline($this->getHeadline($record))
96 ->withSubheadline($this->getSubheadline($record))
97 ->withImportantFields($this->getImportantInfos($record))
98 ->withContent($ui->listing()->descriptive($this->getContent($record)))
99 ->withFurtherFieldsHeadline($this->txt("iass_further_field_headline"))
100 ->withFurtherFields($this->getFurtherFields($record))
101 ->withAction($this->getAction($record, $ui));
102 }
103 );
104
105 $data = array_slice($this->data, $offset, $limit);
106 return $this->renderer->render($ptable->withData($data));
107 }
108
112 protected function getHeadline(ilIndividualAssessmentMember $record): string
113 {
114 return $record->lastname() . ", " . $record->firstname() . " [" . $record->login() . "]";
115 }
116
120 protected function getSubheadline(ilIndividualAssessmentMember $record): string
121 {
122 if (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id())) {
123 return "";
124 }
125
126 $examiner_id = $record->examinerId();
127 return $this->txt("grading") . ": " . $this->getStatus($record->finalized(), $record->LPStatus(), $examiner_id);
128 }
129
135 protected function getImportantInfos(ilIndividualAssessmentMember $record, bool $finalized_only = true): array
136 {
137 if (
138 (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id()))
139 ||
140 (!$record->finalized() && $finalized_only)
141 ) {
142 return [];
143 }
144
145 return array_merge(
146 $this->getGradedInformation($record->eventTime()),
147 $this->getGradedByInformation($record->examinerId()),
148 $this->getChangedByInformation($record->changerId(), $record->changeTime())
149 );
150 }
151
152 protected function getGradedByInformation(?int $graded_by_id): array
153 {
154 if (is_null($graded_by_id)) {
155 return [];
156 }
157
158 if (!ilObjUser::userExists([$graded_by_id])) {
159 return [$this->txt('iass_graded_by') => $this->txt("user_deleted")];
160 }
161
162 $full_name = $this->getFullNameFor($graded_by_id);
163 if (!$this->hasPublicProfile($graded_by_id)) {
164 return [$this->txt('iass_graded_by') => $full_name];
165 }
166
167 return [
168 $this->txt('iass_graded_by') => $this->getProfileLink($full_name, $graded_by_id)
169 ];
170 }
171
172 protected function getChangedByInformation(?int $changed_by_id, ?DateTimeImmutable $change_date): array
173 {
174 if (is_null($changed_by_id)) {
175 return [];
176 }
177
178 $changed_date_str = "";
179 if (!is_null($change_date)) {
180 $changed_date_str = $this->date_formatter->format($this->current_user, $change_date);
181 }
182
183 $full_name = $this->getFullNameFor($changed_by_id);
184 if (!$this->hasPublicProfile($changed_by_id)) {
185 return [$this->txt('iass_changed_by') => $full_name . ' ' . $changed_date_str];
186 }
187
188 return [
189 $this->txt('iass_changed_by') => $this->getProfileLink($full_name, $changed_by_id) . ' ' . $changed_date_str
190 ];
191 }
192
198 protected function getContent(ilIndividualAssessmentMember $record): array
199 {
200 $examiner_id = $record->examinerId();
201 if (
202 !$this->checkEditable($record->finalized(), $record->id(), $examiner_id)
203 && !$this->checkAmendable($record->finalized())
204 && !$this->iass_access->mayViewUser($record->id())
205 && !$this->iass_access->mayGradeUser($record->id())
206 ) {
207 return [];
208 }
209
210 $usr_id = $record->id();
211
212 if (
213 !$this->iass_access->mayViewUser($usr_id)
214 && !$record->finalized()
215 && $examiner_id !== $this->current_user_id
216 ) {
217 return [];
218 }
219
220 $file_name = $record->fileName();
221
222 return array_merge(
223 $this->getRecordNote($record->record()),
224 $this->getInternalRecordNote($record->internalNote()),
225 $this->checkDownloadFile($usr_id, $file_name)
226 ? $this->getFileDownloadLink($usr_id)
227 : []
228 );
229 }
230
236 protected function getFurtherFields(ilIndividualAssessmentMember $record): array
237 {
238 if (!$this->iass_access->mayViewUser($record->id()) && !$this->iass_access->mayGradeUser($record->id())) {
239 return [];
240 }
241
242 return array_merge(
243 $record->LPStatus() ? [$this->txt("grading") . ":" => $this->getEntryForStatus($record->LPStatus())] : [],
244 $this->getImportantInfos($record, false),
245 $this->getLocationInfos(
246 $record->finalized(),
247 $record->id(),
248 $record->place(),
249 $record->examinerId()
250 )
251 );
252 }
253
257 protected function getAction(ilIndividualAssessmentMember $record, Factory $ui_factory): Dropdown
258 {
259 $items = [];
260
261 $examiner_id = $record->examinerId();
262 $usr_id = $record->id();
263 $finalized = $record->finalized();
264 $file_name = $record->fileName();
265
266 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
267
268 if ($this->checkEditable($finalized, $usr_id, $examiner_id)) {
269 $target = $this->ctrl->getLinkTargetByClass(ilIndividualAssessmentMemberGUI::class, 'edit');
270 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_edit'), $target);
271 }
272
273 if ($this->checkUserRemoveable($finalized)) {
274 $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', $usr_id);
275 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMembersGUI', 'removeUserConfirmation');
276 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_remove'), $target);
277 $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', null);
278 }
279
280 if ($this->checkAmendable($finalized)) {
281 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'amend');
282 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_amend'), $target);
283 }
284
285 if ($this->checkDownloadFile($usr_id, $file_name)) {
286 $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'downloadFile');
287 $items[] = $ui_factory->button()->shy($this->txt('iass_usr_download_attachment'), $target);
288 }
289 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
290
291 return $ui_factory->dropdown()->standard($items)->withLabel($this->txt("actions"));
292 }
293
297 protected function getStatus(bool $finalized, int $status, ?int $examiner_id = null): string
298 {
299 if ($status == 0) {
301 }
302
303 if (!$finalized && !is_null($examiner_id)) {
304 return $this->txt('iass_assessment_not_completed');
305 }
306
307 return $this->getEntryForStatus($status);
308 }
309
315 protected function getGradedInformation(?DateTimeImmutable $event_time): array
316 {
317 if (is_null($event_time)) {
318 return [];
319 }
320 $event_time_str = $this->date_formatter->format($this->current_user, $event_time, true);
321 return [$this->txt("iass_event_time") => $event_time_str];
322 }
323
327 protected function getFullNameFor(?int $user_id = null): string
328 {
329 if (is_null($user_id)) {
330 return "";
331 }
332
333 $name_fields = ilObjUser::_lookupName($user_id);
334 return $name_fields["lastname"] . ", " . $name_fields["firstname"] . " [" . $name_fields["login"] . "]";
335 }
336
337 protected function getProfileLink(string $full_name, int $user_id): string
338 {
339 $back_url = $this->ctrl->getLinkTarget($this->parent, "view");
340 $this->ctrl->setParameterByClass(PublicProfileGUI::class, 'user_id', $user_id);
341 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "back_url", rawurlencode($back_url));
342 $link = $this->ctrl->getLinkTargetByClass(
343 [ilPublicProfileBaseClassGUI::class, PublicProfileGUI::class],
344 'getHTML'
345 );
346 $link = $this->factory->link()->standard($full_name, $link);
347
348 return $this->renderer->render($link);
349 }
350
351 protected function hasPublicProfile(int $examiner_id): bool
352 {
353 $user = ilObjectFactory::getInstanceByObjId($examiner_id);
354 return (
355 ($user->getPref('public_profile') == 'y') ||
356 $user->getPref('public_profile') == 'g'
357 );
358 }
359
365 protected function getLocationInfos(
366 bool $finalized,
367 int $usr_id,
368 ?string $location = null,
369 ?int $examiner_id = null
370 ): array {
371 if (!$this->mayViewLocation($finalized, $usr_id, $examiner_id)) {
372 return [];
373 }
374
375 if ($location === "" || is_null($location)) {
376 return [];
377 }
378
379 return [$this->txt("iass_location") . ": " => $location];
380 }
381
387 protected function getRecordNote(string $record_note): array
388 {
389 if (is_null($record_note)) {
390 return [];
391 }
392
393 return [$this->txt("iass_record") => $record_note];
394 }
395
401 protected function getInternalRecordNote(?string $internal_note = null): array
402 {
403 if (is_null($internal_note)) {
404 return [];
405 }
406
407 return [$this->txt("iass_internal_note") => $internal_note];
408 }
409
413 protected function getFileDownloadLink(int $usr_id): array
414 {
415 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
416 $target = $this->ctrl->getLinkTargetByClass(
417 'ilIndividualAssessmentMemberGUI',
419 );
420 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
421 $link = $this->factory->link()->standard($this->txt("iass_download"), $target);
422
423 return array(
424 $this->txt("iass_file") => $this->renderer->render($link)
425 );
426 }
427
431 protected function getEntryForStatus(int $a_status): string
432 {
433 switch ($a_status) {
435 return $this->txt('iass_status_pending');
437 return $this->txt('iass_status_completed');
439 return $this->txt('iass_status_failed');
440 default:
441 throw new ilIndividualAssessmentException("Invalid status: " . $a_status);
442 }
443 }
444
448 protected function mayViewLocation(bool $finalized, int $usr_id, ?int $examiner_id = null): bool
449 {
450 return
451 $this->checkEditable($finalized, $usr_id, $examiner_id) ||
452 $this->checkAmendable($finalized) ||
453 $this->iass_access->mayViewUser($usr_id)
454 ;
455 }
456
460 protected function checkEditable(bool $finalized, int $usr_id, ?int $examiner_id = null): bool
461 {
462 if ($finalized) {
463 return false;
464 }
465
466 return
467 (
468 $this->iass_access->mayGradeUser($usr_id)
469 &&
470 $this->wasEditedByViewer($examiner_id)
471 );
472 }
473
477 protected function checkAmendable(bool $finalized): bool
478 {
479 if (
480 ($this->iass_access->isSystemAdmin() && $finalized) ||
481 ($finalized && $this->iass_access->mayAmendAllUsers())
482 ) {
483 return true;
484 }
485
486 return false;
487 }
488
492 protected function checkUserRemoveable(bool $finalized): bool
493 {
494 if (($this->iass_access->isSystemAdmin() && !$finalized) || (!$finalized && $this->iass_access->mayEditMembers())) {
495 return true;
496 }
497
498 return false;
499 }
500
504 protected function checkDownloadFile(int $usr_id, ?string $file_name = null): bool
505 {
506 if ((!is_null($file_name) && $file_name !== '')
507 && ($this->iass_access->isSystemAdmin() || $this->userMayDownloadAttachment($usr_id))
508 ) {
509 return true;
510 }
511
512 return false;
513 }
514
515 protected function userMayDownloadAttachment(int $usr_id): bool
516 {
517 return $this->iass_access->mayViewUser($usr_id) || $this->iass_access->mayGradeUser($usr_id);
518 }
519
520 protected function wasEditedByViewer(?int $examiner_id = null): bool
521 {
522 return $examiner_id === $this->current_user_id || null === $examiner_id;
523 }
524
525 protected function txt(string $code): string
526 {
527 return $this->lng->txt($code);
528 }
529}
renderer()
factory()
$location
Definition: buildRTE.php:22
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
Edit the record of a user, set LP.
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.
render(array $view_constrols, int $offset=0, ?int $limit=null)
Renders the presentation table.
getLocationInfos(bool $finalized, int $usr_id, ?string $location=null, ?int $examiner_id=null)
Returns the location of assessment.
getContent(ilIndividualAssessmentMember $record)
Return all content elements for each row.
mayViewLocation(bool $finalized, int $usr_id, ?int $examiner_id=null)
Check user may view the location.
__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.
checkDownloadFile(int $usr_id, ?string $file_name=null)
Check the current user is allowed to download the record file.
getChangedByInformation(?int $changed_by_id, ?DateTimeImmutable $change_date)
getAction(ilIndividualAssessmentMember $record, Factory $ui_factory)
Return the ui control with executable actions.
getStatus(bool $finalized, int $status, ?int $examiner_id=null)
Returns readable status.
getFullNameFor(?int $user_id=null)
Returns login of examiner.
getSubheadline(ilIndividualAssessmentMember $record)
Returns the sub headline for each row.
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.
getRecordNote(string $record_note)
Returns information out of record note.
checkEditable(bool $finalized, int $usr_id, ?int $examiner_id=null)
Check the current user has edit permission on record.
getInternalRecordNote(?string $internal_note=null)
Returns information out of internal record note.
language handling
User class.
static userExists(array $a_usr_ids=[])
static _lookupName(int $a_user_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
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
Mechanic regarding the access control and roles of an objet goes here.
if(!file_exists('../ilias.ini.php'))