ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseObjectivesTableGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\UI\Factory as UIFactory;
20use ILIAS\UI\Renderer as UIRenderer;
21
28{
31
32 private UIRenderer $renderer;
33 private UIFactory $uiFactory;
34
35 public function __construct(object $a_parent_obj, ilObject $a_course_obj)
36 {
37 global $DIC;
38
39 $this->course_obj = $a_course_obj;
40
41 $this->settings = ilLOSettings::getInstanceByObjId($this->course_obj->getId());
42
43 parent::__construct($a_parent_obj, 'listObjectives');
44
45 $this->renderer = $DIC->ui()->renderer();
46 $this->uiFactory = $DIC->ui()->factory();
47
48 $this->lng->loadLanguageModule('crs');
49 $this->setFormName('objectives');
50 $this->addColumn('', 'f', "1px");
51 $this->addColumn($this->lng->txt('position'), 'position', '10em');
52 $this->addColumn($this->lng->txt('title'), 'title', '20%');
53 $this->addColumn($this->lng->txt('crs_objective_assigned_materials'), 'materials');
54 if ($this->getSettings()->worksWithInitialTest()) {
55 $this->addColumn($this->lng->txt('crs_objective_self_assessment'), 'self');
56 }
57 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) {
58 $this->addColumn($this->lng->txt('crs_objective_tbl_col_final_tsts'), 'final');
59 } else {
60 $this->addColumn($this->lng->txt('crs_objective_final_test'), 'final');
61 }
62 $this->addColumn($this->lng->txt('actions'), '5em');
63
64 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
65 $this->setRowTemplate("tpl.crs_objectives_table_row.html", "components/ILIAS/Course");
66 $this->disable('sort');
67 $this->enable('header');
68 $this->disable('numinfo');
69 $this->enable('select_all');
70 $this->setSelectAllCheckbox('objective');
71 $this->setLimit(200);
72 $this->addMultiCommand('activateObjectives', $this->lng->txt('set_online'));
73 $this->addMultiCommand('deactivateObjectives', $this->lng->txt('set_offline'));
74 $this->addMultiCommand('askDeleteObjectives', $this->lng->txt('delete'));
75 $this->addCommandButton('saveSorting', $this->lng->txt('sorting_save'));
76 }
77
78 public function getSettings(): ilLOSettings
79 {
80 return $this->settings;
81 }
82
83 protected function fillRow(array $a_set): void
84 {
85 $this->tpl->setVariable('VAL_ID', $a_set['id']);
86 $this->tpl->setVariable('VAL_POSITION', $a_set['position']);
87
88 // begin-patch lok
89 if ($a_set['online']) {
90 $this->tpl->setVariable('VAL_ONOFFLINE', $this->lng->txt('online'));
91 $this->tpl->setVariable('ONOFFLINE_CLASS', 'smallgreen');
92 } else {
93 $this->tpl->setVariable('VAL_ONOFFLINE', $this->lng->txt('offline'));
94 $this->tpl->setVariable('ONOFFLINE_CLASS', 'smallred');
95 }
96
97 if ($a_set['passes']) {
98 $this->tpl->setVariable('PASSES_TXT', $this->lng->txt('crs_loc_passes_info'));
99 $this->tpl->setVariable('PASSES_VAL', $a_set['passes']);
100 }
101
102 // begin-patch lok
103 $this->ctrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', $a_set['id']);
104 $this->tpl->setVariable('VAL_TITLE_LINKED', $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit'));
105 // end-patch lok
106
107 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
108 if (strlen($a_set['description'])) {
109 $this->tpl->setVariable('VAL_DESC', $a_set['description']);
110 }
111
112 // materials
113 foreach ($a_set['materials'] as $data) {
114 if ($data['items'] ?? false) {
115 $this->tpl->touchBlock('ul_begin');
116 foreach ($data['items'] as $pg_st) {
117 $this->tpl->setCurrentBlock('st_pg');
118 $this->tpl->setVariable('MAT_IMG', ilObject::_getIcon($pg_st['obj_id'], "tiny", $pg_st['type']));
119 $this->tpl->setVariable('MAT_ALT', $this->lng->txt('obj_' . $pg_st['type']));
120 $title = ilLMObject::_lookupTitle($pg_st['obj_id']);
121 $this->tpl->setVariable('MAT_TITLE', $title);
122 $this->tpl->parseCurrentBlock();
123 }
124 $this->tpl->touchBlock('ul_end');
125 } else {
126 $this->tpl->touchBlock('new_line');
127 }
128 $this->tpl->setCurrentBlock('mat_row');
129 $this->tpl->setVariable('LM_IMG', ilObject::_getIcon($data['obj_id'], "tiny", $data['type']));
130 $this->tpl->setVariable('LM_ALT', $this->lng->txt('obj_' . $data['type']));
131
132 if ($data['online']) {
133 $this->tpl->setCurrentBlock('mat_online');
134 $this->tpl->setVariable('MAT_VAL_ONOFFLINE', $this->lng->txt('online'));
135 } else {
136 $this->tpl->setCurrentBlock('mat_offline');
137 $this->tpl->setVariable('MAT_VAL_ONOFFLINE', $this->lng->txt('offline'));
138 }
139 $this->tpl->parseCurrentBlock();
140 $this->tpl->setCurrentBlock('mat_row');
141
142 if ($data['type'] == 'catr' || $data['type'] == 'crsr' || $data['type'] == 'grpr') {
143 $this->tpl->setVariable(
144 'LM_TITLE',
146 );
147 } else {
148 $this->tpl->setVariable('LM_TITLE', ilObject::_lookupTitle($data['obj_id']));
149 }
150
151 $this->tpl->parseCurrentBlock();
152 }
153
154 // self assessment
155 // begin-patch lok
156 if ($this->getSettings()->worksWithInitialTest()) {
157 if ($this->getSettings()->hasSeparateInitialTests()) {
158 if ($a_set['initial'] ?? false) {
159 $obj_id = ilObject::_lookupObjId($a_set['initial']);
160 $this->tpl->setCurrentBlock('initial_test_per_objective');
161 $this->tpl->setVariable('IT_IMG', ilObject::_getIcon($obj_id, 'tiny'));
162 $this->tpl->setVariable('IT_ALT', $this->lng->txt('obj_tst'));
163 $this->tpl->setVariable('IT_TITLE', ilObject::_lookupTitle($obj_id));
164 $this->tpl->setVariable('IT_TITLE_LINK', ilLink::_getLink($a_set['initial']));
165
166 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $a_set['initial']);
167 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway');
168 $this->tpl->setVariable(
169 'IT_TITLE_LINK',
170 $this->ctrl->getLinkTargetByClass('ilobjtestgui')
171 );
172
173 $this->tpl->parseCurrentBlock();
174 } else {
175 $this->tpl->touchBlock('with_self_test');
176 }
177 } else {
178 foreach (($a_set['self'] ?? []) as $test) {
179 // begin-patch lok
180 foreach ((array) ($test['questions'] ?? []) as $question) {
181 $this->tpl->setCurrentBlock('self_qst_row');
182 $this->tpl->setVariable('SELF_QST_TITLE', $question['title']);
183 $this->tpl->parseCurrentBlock();
184 }
185 if (count($test['questions'] ?? []) === 0) {
186 $this->tpl->touchBlock('self_qst_row');
187 }
188 // end-patch lok
189 }
190 // begin-patch lok
191 if (count($a_set['self'] ?? []) === 0) {
192 $this->tpl->touchBlock('self_qst_row');
193 }
194 }
195
196 // end-patch lok
197 }
198 // end-patch lok
199
200 // final test questions
201 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) {
202 if ($a_set['final'] ?? false) {
203 $obj_id = ilObject::_lookupObjId($a_set['final']);
204 $this->tpl->setCurrentBlock('final_test_per_objective');
205 $this->tpl->setVariable('FT_IMG', ilObject::_getIcon($obj_id, 'tiny'));
206 $this->tpl->setVariable('FT_ALT', $this->lng->txt('obj_tst'));
207 $this->tpl->setVariable('FT_TITLE', ilObject::_lookupTitle($obj_id));
208
209 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $a_set['final']);
210 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway');
211 $this->tpl->setVariable(
212 'FT_TITLE_LINK',
213 $this->ctrl->getLinkTargetByClass('ilobjtestgui')
214 );
215
216 $this->tpl->parseCurrentBlock();
217 } else {
218 $this->tpl->touchBlock('with_final_test');
219 }
220 } else {
221 foreach ((array) ($a_set['final'] ?? []) as $test) {
222 foreach ((array) ($test['questions'] ?? []) as $question) {
223 $this->tpl->setCurrentBlock('final_qst_row');
224 $this->tpl->setVariable('FINAL_QST_TITLE', $question['title'] ?? '');
225 $this->tpl->parseCurrentBlock();
226 }
227 if (count($test['questions'] ?? []) === 0) {
228 $this->tpl->touchBlock('final_qst_row');
229 }
230 }
231 if (count($a_set['final'] ?? []) === 0) {
232 $this->tpl->touchBlock('final_qst_row');
233 }
234 }
235 $this->ctrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', $a_set['id']);
236 $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit'));
237 $this->tpl->setVariable('TXT_EDIT', $this->lng->txt('edit'));
238
239 $dropDownItems = array();
240
241 $dropDownItems[] = $this->uiFactory->button()->shy(
242 $this->lng->txt('edit'),
243 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit')
244 );
245
246 // materials
247 $dropDownItems[] = $this->uiFactory->button()->shy(
248 $this->lng->txt('crs_objective_action_materials'),
249 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'materialAssignment')
250 );
251
252 // itest
253 if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) {
254 $dropDownItems[] = $this->uiFactory->button()->shy(
255 $this->lng->txt('crs_objective_action_itest'),
256 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'selfAssessmentAssignment')
257 );
258 }
259 // qtest
260 if ($this->getSettings()->hasSeparateQualifiedTests()) {
261 // @todo
262 } else {
263 $dropDownItems[] = $this->uiFactory->button()->shy(
264 $this->lng->txt('crs_objective_action_qtest'),
265 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'finalTestAssignment')
266 );
267 }
268
269 $this->ctrl->setParameterByClass('illopagegui', 'objective_id', $a_set['id']);
270
271 $dropDownItems[] = $this->uiFactory->button()->shy(
272 $this->lng->txt('crs_edit_lo_introduction'),
273 $this->ctrl->getLinkTargetByClass('illopagegui', 'edit')
274 );
275 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
276 ->withAriaLabel('Actions');
277 $this->tpl->setVariable('VAL_ACTIONS', $this->renderer->render($dropDown));
278
279 // end-patch lok
280 }
281
282 public function parse(array $a_objective_ids): void
283 {
284 $position = 1;
285 $objectives = [];
286 foreach ($a_objective_ids as $objective_id) {
287 $objective = new ilCourseObjective($this->course_obj, $objective_id);
288
289 $objective_data = [];
290 $objective_data['id'] = $objective_id;
291 $objective_data['position'] = sprintf("%.1f", $position++) * 10;
292 $objective_data['title'] = $objective->getTitle();
293 $objective_data['description'] = $objective->getDescription();
294
295 $objective_data['online'] = $objective->isActive();
296 $objective_data['passes'] = $objective->getPasses();
297
298 // assigned materials
299 $materials = array();
300 $ass_materials = new ilCourseObjectiveMaterials($objective_id);
301 foreach ($ass_materials->getMaterials() as $material) {
302 $materials[$material['ref_id']]['obj_id'] = $obj_id = ilObject::_lookupObjId($material['ref_id']);
303 $materials[$material['ref_id']]['type'] = ilObject::_lookupType($obj_id);
304
305 switch ($material['type']) {
306 case 'pg':
307 case 'st':
308 $materials[$material['ref_id']]['items'][] = $material;
309 break;
310 default:
311 }
312 $materials[$material['ref_id']]['online'] = !ilObject::lookupOfflineStatus($obj_id);
313 }
314 $objective_data['materials'] = $materials;
315 $question_obj = new ilCourseObjectiveQuestion($objective_id);
316
317 // self assessment questions
318 // begin-patch lok
319 if ($this->getSettings()->worksWithInitialTest()) {
320 if ($this->getSettings()->hasSeparateInitialTests()) {
321 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
322 $assignment = $assignments->getAssignmentByObjective(
323 $objective_id,
325 );
326
327 $objective_data['initial'] = 0;
328 if ($assignment instanceof ilLOTestAssignment) {
329 $test_id = $assignment->getTestRefId();
330
331 $factory = new ilObjectFactory();
332 $test_candidate = $factory->getInstanceByRefId($test_id, false);
333 if ($test_candidate instanceof ilObjTest) {
334 $objective_data['initial'] = $test_id;
335 }
336 }
337 } elseif (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getInitialTest()))) {
338 $test = array();
339 $objective_data['self'] = [];
341 $this->course_obj->getId(),
342 $objective_id,
343 ilObject::_lookupObjId($this->getSettings()->getInitialTest()),
345 ) as $sequence_id
346 ) {
347 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getInitialTest());
348 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getInitialTest(), $sequence_id);
349 if ($qst) {
350 $test['questions'][] = array('title' => $qst);
351 }
352 $objective_data['self'] = array($test);
353 }
354 } else {
355 $tests = array();
356 foreach ($question_obj->getSelfAssessmentTests() as $test) {
357 $questions = array();
358 foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) {
359 $questions[] = $qst;
360 }
361 $tmp_test = $test;
362 $tmp_test['questions'] = $questions;
363
364 $tests[] = $tmp_test;
365 }
366 $objective_data['self'] = $tests;
367 }
368 }
369
370 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) {
371 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
372 $assignment = $assignments->getAssignmentByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
373
374 $objective_data['final'] = 0;
375 if ($assignment instanceof ilLOTestAssignment) {
376 $test_id = $assignment->getTestRefId();
377
378 $factory = new ilObjectFactory();
379 $test_candidate = $factory->getInstanceByRefId($test_id, false);
380 if ($test_candidate instanceof ilObjTest) {
381 $objective_data['final'] = $test_id;
382 }
383 }
384 } elseif ($this->getSettings()->getQualifiedTest()) {
385 if (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()))) {
386 $test = array();
388 $this->course_obj->getId(),
389 $objective_id,
390 ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()),
392 ) as $sequence_id
393 ) {
394 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getQualifiedTest());
395 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getQualifiedTest(), $sequence_id);
396 if ($qst) {
397 $test['questions'][] = array('title' => $qst);
398 }
399 $objective_data['final'] = array($test);
400 }
401 } else {
402 $tests = array();
403 foreach ($question_obj->getFinalTests() as $test) {
404 $questions = array();
405 foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) {
406 $questions[] = $qst;
407 }
408 $tmp_test = $test;
409 $tmp_test['questions'] = $questions;
410
411 $tests[] = $tmp_test;
412 }
413 $objective_data['final'] = $tests;
414 }
415 }
416 // end-patch lok
417 $objectives[] = $objective_data;
418 }
419 $this->setData($objectives);
420 }
421}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static _lookupTargetTitle(int $a_obj_id)
class ilCourseObjectiveMaterials
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilcourseobjective
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(object $a_parent_obj, ilObject $a_course_obj)
fillRow(array $a_set)
Standard Version of Fill Row.
static _lookupTitle(int $a_obj_id)
static lookupSequencesByType(int $a_container_id, int $a_objective_id, int $a_test_id, int $a_test_type)
Settings for LO courses.
static getInstanceByObjId(int $a_obj_id)
const TYPE_QUALIFYING_SELECTED
Settings for LO courses.
static getInstance(int $a_container_id)
static lookupRandomTest(int $a_test_obj_id)
Class ilObjectFactory This class offers methods to get instances of the type-specific object classes ...
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
enable(string $a_module_name)
disable(string $a_module_name)
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$objectives