ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction Class Reference
+ Inheritance diagram for ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction:
+ Collaboration diagram for ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction:

Public Member Functions

 __construct (private readonly Language $lng, private readonly UIFactory $ui_factory, private readonly \ilTestQuestionSetConfigFactory $question_set_config_factory, private readonly GlobalTemplate $tpl, private readonly \ilObjTest $test_obj, private readonly PersonalSettingsRepository $repository, private readonly MainSettingsRepository $main_settings_repository, private readonly ScoreSettingsRepository $score_settings_repository, private readonly MarksRepository $marks_repository,)
 
 getActionId ()
 
 buildTableAction (URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
 
 buildModal (URLBuilder $url_builder, array $selected_templates)
 
 onSubmit (URLBuilder $url_builder, ServerRequestInterface $request, array $selected_templates,)
 
 getActionId ()
 
 buildTableAction (URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
 
 buildModal (URLBuilder $url_builder, array $selected_templates)
 
 onSubmit (URLBuilder $url_builder, ServerRequestInterface $request, array $selected_templates,)
 

Data Fields

const string ACTION_ID = 'apply_template'
 

Private Member Functions

 checkSelectedTemplate (array $selected_templates)
 
 hasDifferentQuestionSetType (int $template_settings_id)
 

Detailed Description

Definition at line 36 of file PersonalSettingsTableApplyAction.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::__construct ( private readonly Language  $lng,
private readonly UIFactory  $ui_factory,
private readonly \ilTestQuestionSetConfigFactory  $question_set_config_factory,
private readonly GlobalTemplate  $tpl,
private readonly \ilObjTest  $test_obj,
private readonly PersonalSettingsRepository  $repository,
private readonly MainSettingsRepository  $main_settings_repository,
private readonly ScoreSettingsRepository  $score_settings_repository,
private readonly MarksRepository  $marks_repository 
)

Definition at line 40 of file PersonalSettingsTableApplyAction.php.

50 {
51 }

Member Function Documentation

◆ buildModal()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::buildModal ( URLBuilder  $url_builder,
array  $selected_templates 
)
Parameters
array<PersonalSettingsTemplate>$selected_templates

Implements ILIAS\Test\Settings\Templates\TableAction.

Definition at line 73 of file PersonalSettingsTableApplyAction.php.

76 : ?Modal {
77 $template = $this->checkSelectedTemplate($selected_templates);
78 $question_set_type_changed = $this->hasDifferentQuestionSetType($template->getSettingsId());
79
80 return $this->ui_factory->modal()->interruptive(
81 $this->lng->txt('confirm'),
82 $this->lng->txt($question_set_type_changed ? 'personal_settings_apply_changed_confirmation' : 'personal_settings_apply_confirmation'),
83 $url_builder->buildURI()->__toString()
84 )->withAffectedItems(
85 [
86 $this->ui_factory->modal()->interruptiveItem()->standard(
87 (string) $template->getId(),
88 $template->getName(),
89 null,
90 sprintf($this->lng->txt('personal_settings_apply_description'), $this->test_obj->getTitle()),
91 ),
92 ]
93 )->withActionButtonLabel($this->lng->txt('apply'));
94 }
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
Definition: URLBuilder.php:214

◆ buildTableAction()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::buildTableAction ( URLBuilder  $url_builder,
URLBuilderToken  $row_id_token,
URLBuilderToken  $action_token,
URLBuilderToken  $action_type_token 
)

Implements ILIAS\Test\Settings\Templates\TableAction.

Definition at line 58 of file PersonalSettingsTableApplyAction.php.

63 : Action {
64 return $this->ui_factory->table()->action()->single(
65 $this->lng->txt('personal_settings_apply'),
66 $url_builder
67 ->withParameter($action_token, self::ACTION_ID)
68 ->withParameter($action_type_token, ParticipantTableActions::SHOW_ACTION),
69 $row_id_token
70 )->withAsync();
71 }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166

◆ checkSelectedTemplate()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::checkSelectedTemplate ( array  $selected_templates)
private

Definition at line 131 of file PersonalSettingsTableApplyAction.php.

131 : PersonalSettingsTemplate
132 {
133 if (count($selected_templates) !== 1) {
134 throw new \InvalidArgumentException('personal_settings_invalid_selection');
135 }
136
137 // Do not apply if user datasets exist
138 if ($this->test_obj->evalTotalPersons() > 0) {
139 throw new \InvalidArgumentException('personal_settings_apply_not_possible');
140 }
141
142 return reset($selected_templates);
143 }

◆ getActionId()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::getActionId ( )

◆ hasDifferentQuestionSetType()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::hasDifferentQuestionSetType ( int  $template_settings_id)
private

Definition at line 145 of file PersonalSettingsTableApplyAction.php.

145 : bool
146 {
147 $template_main_settings = $this->main_settings_repository->getById($template_settings_id);
148 return $template_main_settings->getGeneralSettings()->getQuestionSetType() !== $this->test_obj->getQuestionSetType();
149 }

◆ onSubmit()

ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::onSubmit ( URLBuilder  $url_builder,
ServerRequestInterface  $request,
array  $selected_templates 
)
Parameters
array<PersonalSettingsTemplate>$selected_templates

Implements ILIAS\Test\Settings\Templates\TableAction.

Definition at line 96 of file PersonalSettingsTableApplyAction.php.

100 : ?Modal {
101 $template = $this->checkSelectedTemplate($selected_templates);
102
103 $old_question_set_config = $this->hasDifferentQuestionSetType($template->getSettingsId()) ?
104 $this->question_set_config_factory->getQuestionSetConfig() :
105 null;
106
107 $test_settings_id = $this->test_obj->getMainSettings()->getId();
108 $main_settings = $this->main_settings_repository->getById($template->getSettingsId());
109 $score_settings = $this->score_settings_repository->getById($template->getSettingsId());
110
111 $mark_schema = $this->marks_repository->getMarkSchemaBySteps(
112 $this->repository->lookupMarkSteps($template->getId())
113 );
114
115 $this->main_settings_repository->store($main_settings->withId($test_settings_id));
116 $this->score_settings_repository->store($score_settings->withId($test_settings_id));
117 $this->marks_repository->storeMarkSchema($mark_schema->withTestId($this->test_obj->getTestId()));
118
119 if ($old_question_set_config && $old_question_set_config->doesQuestionSetRelatedDataExist()) {
120 $old_question_set_config->removeQuestionSetRelatedData();
121 }
122
123 $this->tpl->setOnScreenMessage(
125 $this->lng->txt('personal_settings_apply_success'),
126 true
127 );
128 return null;
129 }

Field Documentation

◆ ACTION_ID

const string ILIAS\Test\Settings\Templates\PersonalSettingsTableApplyAction::ACTION_ID = 'apply_template'

The documentation for this class was generated from the following file: