ILIAS  release_8 Revision v8.24
class.ilIndividualAssessmentMemberGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27use GuzzleHttp\Psr7\ServerRequest;
32use ILIAS\Data;
34
36{
37 public const CMD_VIEW = 'view';
38 public const CMD_EDIT = 'edit';
39 public const CMD_UPDATE = 'update';
40 public const CMD_FINALIZE = 'finalize';
41 public const CMD_FINALIZE_CONFIRMATION = 'finalizeConfirmation';
42 public const CMD_AMEND = 'amend';
43 public const CMD_SAVE_AMEND = "saveAmend";
44 public const CMD_DOWNLOAD_FILE = "downloadFile";
45
46 protected ilLanguage $lng;
48 protected ilObjUser $user;
49 protected Input\Factory $input_factory;
52 protected Refinery\Factory $refinery_factory;
55 protected ServerRequest $request;
65
66 public function __construct(
77 ServerRequest $request,
82 ILIAS\Refinery\Factory $refinery,
83 ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper,
85 ) {
87
88 $this->ctrl = $ctrl;
89 $this->lng = $lng;
90 $this->tpl = $tpl;
91 $this->user = $user;
92 $this->input_factory = $input_factory;
93 $this->messagebox_factory = $messagebox_factory;
94 $this->button_factory = $button_factory;
95 $this->refinery_factory = $refinery_factory;
96 $this->data_factory = $data_factory;
97 $this->renderer = $renderer;
98 $this->request = $request;
99 $this->notificator = $notificator;
100 $this->toolbar = $toolbar;
101 $this->object = $object;
102 $this->error_object = $error_object;
103 $this->refinery = $refinery;
104 $this->request_wrapper = $request_wrapper;
105 $this->date_formatter = $date_formatter;
106 }
107
108 public function executeCommand(): void
109 {
110 $cmd = $this->ctrl->getCmd();
111
112 switch ($cmd) {
113 case self::CMD_VIEW:
114 case self::CMD_UPDATE:
115 case self::CMD_EDIT:
118 case self::CMD_AMEND:
121 $this->$cmd();
122 break;
123 case AbstractCtrlAwareUploadHandler::CMD_UPLOAD:
124 case AbstractCtrlAwareUploadHandler::CMD_REMOVE:
125 case AbstractCtrlAwareUploadHandler::CMD_INFO:
126 parent::executeCommand();
127 break;
128 default:
129 throw new LogicException("Unknown command $cmd");
130 }
131 }
132
133 protected function view(): void
134 {
135 if (!$this->mayBeViewed()) {
136 $this->handleAccessViolation();
137 return;
138 }
139 $form = $this->buildForm('', false);
140 $this->tpl->setContent($this->renderer->render($form));
141 }
142
143 protected function edit(): void
144 {
145 if (!$this->mayBeEdited()) {
146 $this->handleAccessViolation();
147 return;
148 }
149
150 $this->setToolbar();
151 $form = $this->buildForm($this->getFormActionForCommand(self::CMD_UPDATE), true);
152 $this->tpl->setContent($this->renderer->render($form));
153 }
154
155 protected function update(): void
156 {
157 $form = $this
158 ->buildForm($this->getFormActionForCommand(self::CMD_UPDATE), true)
159 ->withRequest($this->request)
160 ;
161
163 $grading = $form->getData();
164 if (is_null($grading)) {
165 $this->tpl->setContent($this->renderer->render($form));
166 return;
167 }
168
169 $storage = $this->getUserFileStorage();
170 $storage->deleteAllFilesBut($grading->getFile());
171
172 if ($grading->isFinalized()) {
173 $not_finalized_grading = $grading->withFinalized(false);
174 $this->saveMember($not_finalized_grading);
175 $this->finalizeConfirmation();
176 return;
177 }
178
179 $this->saveMember($grading);
180
181 if ($this->getObject()->isActiveLP()) {
183 }
184
185 $this->tpl->setOnScreenMessage("success", $this->lng->txt('iass_membership_saved'), true);
186 $this->ctrl->redirectByClass(ilIndividualAssessmentMembersGUI::class, 'view');
187 }
188
189 protected function amend(): void
190 {
191 if (!$this->mayBeAmended()) {
192 $this->handleAccessViolation();
193 return;
194 }
195
196 $this->setToolbar();
197 $form = $this->buildForm($this->getFormActionForCommand(self::CMD_SAVE_AMEND), true, true);
198 $form->withSubmitCaption($this->lng->txt("save_amend"));
199 $this->tpl->setContent($this->renderer->render($form));
200 }
201
202 protected function getFormActionForCommand(string $cmd): string
203 {
204 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
205 $action = $this->ctrl->getFormAction($this, $cmd);
206 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
207
208 return $action;
209 }
210
211 protected function downloadFile(): void
212 {
213 $path = $this->getUserFileStorage()->getAbsolutePath();
214 $file_name = $this->getMember()->fileName();
215 ilFileDelivery::deliverFileLegacy($path . "/" . $file_name, $file_name);
216 }
217
218 protected function saveAmend(): void
219 {
220 if (!$this->mayBeAmended()) {
221 $this->handleAccessViolation();
222 return;
223 }
224
225 $form = $this
226 ->buildForm($this->ctrl->getFormAction($this, self::CMD_AMEND), true, true)
227 ->withRequest($this->request)
228 ;
229
230 $grading = $form->getData();
231
232 if (!is_null($grading)) {
233 $this->saveMember($grading, true, true);
234
235 $storage = $this->getUserFileStorage();
236 $storage->deleteAllFilesBut($grading->getFile());
237
238 if ($this->getObject()->isActiveLP()) {
240 }
241
242 $this->tpl->setOnScreenMessage("success", $this->lng->txt('iass_amend_saved'), true);
243 $this->ctrl->redirectByClass(ilIndividualAssessmentMembersGUI::class, 'view');
244 }
245 }
246
247 protected function buildForm(
248 string $form_action,
249 bool $may_be_edited,
250 bool $amend = false
251 ): ILIAS\UI\Component\Input\Container\Form\Form {
252 $date_format = $this->date_formatter->getUserDateFormat($this->user, false);
253
254 $section = $this->getMember()->getGrading()->toFormInput(
255 $this->input_factory->field(),
256 $this->data_factory,
257 $this->lng,
258 $this->refinery_factory,
259 $this,
260 $date_format,
261 $this->getPossibleLPStates(),
262 $may_be_edited,
263 $this->getObject()->getSettings()->isEventTimePlaceRequired(),
264 $amend
265 );
266
267 $form = $this->input_factory->container()->form()->standard($form_action, [$section]);
268 return $form->withAdditionalTransformation(
269 $this->refinery_factory->custom()->transformation(
270 function ($values) use ($amend) {
271 return array_shift($values);
272 }
273 )
274 );
275 }
276
277 protected function finalize(): void
278 {
279 if (!$this->mayBeEdited()) {
280 $this->handleAccessViolation();
281 return;
282 }
283
284 $member = $this->getMember();
285 if (!$member->mayBeFinalized()) {
286 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('iass_may_not_finalize'), true);
287 $this->redirect('edit');
288 return;
289 }
290
291 try {
292 $grading = $member->getGrading()->withFinalized(true);
293 $member = $member->withGrading($grading);
294 $this->getObject()->membersStorage()->updateMember($member);
296 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
297 $this->redirect('edit');
298 return;
299 }
300
301 if ($this->object->isActiveLP()) {
303 }
304
305 try {
306 $member->maybeSendNotification($this->notificator);
307 $this->ctrl->redirectByClass(ilIndividualAssessmentMembersGUI::class, 'view');
309 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
310 $this->redirect('edit');
311 return;
312 }
313
314 $this->tpl->setOnScreenMessage("success", $this->lng->txt('iass_membership_finalized'), true);
315 $this->redirect('view');
316 }
317
318 protected function finalizeConfirmation(): void
319 {
320 if (!$this->mayBeEdited()) {
321 $this->handleAccessViolation();
322 return;
323 }
324
325 $message = $this->lng->txt('iass_finalize_user_qst');
326 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
327 $finalize = $this->ctrl->getFormActionByClass(self::class, self::CMD_FINALIZE);
328 $cancel = $this->ctrl->getFormActionByClass(self::class, self::CMD_EDIT);
329 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
330
331 $buttons = [
332 $this->button_factory->standard($this->lng->txt('iass_confirm_finalize'), $finalize),
333 $this->button_factory->standard($this->lng->txt('iass_cancel'), $cancel)
334 ];
335
336 $message_box = $this->messagebox_factory->confirmation($message)->withButtons($buttons);
337
338 $this->tpl->setContent($this->renderer->render($message_box));
339 }
340
341 protected function saveMember(
343 bool $keep_examiner = false,
344 bool $amend = false
345 ): void {
346 $member = $this->getMember()
347 ->withGrading($grading)
348 ;
349
350 if ($amend) {
351 $member = $member->withChangerId($this->user->getId());
352 }
353
354 if (!$keep_examiner) {
355 $member = $member->withExaminerId($this->user->getId());
356 }
357 $this->getObject()->membersStorage()->updateMember($member);
358 }
359
360 protected function getPossibleLPStates(): array
361 {
362 return [
363 ilIndividualAssessmentMembers::LP_IN_PROGRESS => $this->lng->txt('iass_status_pending'),
364 ilIndividualAssessmentMembers::LP_COMPLETED => $this->lng->txt('iass_status_completed'),
365 ilIndividualAssessmentMembers::LP_FAILED => $this->lng->txt('iass_status_failed')
366 ];
367 }
368
369 protected function getUploadResult(): HandlerResult
370 {
371 $this->upload->process();
372 $array = $this->upload->getResults();
373 $result = end($array);
374
375 $storage = $this->getUserFileStorage();
376 $storage->create();
377
378 if ($result instanceof UploadResult && $result->isOK()) {
379 $identifier = $storage->uploadFile($result);
380 $status = HandlerResult::STATUS_OK;
381 $message = 'Upload ok';
382 } else {
383 $status = HandlerResult::STATUS_FAILED;
384 $identifier = '';
385 $message = $result->getStatus()->getMessage();
386 }
387
388 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
389 }
390
391 protected function getRemoveResult(string $identifier): HandlerResult
392 {
393 $status = HandlerResult::STATUS_OK;
394 $message = $this->lng->txt('iass_file_deleted');
395
396 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
397 }
398
399 public function getInfoResult(string $identifier): FileInfoResult
400 {
401 $storage = $this->getUserFileStorage();
402 $path = $storage->getAbsolutePath() . "/" . $identifier;
403 return new BasicFileInfoResult(
404 $this->getFileIdentifierParameterName(),
405 $identifier,
406 $identifier,
407 filesize($path),
408 pathinfo($path, PATHINFO_EXTENSION)
409 );
410 }
411
412 public function getInfoForExistingFiles(array $file_ids): array
413 {
414 $file_ids = array_filter($file_ids, fn ($id) => $id !== "");
415 $path = $this->getUserFileStorage()->getAbsolutePath();
416 return array_map(function ($id) use ($path) {
417 return new BasicFileInfoResult(
418 $this->getFileIdentifierParameterName(),
419 $id,
420 $id,
421 filesize($path . "/" . $id),
422 pathinfo($path . "/" . $id, PATHINFO_EXTENSION)
423 );
424 }, $file_ids);
425 }
426
427 public function getFileIdentifierParameterName(): string
428 {
429 return 'iass';
430 }
431
432 public function getUploadURL(): string
433 {
434 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
435 $link = $this->ctrl->getLinkTarget($this, self::CMD_UPLOAD);
436 $this->ctrl->setParameter($this, 'usr_id', null);
437
438 return $link;
439 }
440
441 public function getExistingFileInfoURL(): string
442 {
443 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
444 $link = $this->ctrl->getLinkTarget($this, self::CMD_INFO);
445 $this->ctrl->setParameter($this, 'usr_id', null);
446
447 return $link;
448 }
449
450 protected function redirect(string $cmd): void
451 {
452 $this->ctrl->setParameterByClass(self::class, 'usr_id', $this->getExaminee()->getId());
453 $this->ctrl->redirect($this, $cmd);
454 }
455
456 public function setObject(ilObjIndividualAssessment $object): void
457 {
458 $this->object = $object;
459 }
460
462 {
463 return $this->object;
464 }
465
466 public function setParentGUI(ilIndividualAssessmentMembersGUI $parent_gui): void
467 {
468 $this->parent_gui = $parent_gui;
469 }
470
472 {
473 return $this->parent_gui;
474 }
475
477 {
478 if (is_null($this->iass_access)) {
479 $this->iass_access = $this->getObject()->accessHandler();
480 }
481 return $this->iass_access;
482 }
483
484 protected function getExaminee(): ilObjUser
485 {
486 return new ilObjUser($this->request_wrapper->retrieve('usr_id', $this->refinery->kindlyTo()->int()));
487 }
488
490 {
491 $storage = $this->getObject()->getFileStorage();
492 $storage->setUserId($this->getExaminee()->getId());
493 return $storage;
494 }
495
497 {
498 return $this->getObject()->membersStorage()->loadMember(
499 $this->getObject(),
500 $this->getExaminee()
501 );
502 }
503
504 protected function setToolbar(): void
505 {
506 $member = $this->getMember();
507 if ($member->fileName() != '') {
509 $btn->setCaption('download_assessment_paper');
510 $this->ctrl->setParameter($this, 'usr_id', $this->getExaminee()->getId());
511 $btn->setUrl($this->ctrl->getLinkTarget($this, self::CMD_DOWNLOAD_FILE, "", false, true));
512 $this->ctrl->setParameter($this, 'usr_id', null);
513 $this->toolbar->addButtonInstance($btn);
514 }
515 }
516
517 protected function mayBeEdited(): bool
518 {
519 return $this->getAccessHandler()->isSystemAdmin() || (!$this->isFinalized() && $this->userMayGrade());
520 }
521
522 protected function mayBeViewed(): bool
523 {
524 return
525 $this->getAccessHandler()->isSystemAdmin() ||
526 ($this->isFinalized() && ($this->userMayGrade() || $this->userMayView()))
527 ;
528 }
529
530 protected function mayBeAmended(): bool
531 {
532 return $this->getAccessHandler()->isSystemAdmin() || ($this->isFinalized() && $this->userMayAmend());
533 }
534
535 protected function userMayGrade(): bool
536 {
537 return
538 $this->getAccessHandler()->isSystemAdmin() ||
539 (!$this->targetWasEditedByOtherUser($this->getMember()) && $this->getAccessHandler()->mayGradeUser($this->getMember()->id()))
540 ;
541 }
542
543 protected function userMayView(): bool
544 {
545 return $this->getAccessHandler()->mayViewUser($this->getMember()->id());
546 }
547
548 protected function userMayAmend(): bool
549 {
550 return $this->getAccessHandler()->mayAmendAllUsers();
551 }
552
554 {
555 return
556 (int) $member->examinerId() !== $this->user->getId() &&
557 0 !== (int) $member->examinerId()
558 ;
559 }
560
561 protected function isFinalized(): bool
562 {
563 return $this->getMember()->finalized();
564 }
565
566 public function handleAccessViolation(): void
567 {
568 $this->error_object->raiseError($this->lng->txt("msg_no_perm_read"), $this->error_object->WARNING);
569 }
570}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds a Color from either hex- or rgb values.
Definition: Factory.php:17
Builds data types.
Definition: Factory.php:21
Class ilCtrl provides processing control methods.
Error Handling & global info handling uses PEAR error class.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Handles the file upload and folder creation for files uploaded in grading form.
setUserId(int $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)
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
ilIndividualAssessmentDateFormatter $date_formatter
__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, ILIAS\Refinery\Factory $refinery, ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper, ilIndividualAssessmentDateFormatter $date_formatter)
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.
ilIndividualAssessmentPrimitiveInternalNotificator $notificator
targetWasEditedByOtherUser(ilIndividualAssessmentMember $member)
ilIndividualAssessmentAccessHandler $iass_access
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
This describes commonalities between all inputs.
Definition: Input.php:49
This is how a factory for Message Boxes looks like.
Definition: Factory.php:27
An entity that renders components to a string output.
Definition: Renderer.php:31
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$message
Definition: xapiexit.php:32