ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIndividualAssessmentMembersTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2017 Denis Klöpfer <denis.kloepfer@concepts-and-training.de> Extended GPL, see ./LICENSE */
3 /* Copyright (c) 2018 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see ./LICENSE */
4 
5 declare(strict_types=1);
6 
7 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembersStorageDB.php';
8 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
9 require_once 'Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
10 require_once 'Services/Tracking/classes/class.ilLPStatus.php';
11 
16 
21 {
22  public function __construct(
25  ilCtrl $ctrl,
28  Renderer $renderer,
29  int $current_user_id
30  ) {
31  $this->parent = $parent;
32  $this->lng = $lng;
33  $this->ctrl = $ctrl;
34  $this->iass_access = $iass_access;
35  $this->factory = $factory;
36  $this->renderer = $renderer;
37  $this->current_user_id = $current_user_id;
38  }
39 
47  public function setData(array $data)
48  {
49  $this->data = $data;
50  }
51 
57  public function render(array $view_constrols, int $offset = 0, int $limit = null) : string
58  {
59  $ptable = $this->factory->table()->presentation(
60  "",
61  $view_constrols,
62  function (
63  PresentationRow $row,
65  Factory $ui_factory,
66  $environment
67  ) {
68  $headline = $this->getHeadline($record);
69  $subheadline = $this->getSubheadline($record);
70  $important_infos = $this->importantInfos($record);
71  $further_fields = $this->getFurtherFields($record);
72  $content = $this->getContent($record);
73  $action = $this->getAction($record, $ui_factory);
74 
75  $row = $row
76  ->withHeadline($headline)
77  ->withSubheadline($subheadline)
78  ->withImportantFields($important_infos)
79  ->withContent($ui_factory->listing()->descriptive($content))
80  ->withFurtherFieldsHeadline($this->txt("iass_further_field_headline"))
81  ->withFurtherFields($further_fields)
82  ->withAction($action);
83 
84  return $row;
85  }
86  );
87 
88  $data = array_slice($this->data, $offset, $limit);
89  return $this->renderer->render($ptable->withData($data));
90  }
91 
95  protected function getHeadline(ilIndividualAssessmentMember $record) : string
96  {
97  return $record->lastname() . ", " . $record->firstname() . " [" . $record->login() . "]";
98  }
99 
103  protected function getSubheadline(ilIndividualAssessmentMember $record) : string
104  {
105  if (!$this->userMayViewGrades() && !$this->userMayEditGrades()) {
106  return "";
107  }
108 
109  $examiner_id = $record->examinerId();
110  return $this->txt("grading") . ": " . $this->getStatus($record->finalized(), $record->LPStatus(), $examiner_id);
111  }
112 
118  protected function importantInfos(ilIndividualAssessmentMember $record) : array
119  {
120  $finalized = $record->finalized();
121 
122  if ((!$this->userMayViewGrades() && !$this->userMayEditGrades()) || !$finalized) {
123  return [];
124  }
125 
126  $dfdf = array_merge(
127  $this->getGradedInformations($record->eventTime()),
128  $this->getGradedByInformation($record->examinerId()),
129  $this->getChangedByInformation($record->changerId(), $record->changeTime())
130  );
131 
132  return $dfdf;
133  }
134 
135  protected function getGradedByInformation(?int $graded_by_id) : array
136  {
137  if (is_null($graded_by_id)) {
138  return [];
139  }
140 
141  $full_name = $this->getFullNameFor($graded_by_id);
142  if (!$this->hasPublicProfile($graded_by_id)) {
143  return [$this->txt('iass_graded_by') => $full_name];
144  }
145 
146  return [
147  $this->txt('iass_graded_by') => $this->getProfileLink($full_name, $graded_by_id)
148  ];
149  }
150 
151  protected function getChangedByInformation(?int $changed_by_id, ?DateTime $change_date) : array
152  {
153  if (is_null($changed_by_id)) {
154  return [];
155  }
156 
157  $changed_date_str = "";
158  if (!is_null($change_date)) {
159  $dt = new ilDate($change_date->format("Y-m-d"), IL_CAL_DATE);
160  $changed_date_str = ilDatePresentation::formatDate($dt);
161  }
162 
163  $full_name = $this->getFullNameFor($changed_by_id);
164  if (!$this->hasPublicProfile($changed_by_id)) {
165  return [$this->txt('iass_changed_by') => $full_name . ' ' . $changed_date_str];
166  }
167 
168  return [
169  $this->txt('iass_changed_by') => $this->getProfileLink($full_name, $changed_by_id) . ' ' . $changed_date_str
170  ];
171  }
172 
178  protected function getContent(ilIndividualAssessmentMember $record) : array
179  {
180  $examiner_id = $record->examinerId();
181  if (
182  !$this->checkEditable($record->finalized(), $examiner_id, (int) $record->id())
183  && !$this->checkAmendable($record->finalized())
184  && !$this->userMayViewGrades()
185  && !$this->userMayEditGrades()
186  ) {
187  return [];
188  }
189 
190  $usr_id = (int) $record->id();
191  $file_name = $record->fileName();
192 
193  return array_merge(
194  $this->getRecordNote($record->record()),
195  $this->getInternalRecordNote($record->internalNote()),
196  $this->checkDownloadFile($usr_id, $file_name)
197  ? $this->getFileDownloadLink($usr_id, $file_name)
198  : []
199  );
200  }
201 
207  protected function getFurtherFields(ilIndividualAssessmentMember $record) : array
208  {
209  if (!$this->userMayViewGrades() && !$this->userMayEditGrades()) {
210  return [];
211  }
212 
213  return array_merge(
214  $this->importantInfos($record),
215  $this->getLocationInfos(
216  $record->place(),
217  $record->finalized(),
218  $record->examinerId(),
219  (int) $record->id()
220  )
221  );
222  }
223 
227  protected function getAction(ilIndividualAssessmentMember $record, $ui_factory) : Dropdown
228  {
229  $items = [];
230 
231  $examiner_id = $record->examinerId();
232  $usr_id = (int) $record->id();
233  $finalized = $record->finalized();
234  $file_name = $record->fileName();
235 
236  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
237 
238  if ($this->checkEditable($finalized, $examiner_id, $usr_id)) {
239  $target = $this->ctrl->getLinkTargetByClass(ilIndividualAssessmentMemberGUI::class, 'edit');
240  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_edit'), $target);
241  }
242 
243  if ($this->checkUserRemoveable($finalized)) {
244  $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', $usr_id);
245  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMembersGUI', 'removeUserConfirmation');
246  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_remove'), $target);
247  $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', null);
248  }
249 
250  if ($this->checkAmendable($finalized)) {
251  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'amend');
252  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_amend'), $target);
253  }
254 
255  if ($this->checkDownloadFile($usr_id, $file_name)) {
256  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'downloadFile');
257  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_download_attachment'), $target);
258  }
259  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
260 
261  $action = $ui_factory->dropdown()->standard($items)->withLabel($this->txt("actions"));
262  return $action;
263  }
264 
268  protected function getStatus(bool $finalized, int $status, int $examiner_id = null) : string
269  {
270  if ($status == 0) {
272  }
273 
274  if (!$finalized && !is_null($examiner_id)) {
275  return $this->txt('iass_assessment_not_completed');
276  }
277 
278  return $this->getEntryForStatus($status);
279  }
280 
286  protected function getGradedInformations(?DateTimeImmutable $event_time) : array
287  {
288  $event_time_str = "";
289  if (!is_null($event_time)) {
290  $dt = new ilDate($event_time->format("Y-m-d"), IL_CAL_DATE);
291  $event_time_str = ilDatePresentation::formatDate($dt);
292  }
293  return array(
294  $this->txt("iass_event_time") . ": " => $event_time_str
295  );
296  }
297 
303  protected function getFullNameFor(int $user_id = null) : string
304  {
305  if (is_null($user_id)) {
306  return "";
307  }
308 
309  $name_fields = ilObjUser::_lookupName($user_id);
310  $name = $name_fields["lastname"] . ", " . $name_fields["firstname"] . " [" . $name_fields["login"] . "]";
311 
312  return $name;
313  }
314 
315  protected function getProfileLink(string $full_name, int $user_id)
316  {
317  $back_url = $this->ctrl->getLinkTarget($this->parent, "view");
318  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user_id', $user_id);
319  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', "back_url", rawurlencode($back_url));
320  $link = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
321  $link = $this->factory->link()->standard($full_name, $link);
322 
323  return $this->renderer->render($link);
324  }
325 
326  protected function hasPublicProfile(int $examiner_id) : bool
327  {
328  $user = ilObjectFactory::getInstanceByObjId($examiner_id);
329  return (
330  ($user->getPref('public_profile') == 'y') ||
331  $user->getPref('public_profile') == 'g'
332  );
333  }
334 
340  protected function getLocationInfos(
341  string $location = null,
342  bool $finalized,
343  int $examiner_id = null,
344  int $usr_id
345  ) : array {
346  if (!$this->viewLocation($finalized, $examiner_id, $usr_id)) {
347  return array();
348  }
349 
350  if ($location == "" || is_null($location)) {
351  $location = $this->txt("none");
352  }
353 
354  return array(
355  $this->txt("iass_location") . ": " => $location
356  );
357  }
358 
364  protected function getRecordNote(string $record_note) : array
365  {
366  return array(
367  $this->txt("iass_record") => $record_note
368  );
369  }
370 
376  protected function getInternalRecordNote(string $internal_note = null)
377  {
378  if (is_null($internal_note)) {
379  $internal_note = "";
380  }
381 
382  return array(
383  $this->txt("iass_internal_note") => $internal_note
384  );
385  }
386 
390  protected function getFileDownloadLink(int $usr_id, $file_name) : array
391  {
392  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
393  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', ilIndividualAssessmentMemberGUI::CMD_DOWNLOAD_FILE);
394  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
395  $link = $this->factory->link()->standard($this->txt("iass_download"), $target);
396 
397  return array(
398  $this->txt("iass_file") => $this->renderer->render($link)
399  );
400  }
401 
405  protected function getEntryForStatus(int $a_status) : string
406  {
407  switch ($a_status) {
409  return $this->txt('iass_status_pending');
410  break;
412  return $this->txt('iass_status_completed');
413  break;
415  return $this->txt('iass_status_failed');
416  break;
417  default:
418  throw new ilIndividualAssessmentException("Invalid status: " . $a_status);
419  }
420  }
421 
425  protected function viewLocation(bool $finalized, int $examiner_id = null, int $usr_id) : bool
426  {
427  return
428  $this->checkEditable($finalized, $examiner_id, $usr_id)
429  || $this->checkAmendable($finalized)
430  || $this->userMayViewGrades()
431  ;
432  }
433 
437  protected function checkEditable(bool $finalized, int $examiner_id = null, int $usr_id) : bool
438  {
439  if (
440  ($this->userIsSystemAdmin() && !$finalized)
441  || (!$finalized && $this->userMayEditGradesOf($usr_id) && $this->wasEditedByViewer($examiner_id))
442  ) {
443  return true;
444  }
445 
446  return false;
447  }
448 
452  protected function checkAmendable(bool $finalized) : bool
453  {
454  if (
455  ($this->userIsSystemAdmin() && $finalized)
456  || ($finalized && $this->userMayAmendGrades())
457  ) {
458  return true;
459  }
460 
461  return false;
462  }
463 
467  protected function checkUserRemoveable(bool $finalized) : bool
468  {
469  if (($this->userIsSystemAdmin() && !$finalized) || (!$finalized && $this->userMayEditMembers())) {
470  return true;
471  }
472 
473  return false;
474  }
475 
479  protected function checkDownloadFile(int $usr_id, string $file_name = null) : bool
480  {
481  if ((!is_null($file_name) && $file_name !== '')
482  && ($this->userIsSystemAdmin() || $this->userMayDownloadAttachment($usr_id))
483  ) {
484  return true;
485  }
486 
487  return false;
488  }
489 
490  protected function userMayDownloadAttachment(int $usr_id) : bool
491  {
492  return $this->userMayViewGrades() || $this->userMayEditGrades() || $this->userMayEditGradesOf($usr_id);
493  }
494 
495  protected function userMayViewGrades() : bool
496  {
497  return $this->iass_access->mayViewUser();
498  }
499 
500  protected function userMayEditGrades() : bool
501  {
502  return $this->iass_access->mayGradeUser();
503  }
504 
505  protected function userMayAmendGrades() : bool
506  {
507  return $this->iass_access->mayAmendGradeUser();
508  }
509 
510  protected function userMayEditMembers() : bool
511  {
512  return $this->iass_access->mayEditMembers();
513  }
514 
515  protected function userIsSystemAdmin() : bool
516  {
517  return $this->iass_access->isSystemAdmin();
518  }
519 
520  protected function userMayEditGradesOf(int $usr_id) : bool
521  {
522  return $this->iass_access->mayGradeUserById($usr_id);
523  }
524 
525  protected function wasEditedByViewer(int $examiner_id = null) : bool
526  {
527  return $examiner_id === $this->current_user_id || null === $examiner_id;
528  }
529 
530  protected function txt(string $code) : string
531  {
532  return $this->lng->txt($code);
533  }
534 }
getLocationInfos(string $location=null, bool $finalized, int $examiner_id=null, int $usr_id)
Returns the location of assessment.
static _lookupName($a_user_id)
lookup user name
__construct(ilIndividualAssessmentMembersGUI $parent, ilLanguage $lng, ilCtrl $ctrl, IndividualAssessmentAccessHandler $iass_access, Factory $factory, Renderer $renderer, int $current_user_id)
An entity that renders components to a string output.
Definition: Renderer.php:14
This class provides processing control methods.
$data
Definition: storeScorm.php:23
render(array $view_constrols, int $offset=0, int $limit=null)
Renders the presentation table.
$location
Definition: buildRTE.php:44
getRecordNote(string $record_note)
Returns inforamtions out of record note.
checkEditable(bool $finalized, int $examiner_id=null, int $usr_id)
Check the current user has edit permission on record.
getContent(ilIndividualAssessmentMember $record)
Return all content elements for each row.
listing()
description: purpose: > Listings are used to structure itemised textual information.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
getSubheadline(ilIndividualAssessmentMember $record)
Returns the subheadline for each row.
Mechanic regarding the access controll and roles of an objcet goes here.
checkAmendable(bool $finalized)
Check the current user has amend permission on record.
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:15
if($format !==null) $name
Definition: metadata.php:230
getInternalRecordNote(string $internal_note=null)
Returns inforamtions out of internal record note.
Class for single dates.
getAction(ilIndividualAssessmentMember $record, $ui_factory)
Return the ui control with executable actions.
$lng
This is how the factory for UI elements looks.
Definition: Factory.php:17
getFileDownloadLink(int $usr_id, $file_name)
Get the link for download of file.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getFullNameFor(int $user_id=null)
Returns login of examinier.
This describes a Row used in Presentation Table.
Edit the record of a user, set LP.
const IL_CAL_DATE
withHeadline($headline)
Get a row like this with the given headline.
getGradedInformations(?DateTimeImmutable $event_time)
Returns informations about the grading.
viewLocation(bool $finalized, int $examiner_id=null, int $usr_id)
Check user may view the location.
language handling
getChangedByInformation(?int $changed_by_id, ?DateTime $change_date)
getStatus(bool $finalized, int $status, int $examiner_id=null)
Returns readable status.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
checkDownloadFile(int $usr_id, string $file_name=null)
Check the current user is allowed to download the record file.
checkUserRemoveable(bool $finalized)
Check the current user is allowed to remove the user.
getFurtherFields(ilIndividualAssessmentMember $record)
Returns all informations needed for further informations for each row.
$factory
Definition: metadata.php:58
getHeadline(ilIndividualAssessmentMember $record)
Returns the headline for each row.
importantInfos(ilIndividualAssessmentMember $record)
Returns all informations needed for important row.