ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestQuestionBrowserTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data\Factory as DataFactory;
23use ILIAS\Refinery\Factory as Refinery;
24use ILIAS\Taxonomy\DomainService as TaxonomyService;
31use ILIAS\UI\Factory as UIFactory;
32use ILIAS\UI\Renderer as UIRenderer;
33
38{
39 public const REPOSITORY_ROOT_NODE_ID = 1;
40 public const MODE_PARAMETER = 'question_browse_mode';
41 public const MODE_BROWSE_POOLS = 'modeBrowsePools';
42 public const MODE_BROWSE_TESTS = 'modeBrowseTests';
43
44 public const CMD_BROWSE_QUESTIONS = 'browseQuestions';
45 public const CMD_INSERT_QUESTIONS = 'insertQuestions';
46
47 public function __construct(
48 private readonly ilTabsGUI $tabs,
49 private readonly ilTree $tree,
50 private readonly ilDBInterface $db,
51 private readonly TestLogger $logger,
52 private readonly ilComponentRepository $component_repository,
53 private readonly ilObjTest $test_obj,
54 private readonly ilObjUser $current_user,
55 private readonly ilAccessHandler $access,
56 private readonly GlobalHttpState $http_state,
57 private readonly Refinery $refinery,
58 private readonly UIFactory $ui_factory,
59 private readonly UIRenderer $ui_renderer,
60 private readonly RequestDataCollector $testrequest,
61 private readonly GeneralQuestionPropertiesRepository $questionrepository,
62 private readonly ilLanguage $lng,
63 private readonly ilCtrl $ctrl,
64 private readonly ilGlobalTemplateInterface $main_tpl,
65 private readonly ilUIService $ui_service,
66 private readonly DataFactory $data_factory,
67 private readonly TaxonomyService $taxonomy,
68 ) {
69 }
70
71 public function executeCommand(): bool
72 {
73 $this->handleWriteAccess();
74 $this->handleTabs();
75
76 switch (strtolower((string) $this->ctrl->getNextClass($this))) {
77 case strtolower(self::class):
78 case '':
79 $cmd = $this->ctrl->getCmd() . 'Cmd';
80 return $this->$cmd();
81
82 default:
83 $this->ctrl->setReturn($this, self::CMD_BROWSE_QUESTIONS);
84 return $this->browseQuestionsCmd();
85 }
86 }
87
88 private function handleWriteAccess(): void
89 {
90 if (!$this->access->checkAccess('write', '', $this->test_obj->getRefId())) {
91 $this->ctrl->redirectByClass(ilObjTestGUI::class, ilObjTestGUI::SHOW_QUESTIONS_CMD);
92 }
93 }
94
95 private function browseQuestionsCmd(): bool
96 {
97 $this->ctrl->setParameter($this, self::MODE_PARAMETER, $this->testrequest->raw(self::MODE_PARAMETER));
98 $action = $this->ctrl->getLinkTarget($this, self::CMD_BROWSE_QUESTIONS);
99
100 $mode = $this->ctrl->getParameterArrayByClass(self::class)[self::MODE_PARAMETER];
101 $parent_title = ($mode === self::MODE_BROWSE_TESTS ? 'test_title' : 'tst_source_question_pool');
102
103 $filter = $this->getQuestionsBrowserFilterComponent($parent_title, $action);
104 $question_browser_table = $this->getQuestionsBrowserTable($parent_title);
105
106 $this->main_tpl->setContent(
107 $this->ui_renderer->render([
108 $filter,
109 $question_browser_table->getComponent($this->http_state->request(), $this->ui_service->filter()->getData($filter))
110 ])
111 );
112
113 return true;
114 }
115
116 private function getQuestionsBrowserFilterComponent(string $parent_title = '', string $action = ''): Filter
117 {
118 return (new QuestionsBrowserFilter(
119 $this->ui_service,
120 $this->lng,
121 $this->ui_factory,
122 'question_browser_filter',
123 $parent_title
124 ))->getComponent($action, $this->http_state->request());
125 }
126
127 private function getQuestionsBrowserTable(string $parent_title = ''): QuestionsBrowserTable
128 {
129 $question_list = new ilAssQuestionList($this->db, $this->lng, $this->refinery, $this->component_repository);
130 $question_list = $this->addModeParametersToQuestionList($question_list);
131
132 return new QuestionsBrowserTable(
133 (string) $this->test_obj->getId(),
134 $this->current_user,
135 $this->ui_factory,
136 $this->ui_renderer,
137 $this->lng,
138 $this->ctrl,
139 $this->data_factory,
140 $question_list,
141 $this->taxonomy,
142 $parent_title
143 );
144 }
145
146 private function insertQuestionsCmd(): void
147 {
148 $selected_array = $this->http_state->wrapper()->query()->retrieve(
149 'qlist_q_id',
150 $this->refinery->byTrying([
151 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
152 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
153 $this->refinery->always([])
154 ])
155 );
156
157 if ($selected_array === []) {
158 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('tst_insert_missing_question'), true);
159 $this->ctrl->redirect($this, self::CMD_BROWSE_QUESTIONS);
160 }
161
162 if (in_array('ALL_OBJECTS', $selected_array, true)) {
163 $selected_array = array_keys(
164 $this->getQuestionsBrowserTable()->loadRecords(
165 $this->ui_service->filter()->getData($this->getQuestionsBrowserFilterComponent()) ?? []
166 )
167 );
168 }
169
170 array_map(
171 fn(int $v): int => $this->test_obj->insertQuestion($v),
172 $selected_array
173 );
174
175 $this->test_obj->saveCompleteStatus($this->buildTestQuestionSetConfig());
176
177 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('tst_questions_inserted'), true);
178
179 $this->ctrl->redirectByClass(ilObjTestGUI::class, ilObjTestGUI::SHOW_QUESTIONS_CMD);
180 }
181
182 private function handleTabs(): void
183 {
184 $this->tabs->clearTargets();
185 $this->tabs->clearSubTabs();
186
187 $this->tabs->setBackTarget(
188 $this->lng->txt('backtocallingtest'),
189 $this->ctrl->getLinkTargetByClass(ilObjTestGUI::class, ilObjTestGUI::SHOW_QUESTIONS_CMD)
190 );
191
192 $browseQuestionsTabLabel = match ($this->testrequest->raw(self::MODE_PARAMETER)) {
193 self::MODE_BROWSE_POOLS => $this->lng->txt('tst_browse_for_qpl_questions'),
194 self::MODE_BROWSE_TESTS => $this->lng->txt('tst_browse_for_tst_questions'),
195 default => ''
196 };
197
198 $this->tabs->addTab(
199 self::CMD_BROWSE_QUESTIONS,
200 $browseQuestionsTabLabel,
201 $this->ctrl->getLinkTarget($this, self::CMD_BROWSE_QUESTIONS)
202 );
203 $this->tabs->activateTab('browseQuestions');
204 }
205
207 {
209 $this->tree,
210 $this->db,
211 $this->lng,
212 $this->logger,
213 $this->component_repository,
214 $this->test_obj,
215 $this->questionrepository
216 ))->getQuestionSetConfig();
217 }
218
220 {
221 if ($this->testrequest->raw(self::MODE_PARAMETER) === self::MODE_BROWSE_TESTS) {
222 $question_list->setParentObjectType('tst');
224 $question_list->setExcludeQuestionIdsFilter($this->test_obj->getQuestions());
225 return $question_list;
226 }
227
228 $question_list->setParentObjIdsFilter($this->getQuestionParentObjIds(self::REPOSITORY_ROOT_NODE_ID));
230 $question_list->setExcludeQuestionIdsFilter($this->test_obj->getExistingQuestions());
231 return $question_list;
232 }
233
234 private function getQuestionParentObjIds(int $repositoryRootNode): array
235 {
236 $parents = $this->tree->getSubTree(
237 $this->tree->getNodeData($repositoryRootNode),
238 true,
239 ['qpl']
240 );
241
242 $parentIds = [];
243
244 foreach ($parents as $nodeData) {
245 if ((int) $nodeData['obj_id'] === $this->test_obj->getId()) {
246 continue;
247 }
248
249 $parentIds[$nodeData['obj_id']] = $nodeData['obj_id'];
250 }
251
252 $parentIds = array_map('intval', array_values($parentIds));
253 $available_pools = array_map('intval', array_keys(\ilObjQuestionPool::_getAvailableQuestionpools(true)));
254 return array_intersect($parentIds, $available_pools);
255 }
256}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
setQuestionInstanceTypeFilter(?string $questionInstanceTypeFilter)
setParentObjIdsFilter(array $parentObjIdsFilter)
setExcludeQuestionIdsFilter(array $excludeQuestionIdsFilter)
setParentObjectType(string $parentObjType)
Class ilCtrl provides processing control methods.
language handling
static _getAvailableQuestionpools(bool $use_object_id=false, bool $equal_points=false, bool $could_be_offline=false, bool $showPath=false, bool $with_questioncount=false, string $permission='read', int $usr_id=0)
Returns the available question pools for the active user.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ilCtrl_Calls ilTestQuestionBrowserTableGUI: ilFormPropertyDispatchGUI
addModeParametersToQuestionList(ilAssQuestionList $question_list)
getQuestionsBrowserFilterComponent(string $parent_title='', string $action='')
__construct(private readonly ilTabsGUI $tabs, private readonly ilTree $tree, private readonly ilDBInterface $db, private readonly TestLogger $logger, private readonly ilComponentRepository $component_repository, private readonly ilObjTest $test_obj, private readonly ilObjUser $current_user, private readonly ilAccessHandler $access, private readonly GlobalHttpState $http_state, private readonly Refinery $refinery, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly RequestDataCollector $testrequest, private readonly GeneralQuestionPropertiesRepository $questionrepository, private readonly ilLanguage $lng, private readonly ilCtrl $ctrl, private readonly ilGlobalTemplateInterface $main_tpl, private readonly ilUIService $ui_service, private readonly DataFactory $data_factory, private readonly TaxonomyService $taxonomy,)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Filter service.
Interface GlobalHttpState.
This describes commonalities between all filters.
Definition: Filter.php:34
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Readable part of repository interface to ilComponentDataDB.
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31