19declare(strict_types=1);
27use GuzzleHttp\Psr7\Request;
61 private Request $request,
63 private UIFactory $ui_factory,
64 private UIRenderer $ui_renderer,
69 $uri = ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTargetByClass([\ilRepositoryGUI::class, \ilObjTestGUI::class, self::class], self::DEFAULT_CMD);
71 (
new DataFactory())->uri($uri)
76 $this->action_parameter_token,
79 [
'marks',
'overview_table'],
87 $cmd = $this->
ctrl->getCmd(self::DEFAULT_CMD);
91 protected function showMarkSchema(?RoundTripModal $add_mark_modal =
null): void
93 if (!$this->editable) {
94 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'cannot_edit_marks'));
99 if ($add_mark_modal ===
null) {
108 $this->action_parameter_token,
117 $this->tpl->setContent(
118 $this->ui_renderer->render([
119 $mark_schema_table->getTable()->withRequest($this->request),
131 $data = $modal->getData();
132 if (
$data ===
null) {
133 $this->
showMarkSchema($modal->withOnLoad($modal->getShowSignal()));
137 $mark_steps = $this->mark_schema->getMarkSteps();
140 if (is_string($new_schema)) {
141 $this->tpl->setOnScreenMessage(
'failure', $new_schema);
145 $this->mark_schema = $new_schema;
146 $this->test->storeMarkSchema(
149 $this->test->onMarkSchemaSaved();
150 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
152 if ($this->
logger->isLoggingEnabled()) {
153 $this->
logger->logTestAdministrationInteraction(
154 $this->
logger->getInteractionFactory()->buildTestAdministrationInteraction(
155 $this->test->getRefId(),
156 $this->active_user->getId(),
157 TestAdministrationInteractionTypes::MARK_SCHEMA_MODIFIED,
158 $this->mark_schema->toLog($this->logger->getAdditionalInformationGenerator())
170 $this->mark_schema = $this->
factory->createSimpleSchema(
171 $this->mark_schema->getTestId(),
172 $this->lng->txt(
'failed_short'),
173 $this->lng->txt(
'failed_official'),
176 $this->lng->txt(
'passed_short'),
177 $this->lng->txt(
'passed_official'),
181 $this->test->storeMarkSchema($this->mark_schema);
182 if ($this->
logger->isLoggingEnabled()) {
183 $this->
logger->logTestAdministrationInteraction(
184 $this->
logger->getInteractionFactory()->buildTestAdministrationInteraction(
185 $this->test->getRefId(),
186 $this->active_user->getId(),
187 TestAdministrationInteractionTypes::MARK_SCHEMA_RESET,
199 if (!$this->post_wrapper->has(
'interruptive_items')) {
204 $marks_to_be_deleted = $this->post_wrapper->retrieve(
205 'interruptive_items',
206 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
210 if (is_string($new_schema)) {
211 $this->tpl->setOnScreenMessage(
'failure', $new_schema);
216 $this->mark_schema = $new_schema;
217 $this->test->storeMarkSchema($new_schema);
219 if ($this->
logger->isLoggingEnabled()) {
220 $this->
logger->logTestAdministrationInteraction(
221 $this->
logger->getInteractionFactory()->buildTestAdministrationInteraction(
222 $this->test->getRefId(),
223 $this->active_user->getId(),
224 TestAdministrationInteractionTypes::MARK_SCHEMA_MODIFIED,
225 $this->mark_schema->toLog($this->logger->getAdditionalInformationGenerator())
235 return $this->ui_factory->modal()->interruptive(
236 $this->
lng->txt(
'tst_mark_reset_to_simple_mark_schema'),
237 $this->lng->txt(
'tst_mark_reset_to_simple_mark_schema_confirmation'),
238 $this->ctrl->getFormActionByClass(MarkSchemaGUI::class,
'resetToSimpleMarkSchema')
239 )->withActionButtonLabel($this->
lng->txt(
'tst_mark_reset_to_simple_mark_schema'));
244 $title_lng_var =
'edit';
245 if ($mark ===
null) {
246 $title_lng_var =
'create';
249 return $this->ui_factory->modal()->roundtrip(
250 $this->
lng->txt($title_lng_var),
253 'mark' => $mark->toForm(
255 $this->ui_factory->input()->field(),
259 'index' => $this->ui_factory->input()->field()->hidden()
260 ->withValue($mark_index)
262 $this->ctrl->getFormActionByClass(MarkSchemaGUI::class,
'saveMark')
266 private function editMark(array $affected_marks): void
270 $affected_mark = current($affected_marks);
271 $mark_steps = $this->mark_schema->getMarkSteps();
272 $this->response_handler->sendAsync(
273 $this->ui_renderer->renderAsync(
274 $this->buildMarkModal($mark_steps[$affected_mark], $affected_mark)
279 private function populateToolbar(InterruptiveModal $confirmation_modal, RoundTripModal $add_mark_modal): void
281 if (!$this->editable) {
284 $create_simple_schema_button = $this->ui_factory->button()->standard(
285 $this->
lng->txt(
'tst_mark_reset_to_simple_mark_schema'),
286 $confirmation_modal->getShowSignal()
288 $this->
toolbar->addComponent($create_simple_schema_button);
290 $add_mark_button = $this->ui_factory->button()->standard(
291 $this->
lng->txt(
'tst_mark_create_new_mark_step'),
292 $add_mark_modal->getShowSignal()
294 $this->
toolbar->addComponent($add_mark_button);
300 if (!$this->editable || $action ===
null) {
305 if ($affected_marks ===
null) {
306 $this->response_handler->sendAsync(
307 $this->ui_renderer->renderAsync(
308 $this->ui_factory->modal()->roundtrip(
309 $this->lng->txt(
'error'),
310 $this->ui_factory->messageBox()->failure($this->lng->txt(
'tst_delete_missing_mark'))
332 $confirm_delete_modal = $this->ui_factory->modal()->interruptive(
333 $this->
lng->txt(
'confirm'),
334 $this->lng->txt(
'delete_mark_confirmation'),
335 $this->ctrl->getFormActionByClass(MarkSchemaGUI::class,
'deleteMarkSteps')
336 )->withActionButtonLabel($this->
lng->txt(
'delete'))
339 $this->response_handler->sendAsync(
340 $this->ui_renderer->renderAsync($confirm_delete_modal)
346 $mark_steps = $this->mark_schema->getMarkSteps();
347 $marks_to_be_deleted = [];
348 foreach ($affected_marks as $affected_mark) {
349 $marks_to_be_deleted[] = $this->ui_factory->modal()->interruptiveItem()->standard(
350 (
string) $affected_mark,
351 $mark_steps[$affected_mark]->getOfficialName()
354 return $marks_to_be_deleted;
359 $param = $this->action_parameter_token->getName();
360 if (!$this->request_wrapper->has(
$param)) {
363 $trafo = $this->
refinery->byTrying([
364 $this->
refinery->kindlyTo()->null(),
365 $this->refinery->kindlyTo()->string()
367 return $this->request_wrapper->retrieve(
$param, $trafo);
372 $affected_marks = $this->request_wrapper->retrieve(
373 $this->row_id_token->getName(),
374 $this->refinery->byTrying([
375 $this->refinery->kindlyTo()->int(),
376 $this->refinery->container()->mapValues(
377 $this->refinery->kindlyTo()->int()
379 $this->refinery->identity()
383 if (is_int($affected_marks)) {
384 $affected_marks = [$affected_marks];
387 return $affected_marks;
392 if ($this->editable) {
396 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
397 $this->
ctrl->redirect($this,
'showMarkSchema');
402 if ($this->editable) {
406 $this->response_handler->sendAsync(
407 $this->ui_renderer->renderAsync(
408 $this->ui_factory->modal()->roundtrip(
409 $this->lng->txt(
'error'),
410 $this->ui_factory->messageBox()->failure($this->lng->txt(
'permission_denied'))
420 foreach ($marks_to_delete as $mark) {
421 unset($new_marks[$mark]);
425 $this->mark_schema->withMarkSteps(array_values($new_marks))
431 if (!is_string($checked_value)) {
432 return $checked_value;
435 $this->response_handler->sendAsync(
436 $this->ui_renderer->render(
437 $this->ui_factory->modal()->roundtrip(
438 $this->lng->txt(
'error'),
439 $this->ui_factory->messageBox()->failure($checked_value)
449 $messages[] = $this->
lng->txt(
'no_passed_mark');
452 $messages[] = $this->
lng->txt(
'min_percentage_ne_0');
455 $messages[] = $this->
lng->txt(
'no_passed_after_failed');
458 if (isset($messages[1])) {
459 $messages[0] .=
'<br>' . $messages[1];
462 if ($messages === []) {
Builds a Color from either hex- or rgb values.
resetToSimpleMarkSchema()
URLBuilderToken $action_parameter_token
removeMarksAndCheckNewSchema(array $marks_to_delete)
editMark(array $affected_marks)
getTableActionQueryString()
populateToolbar(InterruptiveModal $confirmation_modal, RoundTripModal $add_mark_modal)
URLBuilderToken $row_id_token
redirectOnMarkSchemaNotEditable()
buildResetConfirmationModal()
buildMarkModal(?Mark $mark=null, int $mark_index=-1)
exitOnMarkSchemaNotEditable()
getTableAffectedItemsFromQuery()
__construct(private \ilObjTest $test, private \ilObjUser $active_user, private \ilLanguage $lng, private \ilCtrlInterface $ctrl, private \ilGlobalTemplateInterface $tpl, private \ilToolbarGUI $toolbar, private TestLogger $logger, private RequestWrapper $post_wrapper, private RequestWrapper $request_wrapper, private ResponseHandler $response_handler, private Request $request, private Refinery $refinery, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private MarkSchemaFactory $factory,)
showMarkSchema(?RoundTripModal $add_mark_modal=null)
confirmMarkDeletion(array $marks_to_delete)
exitOnSchemaError(MarkSchema|string $checked_value)
buildInteruptiveItems(array $affected_marks)
checkSchemaForErrors(MarkSchema $new_schema)
A class defining mark schemas for assessment test objects.
checkForMissingZeroPercentage()
checkForFailedAfterPassed()
A class defining marks for assessment test objects.
acquireParameters(array $namespace, string ... $names)
Interface RequestWrapper.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
TestAdministrationInteractionTypes
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...