Skip to content

Commit

Permalink
Full rework after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuszych authored and kergomard committed Oct 25, 2024
1 parent 4f8f473 commit 512b76d
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 469 deletions.

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions components/ILIAS/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
use ILIAS\Filesystem\Util\Archive\Archives;
use ILIAS\Skill\Service\SkillService;
use ILIAS\ResourceStorage\Services as IRSS;
use ILIAS\Taxonomy\DomainService as TaxonomyService;

/**
* Class ilObjTestGUI
Expand Down Expand Up @@ -153,6 +154,7 @@ class ilObjTestGUI extends ilObjectGUI implements ilCtrlBaseClassInterface, ilDe
protected ?QuestionsTableQuery $table_query = null;
protected ?QuestionsTableActions $table_actions = null;
protected DataFactory $data_factory;
protected TaxonomyService $taxonomy;

protected bool $create_question_mode;

Expand Down Expand Up @@ -183,6 +185,8 @@ public function __construct()
$this->type = 'tst';
$this->data_factory = new DataFactory();
$this->ui_service = $DIC->uiService();
$this->taxonomy = $DIC->taxonomy()->domain();
$this->ui_service = $DIC->uiService();

$local_dic = TestDIC::dic();
$this->questionrepository = $local_dic['question.general_properties.repository'];
Expand Down Expand Up @@ -680,11 +684,15 @@ public function executeCommand(): void
$this->ui_factory,
$this->ui_renderer,
$this->testrequest,
$this->title_builder,
$this->questionrepository
$this->questionrepository,
$this->lng,
$this->ctrl,
$this->tpl,
$this->ui_service,
$this->data_factory,
$this->taxonomy,
static fn() => ''
);
$gui->setWriteAccess($this->access->checkAccess("write", "", $this->ref_id));
$gui->init();
$this->ctrl->forwardCommand($gui);
break;

Expand Down Expand Up @@ -1842,24 +1850,19 @@ private function setupToolBarAndMessage(bool $has_started_test_runs): void

$this->toolbar->addButton($this->lng->txt('ass_create_question'), $this->ctrl->getLinkTarget($this, 'createQuestionForm'));
$this->toolbar->addSeparator();
$this->populateQuestionBrowserToolbarButtons($this->toolbar, ilTestQuestionBrowserTableGUI::CONTEXT_LIST_VIEW);
$this->populateQuestionBrowserToolbarButtons($this->toolbar);
}

private function populateQuestionBrowserToolbarButtons(ilToolbarGUI $toolbar, string $context): void
private function populateQuestionBrowserToolbarButtons(ilToolbarGUI $toolbar): void
{
$this->ctrl->setParameterByClass(
ilTestQuestionBrowserTableGUI::class,
ilTestQuestionBrowserTableGUI::CONTEXT_PARAMETER,
$context
);
$this->ctrl->setParameterByClass(
ilTestQuestionBrowserTableGUI::class,
ilTestQuestionBrowserTableGUI::MODE_PARAMETER,
ilTestQuestionBrowserTableGUI::MODE_BROWSE_POOLS
);

$toolbar->addButton(
$this->lng->txt("tst_browse_for_qpl_questions"),
$this->lng->txt('tst_browse_for_qpl_questions'),
$this->ctrl->getLinkTargetByClass(
ilTestQuestionBrowserTableGUI::class,
ilTestQuestionBrowserTableGUI::CMD_BROWSE_QUESTIONS
Expand All @@ -1873,7 +1876,7 @@ private function populateQuestionBrowserToolbarButtons(ilToolbarGUI $toolbar, st
);

$toolbar->addButton(
$this->lng->txt("tst_browse_for_tst_questions"),
$this->lng->txt('tst_browse_for_tst_questions'),
$this->ctrl->getLinkTargetByClass(
ilTestQuestionBrowserTableGUI::class,
ilTestQuestionBrowserTableGUI::CMD_BROWSE_QUESTIONS
Expand Down Expand Up @@ -2723,7 +2726,8 @@ protected function getQuestionsTableActions(): QuestionsTableActions
$this->object,
$this->getTestObject()->getGlobalSettings()->isAdjustingQuestionsWithResultsAllowed(),
$this->getTestObject()->evalTotalPersons() !== 0,
$this->getTestObject()->isRandomTest()
$this->getTestObject()->isRandomTest(),
$this->test_question_set_config_factory
);
}
return $this->table_actions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function __construct(
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 bool $is_in_test_with_random_question_set,
private readonly \ilTestQuestionSetConfigFactory $test_question_set_config_factory
) {
$this->table_id = (string) $test_obj->getId();
}
Expand Down
106 changes: 106 additions & 0 deletions components/ILIAS/Test/src/Questions/QuestionsBrowserFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Test\Questions;

use ilAssQuestionLifecycle;
use ILIAS\UI\Component\Input\Field\Factory as FieldFactory;
use ILIAS\UI\Component\Input\Input;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Component\Input\Container\Filter\Filter;
use ilLanguage;
use ilObjQuestionPool;
use ilUIService;
use Psr\Http\Message\ServerRequestInterface;

class QuestionsBrowserFilter
{
public function __construct(
private readonly ilUIService $ui_service,
private readonly ilLanguage $lng,
private readonly UIFactory $ui_factory,
private readonly string $filter_id,
private readonly string $parent_title
) {
}

public function getComponent(string $action, ServerRequestInterface $request): Filter
{
$filter_inputs = [];
$is_input_initially_rendered = [];
$field_factory = $this->ui_factory->input()->field();

foreach ($this->getFields($field_factory) as $filter_id => $filter) {
[$filter_inputs[$filter_id], $is_input_initially_rendered[$filter_id]] = $filter;
}

$component = $this->ui_service->filter()->standard(
$this->filter_id,
$action,
$filter_inputs,
$is_input_initially_rendered,
true,
true
);

return $request->getMethod() === 'POST' ? $component->withRequest($request) : $component;
}

/**
* @param FieldFactory $input
*
* @return array<string, array<Input, bool>>
*/
private function getFields(FieldFactory $input): array
{
$lifecycle_options = array_merge(
['' => $this->lng->txt('qst_lifecycle_filter_all')],
ilAssQuestionLifecycle::getDraftInstance()->getSelectOptions($this->lng)
);
$yes_no_all_options = [
'' => $this->lng->txt('resulttable_all'),
'true' => $this->lng->txt('yes'),
'false' => $this->lng->txt('no')
];

return [
'title' => [$input->text($this->lng->txt('tst_question_title')), true],
'description' => [$input->text($this->lng->txt('description')), false],
'type' => [$input->select($this->lng->txt('tst_question_type'), $this->resolveQuestionTypeFilterOptions()), true],
'author' => [$input->text($this->lng->txt('author')), false],
'lifecycle' => [$input->select($this->lng->txt('qst_lifecycle'), $lifecycle_options), false],
'parent_title' => [$input->text($this->lng->txt($this->parent_title)), true],
'taxonomy_title' => [$input->text($this->lng->txt('taxonomy_title')), true],
'taxonomy_node_title' => [$input->text($this->lng->txt('taxonomy_node_title')), true],
'feedback' => [$input->select($this->lng->txt('feedback'), $yes_no_all_options), false],
'hints' => [$input->select($this->lng->txt('hints'), $yes_no_all_options), false]
];
}

private function resolveQuestionTypeFilterOptions(): array
{
$question_type_options = ['' => $this->lng->txt('filter_all_question_types')];

foreach (ilObjQuestionPool::_getQuestionTypes() as $translation => $row) {
$question_type_options[$row['type_tag']] = $translation;
}
return $question_type_options;
}
}
Loading

0 comments on commit 512b76d

Please sign in to comment.