19 declare(strict_types=1);
63 private readonly \
ilCtrl $ctrl,
64 private readonly TestQuestionsRepository $questionrepository,
65 private readonly
Printer $question_printer,
67 private readonly
bool $is_adjusting_questions_with_results_allowed,
68 private readonly
bool $is_in_test_with_results,
69 private readonly
bool $is_in_test_with_random_question_set,
72 $this->table_id = (string) $test_obj->getId();
78 $disable_default_actions = $this->is_in_test_with_random_question_set
79 || $this->is_in_test_with_results;
83 $this->is_in_test_with_random_question_set && !$this->is_in_test_with_results
84 )->withDisabledAction(self::ACTION_COPY, $disable_default_actions)
85 ->withDisabledAction(self::ACTION_ADD_TO_POOL, $this->is_in_test_with_random_question_set)
86 ->withDisabledAction(self::ACTION_EDIT_QUESTION, $disable_default_actions)
87 ->withDisabledAction(self::ACTION_EDIT_PAGE, $disable_default_actions)
90 $this->is_adjusting_questions_with_results_allowed && !$this->is_in_test_with_results
91 )->withDisabledAction(self::ACTION_FEEDBACK, $disable_default_actions)
92 ->withDisabledAction(self::ACTION_HINTS, $disable_default_actions)
93 ->withDisabledAction(self::ACTION_PRINT_ANSWERS, !$this->is_in_test_with_results)
95 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS,
97 || !$this->questionrepository->questionHasAnswers((
int) $row->
getId())
103 return $this->table_query->getActionURL(self::ACTION_SAVE_ORDER);
108 $ag = fn(
string $type,
string $label, $action):
TableAction => $this->
109 ui_factory->table()->action()->$type(
110 $this->
lng->txt($label),
111 ...$this->table_query->getRowBoundURLBuilder($action)
115 self::ACTION_PREVIEW => $ag(
'single',
'preview', self::ACTION_PREVIEW),
116 self::ACTION_ADJUST => $ag(
'single',
'tst_corrections_qst_form', self::ACTION_ADJUST),
117 self::ACTION_STATISTICS => $ag(
'single',
'statistics', self::ACTION_STATISTICS),
118 self::ACTION_EDIT_QUESTION => $ag(
'single',
'edit_question', self::ACTION_EDIT_QUESTION),
119 self::ACTION_EDIT_PAGE => $ag(
'single',
'edit_page', self::ACTION_EDIT_PAGE),
120 self::ACTION_FEEDBACK => $ag(
'single',
'tst_feedback', self::ACTION_FEEDBACK),
121 self::ACTION_HINTS => $ag(
'single',
'tst_question_hints_tab', self::ACTION_HINTS),
122 self::ACTION_PRINT_ANSWERS => $ag(
'single',
'print_answers', self::ACTION_PRINT_ANSWERS),
123 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS => $ag(
'single',
'download_all_files', self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS),
126 if (!$this->test_obj->isRandomTest()) {
127 $actions[self::ACTION_DELETE] = $ag(
'standard',
'delete', self::ACTION_DELETE)
132 self::ACTION_COPY => $ag(
'standard',
'copy', self::ACTION_COPY),
133 self::ACTION_ADD_TO_POOL => $ag(
'standard',
'copy_and_link_to_questionpool', self::ACTION_ADD_TO_POOL),
134 self::ACTION_PRINT_QUESTIONS => $ag(
'multi',
'print', self::ACTION_PRINT_QUESTIONS)
140 return function (
int $question_id):
string {
141 [$url_builder, $row_id_token] = $this->table_query->getRowBoundURLBuilder(self::ACTION_PREVIEW);
142 return $url_builder->withParameter($row_id_token, (
string) $question_id)
154 \
Closure $protect_by_write_protection,
155 \
Closure $copy_and_link_to_questionpool,
159 case self::ACTION_SAVE_ORDER:
160 $protect_by_write_protection();
161 $data = $get_table()->getTableComponent()->getData();
162 $this->test_obj->setQuestionOrder(array_flip(
$data), []);
163 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
166 case self::ACTION_PREVIEW:
169 \ilAssQuestionPreviewGUI::class,
174 case self::ACTION_ADJUST:
177 \ilTestCorrectionsGUI::class,
182 case self::ACTION_STATISTICS:
185 \ilAssQuestionPreviewGUI::class,
190 case self::ACTION_EDIT_QUESTION:
191 $question_id = current($row_ids);
192 $qtype = $this->test_obj->getQuestionType($question_id);
193 $target_class = $qtype .
'GUI';
201 case self::ACTION_EDIT_PAGE:
204 \ilAssQuestionPageGUI::class,
209 case self::ACTION_FEEDBACK:
212 \ilAssQuestionFeedbackEditingGUI::class,
217 case self::ACTION_HINTS:
220 \ilAssQuestionHintsGUI::class,
225 case self::ACTION_DELETE:
226 echo $this->ui_renderer->renderAsync(
231 case self::ACTION_DELETE_CONFIRMED:
232 $row_ids = $this->request->getParsedBody()[
'interruptive_items'] ?? [];
233 if (array_filter($row_ids) === []) {
234 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
237 $protect_by_write_protection();
238 if ($this->is_in_test_with_results) {
239 $this->test_obj->removeQuestionsWithResults($row_ids);
241 $this->test_obj->removeQuestions($row_ids);
242 $this->test_obj->saveCompleteStatus($this->test_question_set_config_factory->getQuestionSetConfig());
244 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'tst_questions_removed'),
true);
247 case self::ACTION_COPY:
248 if (array_filter($row_ids) === []) {
249 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
252 $protect_by_write_protection();
253 $this->test_obj->copyQuestions($row_ids);
254 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'copy_questions_success'),
true);
257 case self::ACTION_ADD_TO_POOL:
258 if (array_filter($row_ids) === []) {
259 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'tst_no_question_selected_for_moving_to_qpl'));
262 $protect_by_write_protection();
266 $copy_and_link_to_questionpool();
269 case self::ACTION_PRINT_QUESTIONS:
270 if (array_filter($row_ids) === []) {
271 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
274 $protect_by_write_protection();
275 $this->question_printer->printSelectedQuestions(
278 function (array
$c,
Types $v): array {
279 $c[$v->getLabel($this->
lng)] = $this->table_query
280 ->getPrintViewTypeURL(self::ACTION_PRINT_QUESTIONS, $v->value)->__toString();
285 Types::tryFrom($this->table_query->getPrintViewType()) ?? Types::RESULTS_VIEW_TYPE_SHOW,
290 case self::ACTION_PRINT_ANSWERS:
291 $protect_by_write_protection();
292 $this->question_printer->printAnswers(current($row_ids));
295 case self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS:
296 $protect_by_write_protection();
299 $question_object->deliverFileUploadZIPFile(
300 $this->test_obj->getRefId(),
301 $this->test_obj->getTestId(),
302 $this->test_obj->getTitle()
308 throw new \InvalidArgumentException(
"No such table_cmd: '$cmd'.");
315 foreach ($row_ids as
$id) {
316 $qdata = $this->test_obj->getQuestionDataset($id);
317 $type = $this->questionrepository->getQuestionPropertiesForQuestionId($id)
318 ->getGeneralQuestionProperties()->getTypeName($this->
lng);
319 $icon = $this->ui_renderer->render(
320 $this->ui_factory->symbol()->icon()->standard(
'ques', $type,
'small')
322 $items[] = $this->ui_factory->modal()->interruptiveItem()->keyvalue(
324 $icon .
' ' . $qdata->title,
329 return $this->ui_factory->modal()->interruptive(
330 $this->
lng->txt(
'remove'),
332 $this->is_in_test_with_results
333 ?
'tst_remove_questions_and_results' 334 :
'tst_remove_questions' 336 $this->table_query->getActionURL(self::ACTION_DELETE_CONFIRMED)->__toString()
338 ->withAffectedItems($items);
343 string $target_class,
347 $this->
ctrl->setParameterByClass(
353 $this->
ctrl->setParameterByClass(
356 (
string) $this->test_obj->getRefId()
359 $this->
ctrl->redirectByClass($target_class, $cmd);
367 $question_properties = $this->questionrepository
368 ->getQuestionPropertiesForQuestionIds($question_ids);
369 foreach ($question_ids as $q_id) {
370 if (!$this->questionrepository->originalQuestionExists($q_id)) {
376 $question_properties[$q_id]->getGeneralQuestionProperties()->getOriginalId()
380 if ($type !==
'tst') {
381 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'tst_link_only_unassigned'),
true);
withDisabledAction(string $action_id, bool $disable=true)
Refer to an Action by its id and disable it for this row/record only.
const ACTION_EDIT_QUESTION
const ACTION_PRINT_ANSWERS
redirectWithQuestionParameters(int $question_id, string $target_class, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCellContent(string $col_id)
const CMD_SHOW_LIST
command constants
__construct(private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private \ilGlobalTemplateInterface $tpl, private readonly ServerRequestInterface $request, private readonly QuestionsTableQuery $table_query, private readonly Language $lng, private readonly \ilCtrl $ctrl, private readonly TestQuestionsRepository $questionrepository, private readonly Printer $question_printer, private readonly \ilObjTest $test_obj, private readonly bool $is_adjusting_questions_with_results_allowed, private readonly bool $is_in_test_with_results, private readonly bool $is_in_test_with_random_question_set, private readonly \ilTestQuestionSetConfigFactory $test_question_set_config_factory)
setDisabledActions(OrderingRow $row)
static instantiateQuestion(int $question_id)
getDeleteConfirmation(array $row_ids)
The scope of this class is split ilias-conform URI's into components.
getQuestionTargetLinkBuilder()
const ACTION_PRINT_QUESTIONS
static lookupParentObjId(int $question_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const ACTION_DELETE_CONFIRMED
handleCommand(string $cmd, array $row_ids, \Closure $protect_by_write_protection, \Closure $copy_and_link_to_questionpool, \Closure $get_table)
static _lookupType(int $id, bool $reference=false)
checkQuestionParametersForCopyToPool(array $question_ids)
const ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS