19declare(strict_types=1);
31use Psr\Http\Message\ServerRequestInterface;
56 private readonly UIFactory $ui_factory,
57 private readonly UIRenderer $ui_renderer,
59 private readonly ServerRequestInterface $request,
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;
81 self::ACTION_ADD_TO_POOL,
82 $this->is_in_test_with_random_question_set
83 )->withDisabledAction(self::ACTION_EDIT_QUESTION, $disable_default_actions)
84 ->withDisabledAction(self::ACTION_EDIT_PAGE, $disable_default_actions)
87 !$this->is_adjusting_questions_with_results_allowed || !$this->is_in_test_with_results
88 )->withDisabledAction(self::ACTION_FEEDBACK, $disable_default_actions)
89 ->withDisabledAction(self::ACTION_PRINT_ANSWERS, !$this->is_in_test_with_results)
91 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS,
92 $row->
getCellContent(
'type_tag') !== $this->lng->txt(\assFileUpload::class)
93 || !$this->questionrepository->questionHasAnswers((
int) $row->
getId())
99 return $this->table_query->getActionURL(self::ACTION_SAVE_ORDER);
104 $ag = fn(
string $type,
string $label, $action): TableAction => $this->
105 ui_factory->table()->action()->$type(
106 $this->
lng->txt($label),
107 ...$this->table_query->getRowBoundURLBuilder($action)
111 self::ACTION_PREVIEW => $ag(
'single',
'preview', self::ACTION_PREVIEW),
112 self::ACTION_ADJUST => $ag(
'single',
'tst_corrections_qst_form', self::ACTION_ADJUST),
113 self::ACTION_STATISTICS => $ag(
'single',
'statistics', self::ACTION_STATISTICS),
114 self::ACTION_EDIT_QUESTION => $ag(
'single',
'edit_question', self::ACTION_EDIT_QUESTION),
115 self::ACTION_EDIT_PAGE => $ag(
'single',
'edit_page', self::ACTION_EDIT_PAGE),
116 self::ACTION_FEEDBACK => $ag(
'single',
'tst_feedback', self::ACTION_FEEDBACK),
117 self::ACTION_PRINT_ANSWERS => $ag(
'single',
'print_answers', self::ACTION_PRINT_ANSWERS),
118 self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS => $ag(
'single',
'download_all_files', self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS),
121 if (!$this->is_in_test_with_random_question_set
122 && (!$this->is_in_test_with_results || $this->is_adjusting_questions_with_results_allowed)) {
123 $actions[self::ACTION_DELETE] = $ag(
'standard',
'delete', self::ACTION_DELETE)
127 if (!$this->is_in_test_with_random_question_set && !$this->is_in_test_with_results) {
128 $actions[self::ACTION_COPY] = $ag(
'standard',
'copy', self::ACTION_COPY);
132 self::ACTION_ADD_TO_POOL => $ag(
'standard',
'copy_and_link_to_questionpool', self::ACTION_ADD_TO_POOL),
133 self::ACTION_PRINT_QUESTIONS => $ag(
'multi',
'print', self::ACTION_PRINT_QUESTIONS)
139 return function (
int $question_id):
string {
140 [$url_builder, $row_id_token] = $this->table_query->getRowBoundURLBuilder(self::ACTION_PREVIEW);
141 return $url_builder->withParameter($row_id_token, (
string) $question_id)
153 \Closure $protect_by_write_protection,
154 \Closure $copy_and_link_to_questionpool,
158 case self::ACTION_SAVE_ORDER:
159 $protect_by_write_protection();
161 if ($this->is_in_test_with_random_question_set || $this->is_in_test_with_results) {
162 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'questionlist_cannot_be_altered'));
166 $data = $get_table()->getTableComponent()->getData();
167 $this->test_obj->setQuestionOrder(array_flip(
$data), []);
168 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
171 case self::ACTION_PREVIEW:
172 $this->redirectWithQuestionParameters(
174 \ilAssQuestionPreviewGUI::class,
179 case self::ACTION_ADJUST:
180 $this->redirectWithQuestionParameters(
182 \ilTestCorrectionsGUI::class,
187 case self::ACTION_STATISTICS:
188 $this->redirectWithQuestionParameters(
190 \ilAssQuestionPreviewGUI::class,
195 case self::ACTION_EDIT_QUESTION:
196 $question_id = current($row_ids);
197 $qtype = $this->test_obj->getQuestionType($question_id);
198 $target_class = $qtype .
'GUI';
199 $this->redirectWithQuestionParameters(
206 case self::ACTION_EDIT_PAGE:
207 $this->redirectWithQuestionParameters(
209 \ilAssQuestionPageGUI::class,
214 case self::ACTION_FEEDBACK:
215 $this->redirectWithQuestionParameters(
217 \ilAssQuestionFeedbackEditingGUI::class,
222 case self::ACTION_DELETE:
223 echo $this->ui_renderer->renderAsync(
224 $this->getDeleteConfirmation(array_filter($row_ids))
228 case self::ACTION_DELETE_CONFIRMED:
229 $row_ids = $this->request->getParsedBody()[
'interruptive_items'] ?? [];
230 if (array_filter($row_ids) === []) {
235 if ($this->is_in_test_with_random_question_set
236 || $this->is_in_test_with_results
237 && !$this->is_adjusting_questions_with_results_allowed) {
238 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'questionlist_cannot_be_altered'));
242 $protect_by_write_protection();
243 if ($this->is_in_test_with_results) {
244 $this->test_obj->removeQuestionsWithResults($row_ids);
246 $this->test_obj->removeQuestions($row_ids);
247 $this->test_obj->saveCompleteStatus($this->test_question_set_config_factory->getQuestionSetConfig());
249 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'tst_questions_removed'),
true);
252 case self::ACTION_COPY:
253 if (array_filter($row_ids) === []) {
254 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
258 if ($this->is_in_test_with_random_question_set || $this->is_in_test_with_results) {
259 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'questionlist_cannot_be_altered'));
263 $protect_by_write_protection();
264 $this->test_obj->copyQuestions($row_ids);
265 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'copy_questions_success'),
true);
268 case self::ACTION_ADD_TO_POOL:
269 if (array_filter($row_ids) === []) {
270 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'tst_no_question_selected_for_moving_to_qpl'));
273 $protect_by_write_protection();
274 if (!$this->checkQuestionParametersForCopyToPool($row_ids)) {
277 $copy_and_link_to_questionpool();
280 case self::ACTION_PRINT_QUESTIONS:
281 if (array_filter($row_ids) === []) {
282 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_questions_selected'));
285 $protect_by_write_protection();
286 $this->question_printer->printSelectedQuestions(
289 function (array
$c,
Types $v): array {
290 $c[$v->getLabel($this->
lng)] = $this->table_query
291 ->getPrintViewTypeURL(self::ACTION_PRINT_QUESTIONS, $v->value)->__toString();
296 Types::tryFrom($this->table_query->getPrintViewType()) ?? Types::RESULTS_VIEW_TYPE_SHOW,
301 case self::ACTION_PRINT_ANSWERS:
302 $protect_by_write_protection();
303 $this->question_printer->printAnswers(current($row_ids));
306 case self::ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS:
307 $protect_by_write_protection();
310 $question_object->deliverFileUploadZIPFile(
311 $this->test_obj->getRefId(),
312 $this->test_obj->getTestId(),
313 $this->test_obj->getTitle()
319 throw new \InvalidArgumentException(
"No such table_cmd: '$cmd'.");
326 foreach ($row_ids as
$id) {
327 $qdata = $this->test_obj->getQuestionDataset(
$id);
328 $type = $this->questionrepository->getQuestionPropertiesForQuestionId(
$id)
329 ->getGeneralQuestionProperties()->getTypeName($this->
lng);
330 $icon = $this->ui_renderer->render(
331 $this->ui_factory->symbol()->icon()->standard(
'ques', $type,
'small')
333 $items[] = $this->ui_factory->modal()->interruptiveItem()->keyvalue(
335 $icon .
' ' . $qdata->title,
340 return $this->ui_factory->modal()->interruptive(
341 $this->
lng->txt(
'remove'),
343 $this->is_in_test_with_results
344 ?
'tst_remove_questions_and_results'
345 :
'tst_remove_questions'
347 $this->table_query->getActionURL(self::ACTION_DELETE_CONFIRMED)->__toString()
354 string $target_class,
358 $this->
ctrl->setParameterByClass(
364 $this->
ctrl->setParameterByClass(
367 (
string) $this->test_obj->getRefId()
370 $this->
ctrl->redirectByClass($target_class, $cmd);
378 $question_properties = $this->questionrepository
379 ->getQuestionPropertiesForQuestionIds($question_ids);
380 foreach ($question_ids as $q_id) {
381 if (!$this->questionrepository->originalQuestionExists($q_id)) {
387 $question_properties[$q_id]->getGeneralQuestionProperties()->getOriginalId()
391 if ($type !==
'tst') {
392 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'tst_link_only_unassigned'),
true);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Builds a Color from either hex- or rgb values.
The scope of this class is split ilias-conform URI's into components.
checkQuestionParametersForCopyToPool(array $question_ids)
const ACTION_DELETE_CONFIRMED
redirectWithQuestionParameters(int $question_id, string $target_class, string $cmd)
handleCommand(string $cmd, array $row_ids, \Closure $protect_by_write_protection, \Closure $copy_and_link_to_questionpool, \Closure $get_table)
getDeleteConfirmation(array $row_ids)
const ACTION_DOWNLOAD_FILE_QUESTION_ANSWERS
setDisabledActions(OrderingRow $row)
const ACTION_PRINT_ANSWERS
const ACTION_EDIT_QUESTION
getQuestionTargetLinkBuilder()
const ACTION_PRINT_QUESTIONS
__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)
static lookupParentObjId(int $question_id)
static instantiateQuestion(int $question_id)
Class ilCtrl provides processing control methods.
static _lookupType(int $id, bool $reference=false)
withAffectedItems(array $items)
Get a modal like this listing the given items in the content section below the message.
getCellContent(string $col_id)
withDisabledAction(string $action_id, bool $disable=true)
Refer to an Action by its id and disable it for this row/record only.
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...