19 declare(strict_types=1);
62 private readonly \
ilCtrl $ctrl,
63 private readonly TestQuestionsRepository $questionrepository,
64 private readonly
Printer $question_printer,
66 private readonly
bool $is_adjusting_questions_with_results_allowed,
67 private readonly
bool $is_in_test_with_results,
68 private readonly
bool $is_in_test_with_random_question_set,
71 $this->table_id = (string) $test_obj->getId();
77 $disable_default_actions = $this->is_in_test_with_random_question_set
78 || $this->is_in_test_with_results;
82 $this->is_in_test_with_random_question_set && !$this->is_in_test_with_results
83 )->withDisabledAction(self::ACTION_COPY, $disable_default_actions)
84 ->withDisabledAction(self::ACTION_ADD_TO_POOL, $this->is_in_test_with_random_question_set)
85 ->withDisabledAction(self::ACTION_EDIT_QUESTION, $disable_default_actions)
86 ->withDisabledAction(self::ACTION_EDIT_PAGE, $disable_default_actions)
89 $this->is_adjusting_questions_with_results_allowed && !$this->is_in_test_with_results
90 )->withDisabledAction(self::ACTION_FEEDBACK, $disable_default_actions)
91 ->withDisabledAction(self::ACTION_PRINT_ANSWERS, !$this->is_in_test_with_results)
93 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS,
95 || !$this->questionrepository->questionHasAnswers((
int) $row->
getId())
101 return $this->table_query->getActionURL(self::ACTION_SAVE_ORDER);
106 $ag = fn(
string $type,
string $label, $action):
TableAction => $this->
107 ui_factory->table()->action()->$type(
108 $this->
lng->txt($label),
109 ...$this->table_query->getRowBoundURLBuilder($action)
113 self::ACTION_PREVIEW => $ag(
'single',
'preview', self::ACTION_PREVIEW),
114 self::ACTION_ADJUST => $ag(
'single',
'tst_corrections_qst_form', self::ACTION_ADJUST),
115 self::ACTION_STATISTICS => $ag(
'single',
'statistics', self::ACTION_STATISTICS),
116 self::ACTION_EDIT_QUESTION => $ag(
'single',
'edit_question', self::ACTION_EDIT_QUESTION),
117 self::ACTION_EDIT_PAGE => $ag(
'single',
'edit_page', self::ACTION_EDIT_PAGE),
118 self::ACTION_FEEDBACK => $ag(
'single',
'tst_feedback', self::ACTION_FEEDBACK),
119 self::ACTION_PRINT_ANSWERS => $ag(
'single',
'print_answers', self::ACTION_PRINT_ANSWERS),
120 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS => $ag(
'single',
'download_all_files', self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS),
123 if (!$this->test_obj->isRandomTest()) {
124 $actions[self::ACTION_DELETE] = $ag(
'standard',
'delete', self::ACTION_DELETE)
129 self::ACTION_COPY => $ag(
'standard',
'copy', self::ACTION_COPY),
130 self::ACTION_ADD_TO_POOL => $ag(
'standard',
'copy_and_link_to_questionpool', self::ACTION_ADD_TO_POOL),
131 self::ACTION_PRINT_QUESTIONS => $ag(
'multi',
'print', self::ACTION_PRINT_QUESTIONS)
137 return function (
int $question_id):
string {
138 [$url_builder, $row_id_token] = $this->table_query->getRowBoundURLBuilder(self::ACTION_PREVIEW);
139 return $url_builder->withParameter($row_id_token, (
string) $question_id)
151 \
Closure $protect_by_write_protection,
152 \
Closure $copy_and_link_to_questionpool,
156 case self::ACTION_SAVE_ORDER:
157 $protect_by_write_protection();
158 $data = $get_table()->getTableComponent()->getData();
159 $this->test_obj->setQuestionOrder(array_flip(
$data), []);
160 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
163 case self::ACTION_PREVIEW:
166 \ilAssQuestionPreviewGUI::class,
171 case self::ACTION_ADJUST:
174 \ilTestCorrectionsGUI::class,
179 case self::ACTION_STATISTICS:
182 \ilAssQuestionPreviewGUI::class,
187 case self::ACTION_EDIT_QUESTION:
188 $question_id = current($row_ids);
189 $qtype = $this->test_obj->getQuestionType($question_id);
190 $target_class = $qtype .
'GUI';
198 case self::ACTION_EDIT_PAGE:
201 \ilAssQuestionPageGUI::class,
206 case self::ACTION_FEEDBACK:
209 \ilAssQuestionFeedbackEditingGUI::class,
214 case self::ACTION_DELETE:
215 echo $this->ui_renderer->renderAsync(
220 case self::ACTION_DELETE_CONFIRMED:
221 $row_ids = $this->request->getParsedBody()[
'interruptive_items'] ?? [];
222 if (array_filter($row_ids) === []) {
223 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
226 $protect_by_write_protection();
227 if ($this->is_in_test_with_results) {
228 $this->test_obj->removeQuestionsWithResults($row_ids);
230 $this->test_obj->removeQuestions($row_ids);
231 $this->test_obj->saveCompleteStatus($this->test_question_set_config_factory->getQuestionSetConfig());
233 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'tst_questions_removed'),
true);
236 case self::ACTION_COPY:
237 if (array_filter($row_ids) === []) {
238 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
241 $protect_by_write_protection();
242 $this->test_obj->copyQuestions($row_ids);
243 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'copy_questions_success'),
true);
246 case self::ACTION_ADD_TO_POOL:
247 if (array_filter($row_ids) === []) {
248 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'tst_no_question_selected_for_moving_to_qpl'));
251 $protect_by_write_protection();
255 $copy_and_link_to_questionpool();
258 case self::ACTION_PRINT_QUESTIONS:
259 if (array_filter($row_ids) === []) {
260 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
263 $protect_by_write_protection();
264 $this->question_printer->printSelectedQuestions(
267 function (array
$c,
Types $v): array {
268 $c[$v->getLabel($this->
lng)] = $this->table_query
269 ->getPrintViewTypeURL(self::ACTION_PRINT_QUESTIONS, $v->value)->__toString();
274 Types::tryFrom($this->table_query->getPrintViewType()) ?? Types::RESULTS_VIEW_TYPE_SHOW,
279 case self::ACTION_PRINT_ANSWERS:
280 $protect_by_write_protection();
281 $this->question_printer->printAnswers(current($row_ids));
284 case self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS:
285 $protect_by_write_protection();
288 $question_object->deliverFileUploadZIPFile(
289 $this->test_obj->getRefId(),
290 $this->test_obj->getTestId(),
291 $this->test_obj->getTitle()
297 throw new \InvalidArgumentException(
"No such table_cmd: '$cmd'.");
304 foreach ($row_ids as
$id) {
305 $qdata = $this->test_obj->getQuestionDataset($id);
306 $type = $this->questionrepository->getQuestionPropertiesForQuestionId($id)
307 ->getGeneralQuestionProperties()->getTypeName($this->
lng);
308 $icon = $this->ui_renderer->render(
309 $this->ui_factory->symbol()->icon()->standard(
'ques', $type,
'small')
311 $items[] = $this->ui_factory->modal()->interruptiveItem()->keyvalue(
313 $icon .
' ' . $qdata->title,
318 return $this->ui_factory->modal()->interruptive(
319 $this->
lng->txt(
'remove'),
321 $this->is_in_test_with_results
322 ?
'tst_remove_questions_and_results' 323 :
'tst_remove_questions' 325 $this->table_query->getActionURL(self::ACTION_DELETE_CONFIRMED)->__toString()
327 ->withAffectedItems($items);
332 string $target_class,
336 $this->
ctrl->setParameterByClass(
342 $this->
ctrl->setParameterByClass(
345 (
string) $this->test_obj->getRefId()
348 $this->
ctrl->redirectByClass($target_class, $cmd);
356 $question_properties = $this->questionrepository
357 ->getQuestionPropertiesForQuestionIds($question_ids);
358 foreach ($question_ids as $q_id) {
359 if (!$this->questionrepository->originalQuestionExists($q_id)) {
365 $question_properties[$q_id]->getGeneralQuestionProperties()->getOriginalId()
369 if ($type !==
'tst') {
370 $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)
__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)
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