ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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(PublicProfileGUI::class, 'getHTML');
343 $link = $this->factory->link()->standard($full_name, $link);
344
345 return $this->renderer->render($link);
346 }
347
348 protected function hasPublicProfile(int $examiner_id): bool
349 {
350 $user = ilObjectFactory::getInstanceByObjId($examiner_id);
351 return (
352 ($user->getPref('public_profile') == 'y') ||
353 $user->getPref('public_profile') == 'g'
354 );
355 }
356
362 protected function getLocationInfos(
363 bool $finalized,
364 int $usr_id,
365 ?string $location = null,
366 ?int $examiner_id = null
367 ): array {
368 if (!$this->mayViewLocation($finalized, $usr_id, $examiner_id)) {
369 return [];
370 }
371
372 if ($location === "" || is_null($location)) {
373 return [];
374 }
375
376 return [$this->txt("iass_location") . ": " => $location];
377 }
378
384 protected function getRecordNote(string $record_note): array
385 {
386 if (is_null($record_note)) {
387 return [];
388 }
389
390 return [$this->txt("iass_record") => $record_note];
391 }
392
398 protected function getInternalRecordNote(?string $internal_note = null): array
399 {
400 if (is_null($internal_note)) {
401 return [];
402 }
403
404 return [$this->txt("iass_internal_note") => $internal_note];
405 }
406
410 protected function getFileDownloadLink(int $usr_id): array
411 {
412 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
413 $target = $this->ctrl->getLinkTargetByClass(
414 'ilIndividualAssessmentMemberGUI',
416 );
417 $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
418 $link = $this->factory->link()->standard($this->txt("iass_download"), $target);
419
420 return array(
421 $this->txt("iass_file") => $this->renderer->render($link)
422 );
423 }
424
428 protected function getEntryForStatus(int $a_status): string
429 {
430 switch ($a_status) {
432 return $this->txt('iass_status_pending');
434 return $this->txt('iass_status_completed');
436 return $this->txt('iass_status_failed');
437 default:
438 throw new ilIndividualAssessmentException("Invalid status: " . $a_status);
439 }
440 }
441
445 protected function mayViewLocation(bool $finalized, int $usr_id, ?int $examiner_id = null): bool
446 {
447 return
448 $this->checkEditable($finalized, $usr_id, $examiner_id) ||
449 $this->checkAmendable($finalized) ||
450 $this->iass_access->mayViewUser($usr_id)
451 ;
452 }
453
457 protected function checkEditable(bool $finalized, int $usr_id, ?int $examiner_id = null): bool
458 {
459 if ($finalized) {
460 return false;
461 }
462
463 return
464 (
465 $this->iass_access->mayGradeUser($usr_id)
466 &&
467 $this->wasEditedByViewer($examiner_id)
468 );
469 }
470
474 protected function checkAmendable(bool $finalized): bool
475 {
476 if (
477 ($this->iass_access->isSystemAdmin() && $finalized) ||
478 ($finalized && $this->iass_access->mayAmendAllUsers())
479 ) {
480 return true;
481 }
482
483 return false;
484 }
485
489 protected function checkUserRemoveable(bool $finalized): bool
490 {
491 if (($this->iass_access->isSystemAdmin() && !$finalized) || (!$finalized && $this->iass_access->mayEditMembers())) {
492 return true;
493 }
494
495 return false;
496 }
497
501 protected function checkDownloadFile(int $usr_id, ?string $file_name = null): bool
502 {
503 if ((!is_null($file_name) && $file_name !== '')
504 && ($this->iass_access->isSystemAdmin() || $this->userMayDownloadAttachment($usr_id))
505 ) {
506 return true;
507 }
508
509 return false;
510 }
511
512 protected function userMayDownloadAttachment(int $usr_id): bool
513 {
514 return $this->iass_access->mayViewUser($usr_id) || $this->iass_access->mayGradeUser($usr_id);
515 }
516
517 protected function wasEditedByViewer(?int $examiner_id = null): bool
518 {
519 return $examiner_id === $this->current_user_id || null === $examiner_id;
520 }
521
522 protected function txt(string $code): string
523 {
524 return $this->lng->txt($code);
525 }
526}
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'))