ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  const CHANGED = "changed";
23  const GRADED = "graded";
24 
25  public function __construct(
28  ilCtrl $ctrl,
31  Renderer $renderer,
32  int $current_user_id
33  ) {
34  $this->parent = $parent;
35  $this->lng = $lng;
36  $this->ctrl = $ctrl;
37  $this->iass_access = $iass_access;
38  $this->factory = $factory;
39  $this->renderer = $renderer;
40  $this->current_user_id = $current_user_id;
41  }
42 
50  public function setData(array $data)
51  {
52  $this->data = $data;
53  }
54 
60  public function render(array $view_constrols, int $offset = 0, int $limit = null) : string
61  {
62  $ptable = $this->factory->table()->presentation(
63  "",
64  $view_constrols,
65  function (
68  Factory $ui_factory,
69  $environment
70  ) {
71  $headline = $this->getHeadline($record);
72  $subheadline = $this->getSubheadline($record);
73  $important_infos = $this->importantInfos($record);
74  $further_fields = $this->getFurtherFields($record);
75  $content = $this->getContent($record);
76  $action = $this->getAction($record, $ui_factory);
77 
78  $row = $row
79  ->withHeadline($headline)
80  ->withSubheadline($subheadline)
81  ->withImportantFields($important_infos)
82  ->withContent($ui_factory->listing()->descriptive($content))
83  ->withFurtherFieldsHeadline($this->txt("iass_further_field_headline"))
84  ->withFurtherFields($further_fields)
85  ->withAction($action);
86 
87  return $row;
88  }
89  );
90 
91  $data = array_slice($this->data, $offset, $limit);
92  return $this->renderer->render($ptable->withData($data));
93  }
94 
98  protected function getHeadline(ilIndividualAssessmentMember $record) : string
99  {
100  return $record->lastname() . ", " . $record->firstname();
101  }
102 
106  protected function getSubheadline(ilIndividualAssessmentMember $record) : string
107  {
108  if (!$this->userMayViewGrades() && !$this->userMayEditGrades()) {
109  return "";
110  }
111 
112  $examiner_id = $this->getExaminerId($record);
113  return $this->txt("grading") . ": " . $this->getStatus($record->finalized(), (int) $record->LPStatus(), $examiner_id);
114  }
115 
121  protected function importantInfos(ilIndividualAssessmentMember $record) : array
122  {
123  $finalized = $record->finalized();
124 
125  if ((!$this->userMayViewGrades() && !$this->userMayEditGrades()) || !$finalized) {
126  return [];
127  }
128 
129  $changer = array();
130  if (!is_null($record->changerId())) {
131  $changer_id = $this->getChangerId($record);
132  $changer = $this->getProfileLink(self::CHANGED, $this->getFullNameFor($changer_id), $changer_id);
133  }
134 
135  $examiner_id = $this->getExaminerId($record);
136  return array_merge(
137  $this->getGradedInformations($record->eventTime()),
138  $this->getProfileLink(self::GRADED, $this->getFullNameFor($examiner_id), $examiner_id),
139  $changer
140  );
141  }
142 
148  protected function getContent(ilIndividualAssessmentMember $record) : array
149  {
150  $examiner_id = $this->getExaminerId($record);
151  if (
152  !$this->checkEditable($record->finalized(), $examiner_id, (int) $record->id())
153  && !$this->checkAmendable($record->finalized())
154  && !$this->userMayViewGrades()
155  && !$this->userMayEditGrades()
156  ) {
157  return [];
158  }
159 
160  $usr_id = (int) $record->id();
161  $file_name = $record->fileName();
162 
163  return array_merge(
164  $this->getRecordNote($record->record()),
165  $this->getInternalRecordNote($record->internalNote()),
166  $this->checkDownloadFile($usr_id, $file_name)
167  ? $this->getFileDownloadLink($usr_id, $file_name)
168  : []
169  );
170  }
171 
177  protected function getFurtherFields(ilIndividualAssessmentMember $record) : array
178  {
179  if (!$this->userMayViewGrades() && !$this->userMayEditGrades()) {
180  return [];
181  }
182 
183  return array_merge(
184  $this->importantInfos($record),
185  $this->getLocationInfos(
186  $record->place(),
187  $record->finalized(),
188  $this->getExaminerId($record),
189  (int) $record->id()
190  )
191  );
192  }
193 
197  protected function getAction(ilIndividualAssessmentMember $record, $ui_factory) : Dropdown
198  {
199  $items = [];
200 
201  $examiner_id = $this->getExaminerId($record);
202  $usr_id = (int) $record->id();
203  $finalized = $record->finalized();
204  $file_name = $record->fileName();
205 
206  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
207 
208  if ($this->checkEditable($finalized, $examiner_id, $usr_id)) {
209  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'edit');
210  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_edit'), $target);
211  }
212 
213  if ($this->checkUserRemoveable($finalized)) {
214  $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', $usr_id);
215  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMembersGUI', 'removeUserConfirmation');
216  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_remove'), $target);
217  $this->ctrl->setParameterByClass('ilIndividualAssessmentMembersGUI', 'usr_id', null);
218  }
219 
220  if ($this->checkAmendable($finalized)) {
221  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'amend');
222  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_amend'), $target);
223  }
224 
225  if ($this->checkDownloadFile($usr_id, $file_name)) {
226  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'downloadAttachment');
227  $items[] = $ui_factory->button()->shy($this->txt('iass_usr_download_attachment'), $target);
228  }
229  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
230 
231  $action = $ui_factory->dropdown()->standard($items)->withLabel($this->txt("actions"));
232  return $action;
233  }
234 
238  protected function getStatus(bool $finalized, int $status, int $examiner_id = null) : string
239  {
240  if ($status == 0) {
242  }
243 
244  if (!$finalized && !is_null($examinerId)) {
246  }
247 
248  return $this->getEntryForStatus($status);
249  }
250 
256  protected function getGradedInformations(ilDate $event_time) : array
257  {
258  return array(
259  $this->txt("iass_event_time") . ": " => ilDatePresentation::formatDate($event_time)
260  );
261  }
262 
268  protected function getFullNameFor(int $user_id = null) : string
269  {
270  if (is_null($user_id)) {
271  return "";
272  }
273 
274  $name_fields = ilObjUser::_lookupName($user_id);
275  $name = $name_fields["lastname"] . ", " . $name_fields["firstname"] . " [" . $name_fields["login"] . "]";
276 
277  return $name;
278  }
279 
280  protected function getProfileLink(string $case, string $examiner, int $examiner_id)
281  {
282  if ($examiner === "") {
283  return array();
284  }
285 
286  if (!$this->hasPublicProfile($examiner_id)) {
287  return array(
288  $this->txt("iass_" . $case . "_by") => $examiner
289  );
290  }
291 
292  $back_url = $this->ctrl->getLinkTarget($this->parent, "view");
293  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user_id', $examiner_id);
294  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', "back_url", rawurlencode($back_url));
295  $link = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
296  $link = $this->factory->link()->standard($examiner, $link);
297 
298  return array(
299  $this->txt("iass_" . $case . "_by") => $this->renderer->render($link)
300  );
301  }
302 
303  protected function hasPublicProfile(int $examiner_id) : bool
304  {
306  return (
307  ($user->getPref('public_profile') == 'y') ||
308  $user->getPref('public_profile') == 'g'
309  );
310  }
311 
317  protected function getLocationInfos(
318  string $location = null,
319  bool $finalized,
320  int $examiner_id = null,
321  int $usr_id
322  ) : array {
323  if (!$this->viewLocation($finalized, $examiner_id, $usr_id)) {
324  return array();
325  }
326 
327  if ($location == "" || is_null($location)) {
328  $location = $this->txt("none");
329  }
330 
331  return array(
332  $this->txt("iass_location") . ": " => $location
333  );
334  }
335 
341  protected function getRecordNote(string $record_note) : array
342  {
343  return array(
344  $this->txt("iass_record") => $record_note
345  );
346  }
347 
353  protected function getInternalRecordNote(string $internal_note = null)
354  {
355  if (is_null($internal_note)) {
356  $internal_note = "";
357  }
358 
359  return array(
360  $this->txt("iass_internal_note") => $internal_note
361  );
362  }
363 
367  protected function getFileDownloadLink(int $usr_id, $file_name) : array
368  {
369  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', $usr_id);
370  $target = $this->ctrl->getLinkTargetByClass('ilIndividualAssessmentMemberGUI', 'downloadAttachment');
371  $this->ctrl->setParameterByClass('ilIndividualAssessmentMemberGUI', 'usr_id', null);
372  $link = $this->factory->link()->standard($this->txt("iass_download"), $target);
373 
374  return array(
375  $this->txt("iass_file") => $this->renderer->render($link)
376  );
377  }
378 
382  protected function getEntryForStatus(int $a_status) : string
383  {
384  switch ($a_status) {
386  return $this->txt('iass_status_pending');
387  break;
389  return $this->txt('iass_status_completed');
390  break;
392  return $this->txt('iass_status_failed');
393  break;
395  return $this->txt('iass_assessment_not_completed');
396  break;
397  }
398  }
399 
405  protected function getExaminerId(ilIndividualAssessmentMember $record)
406  {
407  $examiner_id = $record->examinerId();
408 
409  if (is_null($examiner_id)) {
410  return null;
411  }
412 
413  return (int) $examiner_id;
414  }
415 
416  protected function getChangerId(ilIndividualAssessmentMember $record)
417  {
418  $changer_id = $record->changerId();
419 
420  if (is_null($changer_id)) {
421  return null;
422  }
423 
424  return (int) $changer_id;
425  }
426 
430  protected function viewLocation(bool $finalized, int $examiner_id = null, int $usr_id) : bool
431  {
432  return
433  $this->checkEditable($finalized, $examiner_id, $usr_id)
434  || $this->checkAmendable($finalized)
435  || $this->userMayViewGrades()
436  ;
437  }
438 
442  protected function checkEditable(bool $finalized, int $examiner_id = null, int $usr_id) : bool
443  {
444  if (
445  ($this->userIsSystemAdmin() && !$finalized)
446  || (!$finalized && $this->userMayEditGradesOf($usr_id) && $this->wasEditedByViewer($examiner_id))
447  ) {
448  return true;
449  }
450 
451  return false;
452  }
453 
457  protected function checkAmendable(bool $finalized) : bool
458  {
459  if (
460  ($this->userIsSystemAdmin() && $finalized)
461  || ($finalized && $this->userMayAmendGrades())
462  ) {
463  return true;
464  }
465 
466  return false;
467  }
468 
472  protected function checkUserRemoveable(bool $finalized) : bool
473  {
474  if (($this->userIsSystemAdmin() && !$finalized) || (!$finalized && $this->userMayEditMembers())) {
475  return true;
476  }
477 
478  return false;
479  }
480 
484  protected function checkDownloadFile(int $usr_id, string $file_name = null) : bool
485  {
486  if ((!is_null($file_name) && $file_name !== '')
487  && ($this->userIsSystemAdmin() || $this->userMayDownloadAttachment($usr_id))
488  ) {
489  return true;
490  }
491 
492  return false;
493  }
494 
495  protected function userMayDownloadAttachment(int $usr_id) : bool
496  {
497  return $this->userMayViewGrades() || $this->userMayEditGrades() || $this->userMayEditGradesOf($usr_id);
498  }
499 
500  protected function userMayViewGrades() : bool
501  {
502  return $this->iass_access->mayViewUser();
503  }
504 
505  protected function userMayEditGrades() : bool
506  {
507  return $this->iass_access->mayGradeUser();
508  }
509 
510  protected function userMayAmendGrades() : bool
511  {
512  return $this->iass_access->mayAmendGradeUser();
513  }
514 
515  protected function userMayEditMembers() : bool
516  {
517  return $this->iass_access->mayEditMembers();
518  }
519 
520  protected function userIsSystemAdmin() : bool
521  {
522  return $this->iass_access->isSystemAdmin();
523  }
524 
525  protected function userMayEditGradesOf(int $usr_id) : bool
526  {
527  return $this->iass_access->mayGradeUserById($usr_id);
528  }
529 
530  protected function wasEditedByViewer(int $examiner_id = null) : bool
531  {
532  return $examiner_id === $this->current_user_id || null === $examiner_id;
533  }
534 
535  protected function txt(string $code) : string
536  {
537  return $this->lng->txt($code);
538  }
539 }
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
getExaminerId(ilIndividualAssessmentMember $record)
Returns the examnier id from record.
An entity that renders components to a string output.
Definition: Renderer.php:14
This class provides processing control methods.
render(array $view_constrols, int $offset=0, int $limit=null)
Renders the presentation table.
$action
$location
Definition: buildRTE.php:44
$code
Definition: example_050.php:99
examinerId()
Get the user id of the examiner.
getRecordNote(string $record_note)
Returns inforamtions out of record note.
$factory
Definition: metadata.php:43
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.
__construct(ilIndividualAssessmentMembersGUI $parent, ilLanguage $lng, ilCtrl $ctrl, ilIndividualAssessmentAccessHandler $iass_access, Factory $factory, Renderer $renderer, int $current_user_id)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
finalized()
Is this membership allready finalized?
changerId()
Get the user id of the changer.
getSubheadline(ilIndividualAssessmentMember $record)
Returns the subheadline for each row.
checkAmendable(bool $finalized)
Check the current user has amend permission on record.
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:15
getGradedInformations(ilDate $event_time)
Returns informations about the grading.
getInternalRecordNote(string $internal_note=null)
Returns inforamtions out of internal record note.
firstname()
Get the examinee firstname corresponding to this membership.
getProfileLink(string $case, string $examiner, int $examiner_id)
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:15
lastname()
Get the examinee lastname corresponding to this membership.
getFileDownloadLink(int $usr_id, $file_name)
Get the link for download of file.
$user
Definition: migrateto20.php:57
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.
$row
This describes a Row used in Presentation Table.
Edit the record of a user, set LP.
withHeadline($headline)
Get a row like this with the given headline.
$this data['403_header']
viewLocation(bool $finalized, int $examiner_id=null, int $usr_id)
Check user may view the location.
fileName()
Get the name of the uploaded file.
language handling
getStatus(bool $finalized, int $status, int $examiner_id=null)
Returns readable status.
id()
Get the user id corresponding to this membership.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
$target
Definition: test.php:19
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.
LPStatus()
Get the LP-status corresponding to this membership.
getHeadline(ilIndividualAssessmentMember $record)
Returns the headline for each row.
importantInfos(ilIndividualAssessmentMember $record)
Returns all informations needed for important row.
$data
Definition: bench.php:6