ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLOTestAssignmentTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 public const TYPE_MULTIPLE_ASSIGNMENTS = 1;
27 public const TYPE_SINGLE_ASSIGNMENTS = 2;
28
29 private int $test_type = 0;
32 private int $container_id = 0;
33
34 protected ilDBInterface $db;
35
36 public function __construct(
37 object $a_parent_obj,
38 string $a_parent_cmd,
39 int $a_container_id,
40 int $a_test_type,
41 int $a_assignment_type = self::TYPE_SINGLE_ASSIGNMENTS
42 ) {
43 global $DIC;
44
45 $this->test_type = $a_test_type;
46 $this->assignment_type = $a_assignment_type;
47 $this->container_id = $a_container_id;
48 $this->db = $DIC->database();
49
50 $this->setId('obj_loc_' . $a_container_id);
51 parent::__construct($a_parent_obj, $a_parent_cmd);
52
53 $this->settings = ilLOSettings::getInstanceByObjId($a_container_id);
54 $this->initTitle();
55 $this->setTopCommands(false);
56 }
57
58 public function initTitle(): void
59 {
60 switch ($this->test_type) {
62 if ($this->getAssignmentType() == self::TYPE_SINGLE_ASSIGNMENTS) {
63 if ($this->getSettings()->isInitialTestQualifying()) {
64 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_its_q_all'));
65 } else {
66 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_its_nq_all'));
67 }
68 } elseif ($this->getSettings()->isInitialTestQualifying()) {
69 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_it_q'));
70 } else {
71 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_it_nq'));
72 }
73 break;
74
76 if ($this->getAssignmentType() == self::TYPE_SINGLE_ASSIGNMENTS) {
77 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_qts_all'));
78 } else {
79 $this->setTitle($this->lng->txt('crs_loc_settings_tbl_qt'));
80 }
81 break;
82 }
83 }
84
85 public function getSettings(): ilLOSettings
86 {
87 return $this->settings;
88 }
89
90 public function getAssignmentType(): int
91 {
93 }
94
98 public function init(): void
99 {
100 $this->addColumn('', '', '20px');
101 $this->addColumn($this->lng->txt('title'), 'title');
102
103 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
104 $this->addColumn($this->lng->txt('crs_objectives'), 'objective');
105 }
106
107 $this->addColumn($this->lng->txt('crs_loc_tbl_tst_type'), 'ttype');
108 $this->addColumn($this->lng->txt('crs_loc_tbl_tst_qst_qpl'), 'qstqpl');
109
110 $this->setRowTemplate("tpl.crs_loc_tst_row.html", "components/ILIAS/Course");
111 $this->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this->getParentObject()));
112
113 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
114 $this->addMultiCommand('confirmDeleteTests', $this->lng->txt('crs_loc_delete_assignment'));
115 $this->setDefaultOrderField('objective');
116 $this->setDefaultOrderDirection('asc');
117 } else {
118 $this->addMultiCommand('confirmDeleteTest', $this->lng->txt('crs_loc_delete_assignment'));
119 $this->setDefaultOrderField('title');
120 $this->setDefaultOrderDirection('asc');
121 }
122 }
123
124 protected function fillRow(array $a_set): void
125 {
126 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
127 $this->tpl->setVariable('VAL_ID', $a_set['assignment_id']);
128 } else {
129 $this->tpl->setVariable('VAL_ID', $a_set['ref_id']);
130 }
131 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
132
133 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $a_set['ref_id']);
134 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway');
135 $this->tpl->setVariable(
136 'TITLE_LINK',
137 $this->ctrl->getLinkTargetByClass('ilobjtestgui')
138 );
139
140 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
141 $this->tpl->setCurrentBlock('objectives');
142 $this->tpl->setVariable('VAL_OBJECTIVE', (string) $a_set['objective']);
143 $this->tpl->parseCurrentBlock();
144 }
145
146 if (strlen($a_set['description'])) {
147 $this->tpl->setVariable('VAL_DESC', $a_set['description']);
148 }
149
150 $type = '';
151 switch ($a_set['ttype']) {
153 $type = $this->lng->txt('tst_question_set_type_fixed');
154 break;
155
157 $type = $this->lng->txt('tst_question_set_type_random');
158 break;
159 }
160
161 $this->tpl->setVariable('VAL_TTYPE', $type);
162 $this->tpl->setVariable('VAL_QST_QPL', $a_set['qst_info']);
163
164 if (isset($a_set['qpls']) && is_array($a_set['qpls']) && $a_set['qpls'] !== []) {
165 foreach ($a_set['qpls'] as $title) {
166 $this->tpl->setCurrentBlock('qpl');
167 $this->tpl->setVariable('MAT_TITLE', $title);
168 $this->tpl->parseCurrentBlock();
169 }
170 $this->tpl->touchBlock('ul_begin');
171 $this->tpl->touchBlock('ul_end');
172 }
173 }
174
175 public function parseMultipleAssignments(): void
176 {
177 $assignments = ilLOTestAssignments::getInstance($this->container_id);
178 $available = $assignments->getAssignmentsByType($this->test_type);
179 $data = array();
180 foreach ($available as $assignment) {
181 try {
182 $tmp = $this->doParse($assignment->getTestRefId(), $assignment->getObjectiveId());
184 $assignment->delete();
185 continue;
186 }
187 if ($tmp !== []) {
188 // add assignment id
189 $tmp['assignment_id'] = $assignment->getAssignmentId();
190 $data[] = $tmp;
191 }
192 }
193
194 $this->setData($data);
195 }
196
197 public function parse(int $a_tst_ref_id): void
198 {
199 $this->setData(array($this->doParse($a_tst_ref_id)));
200 }
201
206 protected function doParse(int $a_tst_ref_id, int $a_objective_id = 0): array
207 {
208 $tst = ilObjectFactory::getInstanceByRefId($a_tst_ref_id, false);
209
210 if (!$tst instanceof ilObjTest) {
211 throw new ilLOInvalidConfigurationException('No valid test given');
212 }
213 $tst_data['ref_id'] = $tst->getRefId();
214 $tst_data['title'] = $tst->getTitle();
215 $tst_data['description'] = $tst->getLongDescription();
216 $tst_data['ttype'] = $tst->getQuestionSetType();
217
218 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
219 $tst_data['objective'] = ilCourseObjective::lookupObjectiveTitle($a_objective_id);
220 }
221
222 switch ($tst->getQuestionSetType()) {
224 $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_num_qst');
225 $tst_data['qst_info'] .= (' ' . count($tst->getAllQuestions()));
226 break;
227
228 default:
229 // get available assiged question pools
230
232 $GLOBALS['DIC']['ilDB'],
233 $tst,
235 $GLOBALS['DIC']['ilDB'],
236 $tst
237 )
238 );
239
240 $list->loadDefinitions();
241
242 // tax translations
243 $translator = new ilTestQuestionFilterLabelTranslator($this->db, $this->lng);
244 $translator->loadLabels($list);
245
246 $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_qpls');
247 $num = 0;
248 foreach ($list as $definition) {
250 $title = $definition->getPoolTitle();
251 $filterTitle = array();
252 $filterTitle[] = $translator->getTaxonomyFilterLabel($definition->getMappedTaxonomyFilter());
253 $filterTitle[] = $translator->getTypeFilterLabel($definition->getTypeFilter());
254 if (!empty($filterTitle)) {
255 $title .= ' -> ' . implode(' / ', $filterTitle);
256 }
257 $tst_data['qpls'][] = $title;
258 ++$num;
259 }
260 if ($num === 0) {
261 $tst_data['qst_info'] .= (' ' . 0);
262 }
263 break;
264 }
265 return $tst_data;
266 }
267}
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Settings for LO courses.
static getInstanceByObjId(int $a_obj_id)
Class ilLOTestAssignmentTableGUI.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_container_id, int $a_test_type, int $a_assignment_type=self::TYPE_SINGLE_ASSIGNMENTS)
fillRow(array $a_set)
Standard Version of Fill Row.
static getInstance(int $a_container_id)
const QUESTION_SET_TYPE_RANDOM
const QUESTION_SET_TYPE_FIXED
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
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)
setDefaultOrderField(string $a_defaultorderfield)
setTopCommands(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
Interface ilDBInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54