ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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.

51 {
52 }

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 74 of file PersonalSettingsTableApplyAction.php.

77 : ?Modal {
78 $template = $this->checkSelectedTemplate($selected_templates);
79 $question_set_type_changed = $this->hasDifferentQuestionSetType($template->getSettingsId());
80
81 return $this->ui_factory->modal()->interruptive(
82 $this->lng->txt('confirm'),
83 $this->lng->txt($question_set_type_changed ? 'personal_settings_apply_changed_confirmation' : 'personal_settings_apply_confirmation'),
84 $url_builder->buildURI()->__toString()
85 )->withAffectedItems(
86 [
87 $this->ui_factory->modal()->interruptiveItem()->standard(
88 (string) $template->getId(),
89 $template->getName(),
90 null,
91 sprintf($this->lng->txt('personal_settings_apply_description'), $this->test_obj->getTitle()),
92 ),
93 ]
94 )->withActionButtonLabel($this->lng->txt('apply'));
95 }
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 59 of file PersonalSettingsTableApplyAction.php.

64 : Action {
65 return $this->ui_factory->table()->action()->single(
66 $this->lng->txt('personal_settings_apply'),
67 $url_builder
68 ->withParameter($action_token, self::ACTION_ID)
69 ->withParameter($action_type_token, ParticipantTableActions::SHOW_ACTION),
70 $row_id_token
71 )->withAsync();
72 }
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 132 of file PersonalSettingsTableApplyAction.php.

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

◆ getActionId()

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

◆ hasDifferentQuestionSetType()

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

Definition at line 146 of file PersonalSettingsTableApplyAction.php.

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

◆ 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 97 of file PersonalSettingsTableApplyAction.php.

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

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: