ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilIndividualAssessmentMemberGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4declare(strict_types=1);
5
12use GuzzleHttp\Psr7\ServerRequest;
17use ILIAS\Data;
19
21{
22 const CMD_VIEW = 'view';
23 const CMD_EDIT = 'edit';
24 const CMD_UPDATE = 'update';
25 const CMD_FINALIZE = 'finalize';
26 const CMD_FINALIZE_CONFIRMATION = 'finalizeConfirmation';
27 const CMD_AMEND = 'amend';
28 const CMD_SAVE_AMEND = "saveAmend";
29 const CMD_DOWNLOAD_FILE = "downloadFile";
30
34 protected $ctrl;
35
39 protected $lng;
40
44 protected $tpl;
45
49 protected $user;
50
54 protected $input_factory;
55
60
64 protected $button_factory;
65
70
74 protected $data_factory;
75
79 protected $renderer;
80
84 protected $request;
85
89 protected $object;
90
94 protected $parent_gui;
95
99 protected $iass_access;
100
104 protected $notificator;
105
109 protected $toolbar;
110
114 protected $error_object;
115
116 public function __construct(
124 Refinery\Factory $refinery_factory,
127 ServerRequest $request,
132 ) {
134
135 $this->ctrl = $ctrl;
136 $this->lng = $lng;
137 $this->tpl = $tpl;
138 $this->user = $user;
139 $this->input_factory = $input_factory;
140 $this->messagebox_factory = $messagebox_factory;
141 $this->button_factory = $button_factory;
142 $this->refinery_factory = $refinery_factory;
143 $this->data_factory = $data_factory;
144 $this->renderer = $renderer;
145 $this->request = $request;
146 $this->notificator = $notificator;
147 $this->toolbar = $toolbar;
148 $this->object = $object;
149 $this->error_object = $error_object;
150 }
151
152 public function executeCommand() : void
153 {
154 $cmd = $this->ctrl->getCmd();
155
156 switch ($cmd) {
157 case self::CMD_VIEW:
158 case self::CMD_UPDATE:
159 case self::CMD_EDIT:
162 case self::CMD_AMEND:
165 $this->$cmd();
166 break;
167 case AbstractCtrlAwareUploadHandler::CMD_UPLOAD:
168 case AbstractCtrlAwareUploadHandler::CMD_REMOVE:
169 case AbstractCtrlAwareUploadHandler::CMD_INFO:
170 parent::executeCommand();
171 break;
172 default:
173 throw new LogicException("Unknown command $cmd");
174 }
175 }
176
177 protected function view()
178 {
179 if (!$this->mayBeViewed()) {
180 $this->handleAccessViolation();
181 return;
182 }
183 $form = $this->buildForm('', false);
184 $this->tpl->setContent($this->renderer->render($form));
185 }
186
187 protected function edit()
188 {
189 if (!$this->mayBeEdited()) {
190 $this->handleAccessViolation();
191 return;
192 }
193
194 $this->setToolbar();
195 $form = $this->buildForm($this->getFormActionForCommand(self::CMD_UPDATE), true);
196 $this->tpl->setContent($this->renderer->render($form));
197 }
198
199 protected function update()
200 {
201 $form = $this
202 ->buildForm($this->getFormActionForCommand(self::CMD_UPDATE), true)
203 ->withRequest($this->request)
204 ;
205
207 $grading = $form->getData();
208 if (is_null($grading)) {
209 $this->tpl->setContent($this->renderer->render($form));
210 return;
211 }
212
213 if ($grading->getFile() == '') {
214 $storage = $this->getUserFileStorage();
215 $storage->deleteCurrentFile();
216 }
217
218 if ($grading->isFinalized()) {
219 $not_finalized_grading = $grading->withFinalized(false);
220 $this->saveMember($not_finalized_grading);
221 $this->finalizeConfirmation();
222 return;
223 }
224
225 $this->saveMember($grading);
226
227 if ($this->getObject()->isActiveLP()) {
229 }
230
231 ilUtil::sendSuccess($this->lng->txt('iass_membership_saved'), true);
232 $this->redirect(self::CMD_EDIT);
233
234 }
235
236 protected function amend()
237 {
238 if (!$this->mayBeAmended()) {
239 $this->handleAccessViolation();
240 return;
241 }
242
243 $this->setToolbar();
244 $form = $this->buildForm($this->getFormActionForCommand(self::CMD_SAVE_AMEND), true, true);
245 $this->tpl->setContent($this->renderer->render($form));
246 }
247
248 protected function getFormActionForCommand(string $cmd) : string
249 {
250 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
251 $action = $this->ctrl->getFormAction($this, $cmd);
252 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
253
254 return $action;
255 }
256
257 protected function downloadFile()
258 {
259 $path = $this->getUserFileStorage()->getFilePath();
260 $file_name = $this->getMember()->fileName();
261 ilUtil::deliverFile($path, $file_name);
262 }
263
264 protected function saveAmend()
265 {
266 if (!$this->mayBeAmended()) {
267 $this->handleAccessViolation();
268 return;
269 }
270
271 $form = $this
272 ->buildForm($this->ctrl->getFormAction($this, self::CMD_AMEND), true, true)
273 ->withRequest($this->request)
274 ;
275
276 $grading = $form->getData();
277
278 if (!is_null($grading)) {
279 if ($grading->getFile() == '') {
280 $storage = $this->getUserFileStorage();
281 $storage->deleteCurrentFile();
282 }
283
284 $this->saveMember($grading, true, true);
285
286 if ($this->getObject()->isActiveLP()) {
288 }
289
290 ilUtil::sendSuccess($this->lng->txt('iass_amend_saved'), true);
291 $this->redirect(self::CMD_AMEND);
292 }
293 }
294
295 protected function buildForm(
296 string $form_action,
297 bool $may_be_edited,
298 bool $amend = false
299 ) : ILIAS\UI\Component\Input\Container\Form\Form {
300 $section = $this->getMember()->getGrading()->toFormInput(
301 $this->input_factory->field(),
302 $this->data_factory,
303 $this->lng,
304 $this->refinery_factory,
305 $this->getPossibleLPStates(),
306 $may_be_edited,
307 (bool) $this->getObject()->getSettings()->isEventTimePlaceRequired(),
308 $amend,
309 $this
310 );
311
312 $form = $this->input_factory->container()->form()->standard($form_action, [$section]);
313 $form = $form->withAdditionalTransformation(
314 $this->refinery_factory->custom()->transformation(
315 function ($values) use ($amend) {
316 return array_shift($values);
317 }
318 )
319 );
320 return $form;
321 }
322
323 protected function finalize() : void
324 {
325 if (!$this->mayBeEdited()) {
326 $this->handleAccessViolation();
327 return;
328 }
329
330 $member = $this->getMember();
331 if (!$member->mayBeFinalized()) {
332 ilUtil::sendFailure($this->lng->txt('iass_may_not_finalize'), true);
333 $this->redirect('edit');
334 return;
335 }
336
337 try {
338 $grading = $member->getGrading()->withFinalized(true);
339 $member = $member->withGrading($grading);
340 $this->getObject()->membersStorage()->updateMember($member);
342 ilUtil::sendFailure($e->getMessage(), true);
343 $this->redirect('edit');
344 return;
345 }
346
347 if ($this->object->isActiveLP()) {
349 }
350
351 try {
352 $member->maybeSendNotification($this->notificator);
354 ilUtil::sendFailure($e->getMessage(), true);
355 $this->redirect('edit');
356 return;
357 }
358
359 ilUtil::sendSuccess($this->lng->txt('iass_membership_finalized'), true);
360 $this->redirect('view');
361 }
362
363 protected function finalizeConfirmation()
364 {
365 if (!$this->mayBeEdited()) {
366 $this->handleAccessViolation();
367 return;
368 }
369
370 $message = $this->lng->txt('iass_finalize_user_qst');
371 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
372 $finalize = $this->ctrl->getFormActionByClass(self::class, self::CMD_FINALIZE);
373 $cancel = $this->ctrl->getFormActionByClass(self::class, self::CMD_EDIT);
374 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
375
376 $buttons = [
377 $this->button_factory->standard($this->lng->txt('iass_confirm_finalize'), $finalize),
378 $this->button_factory->standard($this->lng->txt('iass_cancel'), $cancel)
379 ];
380
381 $message_box = $this->messagebox_factory->confirmation($message)->withButtons($buttons);
382
383 $this->tpl->setContent($this->renderer->render($message_box));
384 }
385
386 protected function saveMember(
388 bool $keep_examiner = false,
389 bool $amend = false
390 ) : void {
391 $member = $this->getMember()
392 ->withGrading($grading)
393 ;
394
395 if ($amend) {
396 $member = $member->withChangerId($this->user->getId());
397 }
398
399 if (!$keep_examiner) {
400 $member = $member->withExaminerId($this->user->getId());
401 }
402 $this->getObject()->membersStorage()->updateMember($member);
403 }
404
405 protected function getPossibleLPStates() : array
406 {
407 return [
408 ilIndividualAssessmentMembers::LP_IN_PROGRESS => $this->lng->txt('iass_status_pending'),
409 ilIndividualAssessmentMembers::LP_COMPLETED => $this->lng->txt('iass_status_completed'),
410 ilIndividualAssessmentMembers::LP_FAILED => $this->lng->txt('iass_status_failed')
411 ];
412 }
413
414 protected function getUploadResult() : HandlerResult
415 {
416 $this->upload->process();
417 $array = $this->upload->getResults();
418 $result = end($array);
419
420 if ($result instanceof UploadResult && $result->isOK()) {
421 $identifier = $this->uploadFile($result);
422 $status = HandlerResult::STATUS_OK;
423 $message = 'Upload ok';
424 } else {
425 $status = HandlerResult::STATUS_FAILED;
426 $identifier = '';
427 $message = $result->getStatus()->getMessage();
428 }
429
430 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
431 }
432
433 protected function getRemoveResult(string $identifier) : HandlerResult
434 {
435 $status = HandlerResult::STATUS_FAILED;
436 $message = $this->lng->txt('iass_file_deleted');
437
438 if ($this->getFileName() == $identifier) {
439 $this->deleteFile();
440 $member = $this->getMember();
441 $grading = $member->getGrading()->withFile(null);
442 $member = $member->withGrading($grading);
443 $this->getObject()->membersStorage()->updateMember($member);
444 $status = HandlerResult::STATUS_OK;
445 $message = 'File Deleted';
446 }
447
448 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
449 }
450
454 protected function getInfoResult(string $identifier) : FileInfoResult
455 {
456 $filename = $this->getFileName();
457 if ($filename != $identifier) {
458 throw new LogicException("Wrong filename $identifier");
459 }
460
461 $file_size = filesize($this->getFilePath());
462 return new BasicFileInfoResult(
463 $this->getFileIdentifierParameterName(),
464 $identifier,
465 $filename,
466 $file_size,
467 pathinfo($filename, PATHINFO_EXTENSION)
468 );
469 }
470
474 public function getInfoForExistingFiles(array $file_ids) : array
475 {
476 $name = $this->getFileName();
477
478 $ids = array_filter($file_ids, function ($id) {
479 if ($id == "") {
480 return false;
481 }
482 return true;
483 });
484
485 if (is_null($name) || count($ids) === 0) {
486 return [];
487 }
488
489 if (!in_array($name, $file_ids)) {
490 throw new LogicException("Wrong filename " . $this->getFileName());
491 }
492
493 return [
495 $this->getFileIdentifierParameterName(),
496 "identifier",
497 $name,
498 64,
499 ''
500 )
501 ];
502 }
503
507 public function getFileIdentifierParameterName() : string
508 {
509 return 'iass';
510 }
511
515 public function getUploadURL() : string
516 {
517 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
518 $link = $this->ctrl->getLinkTarget($this, self::CMD_UPLOAD);
519 $this->ctrl->setParameter($this, 'usr_id', null);
520
521 return $link;
522 }
523
527 public function getExistingFileInfoURL() : string
528 {
529 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
530 $link = $this->ctrl->getLinkTarget($this, self::CMD_INFO);
531 $this->ctrl->setParameter($this, 'usr_id', null);
532
533 return $link;
534 }
535
539 public function getFileRemovalURL() : string
540 {
541 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
542 $this->ctrl->setParameter($this, $this->getFileIdentifierParameterName(), $this->getFileName());
543 $link = $this->ctrl->getLinkTarget($this, self::CMD_REMOVE);
544 $this->ctrl->setParameter($this, 'usr_id', null);
545 $this->ctrl->setParameter($this, $this->getFileIdentifierParameterName(), null);
546
547 return $link;
548 }
549
550 protected function uploadFile(UploadResult $result) : string
551 {
552 $storage = $this->getUserFileStorage();
553 $storage->create();
554 $storage->deleteCurrentFile();
555 $storage->uploadFile($result);
556
557 return $storage->getFileName();
558 }
559
560 protected function deleteFile()
561 {
562 $storage = $this->getUserFileStorage();
563 $storage->deleteCurrentFile();
564 }
565
566 protected function getFileName() : ?string
567 {
568 $path = $this->getFilePath();
569 if (is_null($path)) {
570 return null;
571 }
572
573 return end(explode('/', $path));
574 }
575
576 protected function getFilePath() : ?string
577 {
578 $storage = $this->getUserFileStorage();
579 if ($storage->isEmpty()) {
580 return null;
581 }
582
583 return $storage->getFilePath();
584 }
585
586 protected function redirect(string $cmd) : void
587 {
588 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
589 $this->ctrl->redirect($this, $cmd);
590 }
591
592 public function setObject(ilObjIndividualAssessment $object) : void
593 {
594 $this->object = $object;
595 }
596
598 {
599 return $this->object;
600 }
601
602 public function setParentGUI(ilIndividualAssessmentMembersGUI $parent_gui) : void
603 {
604 $this->parent_gui = $parent_gui;
605 }
606
608 {
609 return $this->parent_gui;
610 }
611
613 {
614 if (is_null($this->iass_access)) {
615 $this->iass_access = $this->getObject()->accessHandler();
616 }
617 return $this->iass_access;
618 }
619
620 protected function getExaminee()
621 {
622 return new ilObjUser($_GET['usr_id']);
623 }
624
626 {
627 $storage = $this->getObject()->getFileStorage();
628 $storage->setUserId($this->getExaminee()->getId());
629 return $storage;
630 }
631
633 {
634 return $this->getObject()->membersStorage()->loadMember(
635 $this->getObject(),
636 $this->getExaminee()
637 );
638 }
639
640 protected function setToolbar()
641 {
642 $member = $this->getMember();
643 if ($member->fileName() != '') {
645 $btn->setCaption('download_assessment_paper');
646 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
647 $btn->setUrl($this->ctrl->getLinkTarget($this, self::CMD_DOWNLOAD_FILE, false, true));
648 $this->ctrl->setParameter($this, 'usr_id', null);
649 $this->toolbar->addButtonInstance($btn);
650 }
651 }
652
653 protected function mayBeEdited() : bool
654 {
655 return $this->getAccessHandler()->isSystemAdmin() || (!$this->isFinalized() && $this->userMayGrade());
656 }
657
658 protected function mayBeViewed() : bool
659 {
660 return
661 $this->getAccessHandler()->isSystemAdmin() ||
662 ($this->isFinalized() && ($this->userMayGrade() || $this->userMayView()))
663 ;
664 }
665
666 protected function mayBeAmended() : bool
667 {
668 return $this->getAccessHandler()->isSystemAdmin() || ($this->isFinalized() && $this->userMayAmend());
669 }
670
671 protected function userMayGrade() : bool
672 {
673 return
674 $this->getAccessHandler()->isSystemAdmin() ||
675 (!$this->targetWasEditedByOtherUser($this->getMember()) && $this->getAccessHandler()->mayGradeUser())
676 ;
677 }
678
679 protected function userMayView() : bool
680 {
681 return $this->getAccessHandler()->isSystemAdmin() || $this->getAccessHandler()->mayViewUser();
682 }
683
684 protected function userMayAmend() : bool
685 {
686 return $this->getAccessHandler()->isSystemAdmin() || $this->getAccessHandler()->mayAmendGradeUser();
687 }
688
690 {
691 return
692 (int) $member->examinerId() !== (int) $this->user->getId() &&
693 0 !== (int) $member->examinerId()
694 ;
695 }
696
697 protected function isFinalized() : bool
698 {
699 return $this->getMember()->finalized();
700 }
701
702 public function handleAccessViolation()
703 {
704 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
705 }
706}
$result
user()
Definition: user.php:4
$section
Definition: Utf8Test.php:83
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Builds a Color from either hex- or rgb values.
Definition: Factory.php:14
This class provides processing control methods.
Class ilGlobalPageTemplate.
Handles the fileupload and folder creation for files uploaded in grading form.
setUserId($user_id)
Set the user id for an extra folder of each participant in the IA.
static updateLPStatusOfMember(ilIndividualAssessmentMember $member)
buildForm(string $form_action, bool $may_be_edited, bool $amend=false)
__construct(ilCtrl $ctrl, ilLanguage $lng, ilGlobalPageTemplate $tpl, ilObjUser $user, Input\Factory $input_factory, MessageBox\Factory $messagebox_factory, Button\Factory $button_factory, Refinery\Factory $refinery_factory, Data\Factory $data_factory, Renderer $renderer, ServerRequest $request, ilIndividualAssessmentPrimitiveInternalNotificator $notificator, ilToolbarGUI $toolbar, ilObjIndividualAssessment $object, ilErrorHandling $error_object)
saveMember(ilIndividualAssessmentUserGrading $grading, bool $keep_examiner=false, bool $amend=false)
setParentGUI(ilIndividualAssessmentMembersGUI $parent_gui)
executeCommand()
Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.
targetWasEditedByOtherUser(ilIndividualAssessmentMember $member)
Edit the record of a user, set LP.
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
language handling
static getInstance()
Factory.
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
An entity that renders components to a string output.
Definition: Renderer.php:15
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$message
Definition: xapiexit.php:14