ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilIndividualAssessmentMemberGUI.php
Go to the documentation of this file.
1 <?php
2 
3 require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
4 require_once 'Services/Form/classes/class.ilTextInputGUI.php';
5 require_once 'Services/Form/classes/class.ilCheckboxInputGUI.php';
6 require_once 'Services/Form/classes/class.ilNonEditableValueGUI.php';
7 require_once 'Services/Form/classes/class.ilSelectInputGUI.php';
8 require_once 'Modules/IndividualAssessment/classes/LearningProgress/class.ilIndividualAssessmentLPInterface.php';
9 require_once 'Modules/IndividualAssessment/classes/Notification/class.ilIndividualAssessmentPrimitiveInternalNotificator.php';
10 require_once 'Modules/IndividualAssessment/classes/class.ilIndividualAssessmentLP.php';
11 require_once 'Modules/IndividualAssessment/classes/FileStorage/class.ilIndividualAssessmentFileStorage.php';
12 require_once 'Services/Form/classes/class.ilFileInputGUI.php';
13 
22 {
23  protected $notificator;
24 
25  public function __construct($members_gui, $a_parent_gui, $a_ref_id)
26  {
27  $this->notificator = new ilIndividualAssessmentPrimitiveInternalNotificator();
28  global $DIC;
29  $this->ctrl = $DIC['ilCtrl'];
30  $this->members_gui = $members_gui;
31  $this->parent_gui = $a_parent_gui;
32  $this->object = $a_parent_gui->object;
33  $this->ref_id = $a_ref_id;
34  $this->tpl = $DIC['tpl'];
35  $this->lng = $DIC['lng'];
36  $this->ctrl->saveParameter($this, 'usr_id');
37  $this->examinee = new ilObjUser($_GET['usr_id']);
38  $this->examiner = $DIC['ilUser'];
39  $this->changer = $DIC['ilUser'];
40  $this->setTabs($DIC['ilTabs']);
41  $this->member = $this->object->membersStorage()
42  ->loadMember($this->object, $this->examinee);
43  $this->access = $this->object->accessHandler();
44  $this->file_storage = $this->object->getFileStorage();
45  }
46 
47  public function executeCommand()
48  {
49  $cmd = $this->ctrl->getCmd();
50  switch ($cmd) {
51  case 'view':
52  case 'edit':
53  case 'save':
54  case 'finalizeConfirmation':
55  case 'finalize':
56  case 'cancelFinalize':
57  case 'amend':
58  case 'saveAmend':
59  case 'downloadAttachment':
60  case 'deliverFile':
61  break;
62  default:
63  $this->parent_gui->handleAccessViolation();
64  }
65  $this->$cmd();
66  }
67 
73  protected function view()
74  {
75  if (!$this->mayBeViewed()) {
76  $this->parent_gui->handleAccessViolation();
77  return;
78  }
79  $form = $this->fillForm($this->initGradingForm(false), $this->member);
80  $this->renderForm($form);
81  }
82 
90  protected function edit(ilPropertyFormGUI $form = null)
91  {
92  if (!$this->mayBeEdited()) {
93  $this->parent_gui->handleAccessViolation();
94  return;
95  }
96 
97  if ($form === null) {
98  $form = $this->fillForm($this->initGradingForm(), $this->member);
99  }
100 
101  $form->addCommandButton('save', $this->lng->txt('save'));
102  $form->addCommandButton('finalizeConfirmation', $this->lng->txt('iass_finalize'));
103  $this->renderForm($form);
104  }
105 
106  protected function downloadAttachment()
107  {
108  if (!$this->mayBeEdited() && !$this->mayBeViewed() && !$this->mayBeAmended()) {
109  $this->parent_gui->handleAccessViolation();
110  return;
111  }
112  $file_storage = $this->object->getFileStorage();
113  $file_storage->setUserId($this->member->id());
114  ilUtil::deliverFile($file_storage->getFilePath(), $this->member->fileName());
115  }
116 
122  protected function save()
123  {
124  if (!$this->mayBeEdited()) {
125  $this->parent_gui->handleAccessViolation();
126  return;
127  }
128 
129  $form = $this->initGradingForm();
130  $item = $form->getItemByPostVar('file');
131  if ($item && $item->checkInput()) {
132  $post = $_POST;
133  $new_file = $this->uploadFile($post["file"]);
134  if ($new_file) {
135  $this->updateFileName($post['file']['name']);
136  }
137  }
138 
139  $form->setValuesByArray(array('file' => $this->member->fileName()));
140  if (!$form->checkInput()) {
141  $form->setValuesByPost();
142  $this->edit($form);
143  return;
144  }
145 
146  $this->saveMember($_POST);
147  if ($this->object->isActiveLP()) {
149  }
150  ilUtil::sendSuccess($this->lng->txt('iass_membership_saved'), true);
151  $this->redirect('edit');
152  }
153 
159  protected function finalizeConfirmation()
160  {
161  if (!$this->mayBeEdited()) {
162  $this->parent_gui->handleAccessViolation();
163  return;
164  }
165 
166  $new_file = null;
167  $form = $this->initGradingForm();
168  $item = $form->getItemByPostVar('file');
169  if ($item && $item->checkInput()) {
170  $post = $_POST;
171  $new_file = $this->uploadFile($post["file"]);
172  if ($new_file) {
173  $this->updateFileName($post['file']['name']);
174  }
175  }
176 
177  $form->setValuesByArray(array('file' => $this->member->fileName()));
178  if (!$form->checkInput()) {
179  $form->setValuesByPost();
180  $this->edit($form);
181  return;
182  }
183 
184  $this->saveMember($_POST);
185 
186  if (!$this->member->mayBeFinalized()) {
187  ilUtil::sendFailure($this->lng->txt('iass_may_not_finalize'), true);
188  $this->redirect('edit');
189  }
190 
191  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
192  $confirm = new ilConfirmationGUI();
193  $confirm->addHiddenItem('record', $_POST['record']);
194  $confirm->addHiddenItem('internal_note', $_POST['internal_note']);
195  $confirm->addHiddenItem('notify', $_POST['notify']);
196  $confirm->addHiddenItem('learning_progress', $_POST['learning_progress']);
197  $confirm->addHiddenItem('place', $_POST['place']);
198  $confirm->addHiddenItem('event_time', $_POST['event_time']);
199  $confirm->setHeaderText($this->lng->txt('iass_finalize_user_qst'));
200  $confirm->setFormAction($this->ctrl->getFormAction($this));
201  $confirm->setConfirm($this->lng->txt('iass_finalize'), 'finalize');
202  $confirm->setCancel($this->lng->txt('cancel'), 'save');
203  $this->tpl->setContent($confirm->getHTML());
204  }
205 
211  protected function finalize()
212  {
213  if (!$this->mayBeEdited()) {
214  $this->parent_gui->handleAccessViolation();
215  return;
216  }
217 
218  if (!$this->member->mayBeFinalized()) {
219  ilUtil::sendFailure($this->lng->txt('iass_may_not_finalize'), true);
220  $this->redirect('edit');
221  return;
222  }
223 
224  $this->member = $this->member->withFinalized();
225  $this->object->membersStorage()->updateMember($this->member);
226  if ($this->object->isActiveLP()) {
228  }
229  $this->member->maybeSendNotification($this->notificator);
230 
231  ilUtil::sendSuccess($this->lng->txt('iass_membership_finalized'), true);
232  $this->redirect('view');
233  }
234 
240  protected function cancelFinalize()
241  {
242  $this->edit();
243  }
244 
252  protected function amend($form = null)
253  {
254  if (!$this->mayBeAmended()) {
255  $this->parent_gui->handleAccessViolation();
256  return;
257  }
258 
259  if ($form === null) {
260  $form = $this->fillForm($this->initGradingForm(true, true), $this->member);
261  }
262 
263  $form->addCommandButton('saveAmend', $this->lng->txt('iass_save_amend'));
264  $this->renderForm($form, $this->getFileLinkHTML(true));
265  }
266 
272  protected function saveAmend()
273  {
274  if (!$this->mayBeAmended()) {
275  $this->parent_gui->handleAccessViolation();
276  return;
277  }
278  $new_file = null;
279  $form = $this->initGradingForm(true, true);
280  $item = $form->getItemByPostVar('file');
281  if ($item && $item->checkInput()) {
282  $post = $_POST;
283  $new_file = $this->uploadFile($post["file"]);
284  if ($new_file) {
285  $this->updateFileName($post['file']['name']);
286  }
287  }
288  $form->setValuesByArray(array('file' => $this->member->fileName()));
289  if (!$form->checkInput()) {
290  $form->setValuesByPost();
291  $this->amend($form);
292  return;
293  }
294 
295  $this->saveMember($_POST, true, true);
296 
297  if ($this->object->isActiveLP()) {
299  }
300 
301  ilUtil::sendSuccess($this->lng->txt('iass_amend_saved'), true);
302  $this->redirect("amend");
303  }
304 
312  protected function initGradingForm($may_be_edited = true, $amend = false)
313  {
314  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
315  $form = new ilPropertyFormGUI();
316  $form->setFormAction($this->ctrl->getFormAction($this));
317  $form->setTitle($this->lng->txt('iass_edit_record'));
318 
319  $examinee_name = $this->examinee->getLastname() . ', ' . $this->examinee->getFirstname();
320 
321  $usr_name = new ilNonEditableValueGUI($this->lng->txt('name'), 'name');
322  $form->addItem($usr_name);
323  // record
324  $ti = new ilTextAreaInputGUI($this->lng->txt('iass_record'), 'record');
325  $ti->setInfo($this->lng->txt('iass_record_info'));
326  $ti->setCols(40);
327  $ti->setRows(5);
328  $ti->setDisabled(!$may_be_edited);
329  $form->addItem($ti);
330 
331  // description
332  $ta = new ilTextAreaInputGUI($this->lng->txt('iass_internal_note'), 'internal_note');
333  $ta->setInfo($this->lng->txt('iass_internal_note_info'));
334  $ta->setCols(40);
335  $ta->setRows(5);
336  $ta->setDisabled(!$may_be_edited);
337  $form->addItem($ta);
338 
339  if ($this->member->finalized() && !$amend) {
340  $link = $this->getFileLinkHTML(true);
341  if ($link !== "") {
342  $filelink = new ilNonEditableValueGUI($this->lng->txt('iass_upload_file'), '', true);
343  $filelink->setValue($link);
344  $form->addItem($filelink);
345  }
346  } else {
347  $title = $this->lng->txt('iass_upload_file');
348  $link = $this->getFileLinkHTML(true);
349  if ($link !== "") {
350  $filelink = new ilNonEditableValueGUI($title, '', true);
351  $filelink->setValue($link);
352  $form->addItem($filelink);
353  $title = "";
354  }
355  $file = new ilFileInputGUI($title, 'file');
356  $file->setRequired($this->object->getSettings()->fileRequired() && !$this->fileUploaded());
357  $file->setDisabled(!$may_be_edited);
358  $file->setAllowDeletion(false);
359  $form->addItem($file);
360  }
361 
362 
363  $file_visible_to_examinee = new ilCheckboxInputGUI($this->lng->txt('iass_file_visible_examinee'), 'file_visible_examinee');
364  $file_visible_to_examinee->setDisabled(!$may_be_edited);
365  $form->addItem($file_visible_to_examinee);
366 
367 
368  $learning_progress = new ilSelectInputGUI($this->lng->txt('grading'), 'learning_progress');
369  $learning_progress->setOptions(
370  array(ilIndividualAssessmentMembers::LP_IN_PROGRESS => $this->lng->txt('iass_status_pending')
371  , ilIndividualAssessmentMembers::LP_COMPLETED => $this->lng->txt('iass_status_completed')
372  , ilIndividualAssessmentMembers::LP_FAILED => $this->lng->txt('iass_status_failed'))
373  );
374  $learning_progress->setDisabled(!$may_be_edited);
375  $form->addItem($learning_progress);
376 
377  $settings = $this->object->getSettings();
378  $txt = new ilTextInputGUI($this->lng->txt('iass_place'), 'place');
379  $txt->setRequired($settings->eventTimePlaceRequired());
380  $txt->setDisabled(!$may_be_edited);
381  $form->addItem($txt);
382 
383  $date = new ilDateTimeInputGUI($this->lng->txt('iass_event_time'), 'event_time');
384  $date->setShowTime(false);
385  $date->setRequired($settings->eventTimePlaceRequired());
386  $date->setDisabled(!$may_be_edited);
387  $form->addItem($date);
388 
389  // notify examinee
390  $notify = new ilCheckboxInputGUI($this->lng->txt('iass_notify'), 'notify');
391  $notify->setInfo($this->lng->txt('iass_notify_explanation'));
392  $notify->setDisabled(!$may_be_edited);
393  $form->addItem($notify);
394 
395  return $form;
396  }
397 
398  protected function fileUploaded()
399  {
400  return $this->member->fileName() && $this->member->fileName() != "";
401  }
402 
411  protected function fillForm(ilPropertyFormGUI $a_form, ilIndividualAssessmentMember $member)
412  {
413  $a_form->setValuesByArray(array(
414  'name' => $member->name()
415  , 'record' => $member->record()
416  , 'internal_note' => $member->internalNote()
417  , 'place' => $member->place()
418  , 'event_time' => $member->eventTime()
419  , 'notify' => $member->notify()
420  , 'learning_progress' => (int) $member->LPStatus()
421  , 'file_visible_examinee' => (int) $member->viewFile()
422  , 'file_name' => $this->getFileLinkHTML()
423  ));
424  return $a_form;
425  }
426 
432  protected function getFileLinkHTML($amend = false)
433  {
434  $html = '';
435  if ($this->member->fileName() && $this->member->fileName() != "") {
436  $tpl = new ilTemplate("tpl.iass_user_file_download.html", true, true, "Modules/IndividualAssessment");
437  if (!$this->member->finalized() || $amend) {
438  $tpl->setVariable("FILE_NAME", $this->member->fileName());
439  }
440  $tpl->setVariable("HREF", $this->ctrl->getLinkTarget($this, "downloadAttachment"));
441  $html .= $tpl->get();
442  }
443  return $html;
444  }
445 
451  protected function renderForm(ilPropertyFormGUI $form)
452  {
453  $this->tpl->setContent($form->getHTML());
454  }
455 
461  protected function setTabs(ilTabsGUI $tabs)
462  {
463  $tabs->clearTargets();
464  $tabs->setBackTarget(
465  $this->lng->txt('back'),
466  $this->getBackLink()
467  );
468  }
469 
475  protected function getBackLink()
476  {
477  return $this->ctrl->getLinkTargetByClass(
478  array(get_class($this->parent_gui)
479  ,get_class($this->members_gui)),
480  'view'
481  );
482  }
483 
491  protected function redirect($cmd)
492  {
493  $this->ctrl->redirect($this, $cmd);
494  }
495 
501  protected function mayBeEdited()
502  {
503  return $this->access->isSystemAdmin()
504  || (!$this->isFinalized() && $this->userMayGrade());
505  }
506 
512  protected function mayBeViewed()
513  {
514  return $this->access->isSystemAdmin()
515  || ($this->isFinalized() && ($this->userMayGrade() || $this->userMayView()));
516  }
517 
523  protected function mayBeAmended()
524  {
525  return $this->access->isSystemAdmin()
526  || ($this->isFinalized() && $this->userMayAmend());
527  }
528 
534  protected function userMayGrade()
535  {
536  return $this->access->isSystemAdmin()
537  || (!$this->targetWasEditedByOtherUser($this->member) && $this->access->mayGradeUser());
538  }
539 
545  protected function userMayView()
546  {
547  return $this->access->isSystemAdmin()
548  || $this->access->mayViewUser();
549  }
550 
556  protected function userMayAmend()
557  {
558  return $this->access->isSystemAdmin()
559  || $this->access->mayAmendGradeUser();
560  }
561 
568  {
569  return (int) $member->examinerId() !== (int) $this->examiner->getId()
570  && 0 !== (int) $member->examinerId();
571  }
572 
578  protected function isFinalized()
579  {
580  return $this->member->finalized();
581  }
582 
591  protected function saveMember(array $post, $keep_examiner = false, $amend = false)
592  {
593  $this->member = $this->updateDataInMemberByArray($this->member, $post, $keep_examiner, $amend);
594  $this->object->membersStorage()->updateMember($this->member);
595  }
596 
606  protected function updateDataInMemberByArray(ilIndividualAssessmentMember $member, $data, $keep_examiner = false, $amend = false)
607  {
608  $member = $member->withRecord($data['record'])
609  ->withInternalNote($data['internal_note'])
610  ->withPlace($data['place'])
611  ->withLPStatus($data['learning_progress'])
612  ->withViewFile((bool) $data['file_visible_examinee']);
613  if ($data['event_time']) {
614  $member = $member->withEventTime($this->createDate($data['event_time']));
615  }
616  if ($amend) {
617  $member = $member->withChangerId($this->changer->getId());
618  }
619  if (!$keep_examiner) {
620  $member = $member->withExaminerId($this->examiner->getId());
621  }
622 
623  if ($data['notify'] == 1) {
624  $member = $member->withNotify(true);
625  } else {
626  $member = $member->withNotify(false);
627  }
628  if ($new_file) {
629  $member = $member->withFileName($data['file']['name']);
630  }
631  return $member;
632  }
633 
634  private function createDate($datetime)
635  {
636  return new ilDate($datetime, IL_CAL_DATE);
637  }
638 
639  protected function uploadFile($file)
640  {
641  $new_file = false;
642  $this->file_storage->setUserId($this->member->id());
643  $this->file_storage->create();
644  if (!$file["name"] == "") {
645  $this->file_storage->deleteCurrentFile();
646  $this->file_storage->uploadFile($file);
647  $new_file = true;
648  }
649  return $new_file;
650  }
651 
652  protected function updateFileName($file_name)
653  {
654  $this->member = $this->member->withFileName($file_name);
655  $this->object->membersStorage()->updateMember($this->member);
656  }
657 }
updateDataInMemberByArray(ilIndividualAssessmentMember $member, $data, $keep_examiner=false, $amend=false)
Updates member object with new grading informations.
__construct($members_gui, $a_parent_gui, $a_ref_id)
This class represents a selection list property in a property form.
Tabs GUI.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tpl
Definition: ilias.php:10
This class represents a file property in a property form.
edit(ilPropertyFormGUI $form=null)
Edit grading informations for user.
examinerId()
Get the user id of the examiner.
withFileName($file_name)
Set the name of the file.
userMayGrade()
Current user has permission to edit learning progess.
This class represents a checkbox property in a property form.
static updateLPStatusOfMember(ilIndividualAssessmentMember $member)
withChangerId($changer_id)
Clone this object and set an changer_id.
getFileLinkHTML($amend=false)
Render grading form into template.
view()
View grading informations for user.
userMayView()
Current user has permission to read learning progress.
setBackTarget($a_title, $a_target, $a_frame="")
back target for upper context
withRecord($record)
Clone this object and set a record.
This class represents a date/time property in a property form.
fillForm(ilPropertyFormGUI $a_form, ilIndividualAssessmentMember $member)
Fill form with current grading informations.
setInfo($a_info)
Set Information Text.
initGradingForm($may_be_edited=true, $amend=false)
Inint form for gradings.
mayBeAmended()
Grading may be edited by current user after finalization.
mayBeViewed()
Content of grading may be viewes by current user.
Class for single dates.
if(isset($_POST['submit'])) $form
withNotify($notify)
Clone this object and set wether the examinee should be notified.
withEventTime($event_time)
Clone this object and set an internal note.
special template class to simplify handling of ITX/PEAR
targetWasEditedByOtherUser(ilIndividualAssessmentMember $member)
Grading was edited by an other user.
This class represents a text property in a property form.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
$post
Definition: post.php:34
amend($form=null)
Show grading form to amend the result.
clearTargets()
clear all targets
saveMember(array $post, $keep_examiner=false, $amend=false)
Save grading informations.
setOptions($a_options)
Set Options.
$txt
Definition: error.php:11
viewFile()
Can user see the uploaded file.
finalizeConfirmation()
Save grading informations and show confirmation form.
withExaminerId($examiner_id)
Clone this object and set an examiner_id.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Edit the record of a user, set LP.
notify()
Will the user be notified after finalization?
name()
Get the examinee name corresponding to this membership.
if(!empty($this->data['faventry'])) $tabs
Definition: disco.tpl.php:124
cancelFinalize()
Cancel finalizing and get back to edit form.
const IL_CAL_DATE
This class represents a non editable value in a property form.
This class represents a text area property in a property form.
renderForm(ilPropertyFormGUI $form)
Render the form and put it into template.
mayBeEdited()
Grading may be edited by current user.
redirect($cmd)
Redirect to this with command.
save()
Save grading informations for user.
setDisabled($a_disabled)
Set Disabled.
$_POST["username"]
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
$html
Definition: example_001.php:87
LPStatus()
Get the LP-status corresponding to this membership.
setShowTime($a_showtime)
Set Show Time Information.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Confirmation screen class.
userMayAmend()
Current user has permission to amend grading.
$data
Definition: bench.php:6