ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTestQuestionsTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('./Services/Table/classes/class.ilTable2GUI.php');
5require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6
17{
21 protected $questionTitleLinksEnabled = false;
22
27
31 protected $questionManagingEnabled = false;
32
37
41 protected $questionPositioningEnabled = false;
42
47
51 protected $totalPoints = 0;
52
56 protected $totalWorkingTime = '';
57
61 private $position = 0;
62
70 public function __construct($a_parent_obj, $a_parent_cmd, $parentRefId)
71 {
72 $this->setId('tst_qst_lst_' . $parentRefId);
73
74 parent::__construct($a_parent_obj, $a_parent_cmd);
75
76 $this->setFormName('questionbrowser');
77 $this->setStyle('table', 'fullwidth');
78
79 $this->setExternalSegmentation(true);
80
81 $this->setRowTemplate("tpl.il_as_tst_questions_row.html", "Modules/Test");
82
83 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
84
85 $this->disable('sort');
86 $this->enable('header');
87
88 $this->setShowRowsSelector(false);
89 }
90
94 public function getSelectableColumns()
95 {
96 $cols = array(
97 'qid' => array('txt' => $this->lng->txt('question_id'), 'default' => true),
98 'description' => array('txt' => $this->lng->txt('description'), 'default' => false),
99 'author' => array('txt' => $this->lng->txt('author'), 'default' => false),
100 'lifecycle' => array('txt' => $this->lng->txt('qst_lifecycle'), 'default' => true),
101 'working_time' => array('txt' => $this->lng->txt('working_time'), 'default' => false)
102 );
103
104 return $cols;
105 }
106
110 public function init()
111 {
112 $this->initColumns();
113 $this->initCommands();
114
115 if ($this->isQuestionManagingEnabled()) {
116 $this->setSelectAllCheckbox('q_id');
117 }
118 }
119
123 protected function initColumns()
124 {
125 if ($this->isCheckboxColumnRequired()) {
126 $this->addColumn('', 'f', '1%', true);
127 }
128
129 if ($this->isQuestionPositioningEnabled()) {
130 $this->addColumn('', 'f', '1%');
131 }
132
133 if ($this->isColumnSelected('qid')) {
134 $this->addColumn($this->lng->txt('question_id'), 'qid', '');
135 }
136
137 $this->addColumn($this->lng->txt("tst_question_title"), 'title', '');
138
140 $this->addColumn($this->lng->txt("obligatory"), 'obligatory', '');
141 }
142
143 if ($this->isColumnSelected('description')) {
144 $this->addColumn($this->lng->txt('description'), 'description', '');
145 }
146
147 $this->addColumn($this->lng->txt("tst_question_type"), 'type', '');
148 $this->addColumn($this->buildPointsHeader(), '', '');
149
150 if ($this->isColumnSelected('author')) {
151 $this->addColumn($this->lng->txt('author'), 'author', '');
152 }
153 if ($this->isColumnSelected('lifecycle')) {
154 $this->addColumn($this->lng->txt('qst_lifecycle'), 'lifecycle', '');
155 }
156 if ($this->isColumnSelected('working_time')) {
157 $this->addColumn($this->buildWorkingTimeHeader(), 'working_time', '');
158 }
159
160 $this->addColumn($this->lng->txt('qpl'), 'qpl', '');
161
163 $this->addColumn('', '', '1%');
164 }
165 }
166
167 protected function initCommands()
168 {
169 if ($this->isQuestionManagingEnabled()) {
170 $this->addMultiCommand('removeQuestions', $this->lng->txt('remove_question'));
171 $this->addMultiCommand('moveQuestions', $this->lng->txt('move'));
172 }
173
174 if ($this->isPositionInsertCommandsEnabled()) {
175 $this->addMultiCommand('insertQuestionsBefore', $this->lng->txt('insert_before'));
176 $this->addMultiCommand('insertQuestionsAfter', $this->lng->txt('insert_after'));
177 }
178
179 if ($this->isQuestionManagingEnabled()) {
180 $this->addMultiCommand('copyQuestion', $this->lng->txt('copy'));
181 $this->addMultiCommand('copyAndLinkToQuestionpool', $this->lng->txt('copy_and_link_to_questionpool'));
182 }
183
184 if ($this->isTableSaveCommandRequired()) {
185 $this->addCommandButton('saveOrderAndObligations', $this->buildTableSaveCommandLabel());
186 }
187 }
188
196 public function fillRow($data)
197 {
198 if ($this->isCheckboxColumnRequired()) {
199 $this->tpl->setVariable("CHECKBOX_QID", $data['question_id']);
200 }
201
202 if ($this->isQuestionPositioningEnabled()) {
203 $this->position += 10;
204 $inputField = $this->buildPositionInput($data['question_id'], $this->position);
205
206 $this->tpl->setVariable("QUESTION_POSITION", $inputField);
207 $this->tpl->setVariable("POSITION_QID", $data['question_id']);
208 }
209
210 if ($this->isColumnSelected('qid')) {
211 $this->tpl->setVariable("QUESTION_ID_PRESENTATION", $data['question_id']);
212 }
213
214 if ($this->isQuestionTitleLinksEnabled()) {
215 $this->tpl->setVariable("QUESTION_TITLE", $this->buildQuestionTitleLink($data));
216 } else {
217 $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
218 }
219
220 if (!$data['complete']) {
221 $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("icon_alert.svg"));
222 $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
223 $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
224 }
225
227 $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->buildObligatoryColumnContent($data));
228 }
229
230 if ($this->isColumnSelected('description')) {
231 $this->tpl->setVariable("QUESTION_COMMENT", $data["description"] ? $data["description"] : '&nbsp;');
232 }
233
234 $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($data["type_tag"]));
235 $this->tpl->setVariable("QUESTION_POINTS", $data["points"]);
236
237 if ($this->isColumnSelected('author')) {
238 $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
239 }
240
241 if ($this->isColumnSelected('lifecycle')) {
242 try {
243 $lifecycle = ilAssQuestionLifecycle::getInstance($data['lifecycle'])->getTranslation($this->lng);
244 $this->tpl->setVariable("QUESTION_LIFECYCLE", $lifecycle);
246 $this->tpl->setVariable("QUESTION_LIFECYCLE", '');
247 }
248 }
249
250 if ($this->isColumnSelected('working_time')) {
251 $this->tpl->setVariable("QUESTION_WORKING_TIME", $data["working_time"]);
252 }
253
254 if (ilObject::_lookupType($data["orig_obj_fi"]) == 'qpl') {
255 $this->tpl->setVariable("QUESTION_POOL", ilObject::_lookupTitle($data["orig_obj_fi"]));
256 } else {
257 $this->tpl->setVariable("QUESTION_POOL", $this->lng->txt('tst_question_not_from_pool_info'));
258 }
259
261 $this->tpl->setVariable('ROW_ACTIONS', $this->buildQuestionRemoveButton($data));
262 }
263 }
264
269 protected function buildQuestionRemoveButton(array $rowData) : string
270 {
271 $this->ctrl->setParameter($this->getParentObject(), 'removeQid', $rowData['question_id']);
272 $removeUrl = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
273 $this->ctrl->setParameter($this->getParentObject(), 'removeQid', '');
274
275 $button = ilLinkButton::getInstance();
276 $button->setCaption('remove_question');
277 $button->setUrl($removeUrl);
278
279 return $button->render();
280 }
281
286 protected function buildQuestionTitleLink(array $rowData) : string
287 {
288 $this->ctrl->setParameter(
289 $this->getParentObject(),
290 'eqpl',
291 current(ilObject::_getAllReferences($rowData['obj_fi']))
292 );
293
294 $this->ctrl->setParameter(
295 $this->getParentObject(),
296 'eqid',
297 $rowData['question_id']
298 );
299
300 $questionHref = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
301
302 $this->ctrl->setParameter($this->getParentObject(), 'eqpl', '');
303 $this->ctrl->setParameter($this->getParentObject(), 'eqid', '');
304
305 return '<a href="' . $questionHref . '">' . $rowData["title"] . '</a>';
306 }
307
312 protected function buildObligatoryColumnContent(array $rowData) : string
313 {
314 if (!$rowData['obligationPossible']) {
315 return '&nbsp;';
316 }
317
318 if ($rowData['obligatory'] && !$this->isQuestionManagingEnabled()) {
319 // obligatory icon
320 return ilGlyphGUI::get(ilGlyphGUI::EXCLAMATION, $this->lng->txt('question_obligatory'));
321 }
322
323 $checkedAttr = $rowData['obligatory'] ? 'checked="checked"' : '';
324 return '<input type="checkbox" name="obligatory[' . $rowData['question_id'] . ']" value="1" ' . $checkedAttr . ' />';
325 }
326
332 protected function buildPositionInput($questionId, $position) : string
333 {
334 return '<input type="text" name="order[q_' . $questionId . ']" value="' . $position . '" maxlength="3" size="3" />';
335 }
336
340 protected function buildTableSaveCommandLabel() : string
341 {
343 return $this->lng->txt('saveOrderAndObligations');
344 }
345
347 return $this->lng->txt('saveObligations');
348 }
349
350 if ($this->isQuestionPositioningEnabled()) {
351 return $this->lng->txt('saveOrder');
352 }
353
354 return $this->lng->txt('save');
355 }
356
360 protected function buildPointsHeader() : string
361 {
362 if ($this->getTotalPoints()) {
363 return $this->lng->txt('points') . ' (' . $this->getTotalPoints() . ')';
364 }
365
366 return $this->lng->txt('points');
367 }
368
372 protected function buildWorkingTimeHeader() : string
373 {
374 if (strlen($this->getTotalWorkingTime())) {
375 return $this->lng->txt('working_time') . ' (' . $this->getTotalWorkingTime() . ')';
376 }
377
378 return $this->lng->txt('working_time');
379 }
380
384 protected function isTableSaveCommandRequired() : bool
385 {
386 if (!$this->isQuestionManagingEnabled()) {
387 return false;
388 }
389
391 }
392
396 protected function isCheckboxColumnRequired() : bool
397 {
399 }
400
404 public function isQuestionManagingEnabled() : bool
405 {
407 }
408
413 {
414 $this->questionManagingEnabled = $questionManagingEnabled;
415 }
416
420 public function isPositionInsertCommandsEnabled() : bool
421 {
423 }
424
429 {
430 $this->positionInsertCommandsEnabled = $positionInsertCommandsEnabled;
431 }
432
436 public function isQuestionPositioningEnabled() : bool
437 {
439 }
440
445 {
446 $this->questionPositioningEnabled = $questionPositioningEnabled;
447 }
448
453 {
455 }
456
461 {
462 $this->obligatoryQuestionsHandlingEnabled = $obligatoryQuestionsHandlingEnabled;
463 }
464
468 public function getTotalPoints() : float
469 {
470 return $this->totalPoints;
471 }
472
476 public function setTotalPoints(float $totalPoints)
477 {
478 $this->totalPoints = $totalPoints;
479 }
480
484 public function getTotalWorkingTime() : string
485 {
487 }
488
493 {
494 $this->totalWorkingTime = $totalWorkingTime;
495 }
496
500 public function isQuestionTitleLinksEnabled() : bool
501 {
503 }
504
509 {
510 $this->questionTitleLinksEnabled = $questionTitleLinksEnabled;
511 }
512
516 public function isQuestionRemoveRowButtonEnabled() : bool
517 {
519 }
520
525 {
526 $this->questionRemoveRowButtonEnabled = $questionRemoveRowButtonEnabled;
527 }
528}
An exception for terminatinating execution or to throw for unit testing.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
static get($a_glyph, $a_text="")
Get glyph html.
static getInstance()
Factory.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilTable2GUI.
getParentCmd()
Get parent command.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getParentObject()
Get parent object.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
isColumnSelected($a_col)
Is given column selected?
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
disable($a_module_name)
diesables particular modules of table
setStyle($a_element, $a_style)
enable($a_module_name)
enables particular modules of table
setQuestionRemoveRowButtonEnabled(bool $questionRemoveRowButtonEnabled)
setQuestionManagingEnabled(bool $questionManagingEnabled)
setPositionInsertCommandsEnabled(bool $positionInsertCommandsEnabled)
__construct($a_parent_obj, $a_parent_cmd, $parentRefId)
Constructor.
buildPositionInput($questionId, $position)
setQuestionTitleLinksEnabled(bool $questionTitleLinksEnabled)
setQuestionPositioningEnabled(bool $questionPositioningEnabled)
setObligatoryQuestionsHandlingEnabled(bool $obligatoryQuestionsHandlingEnabled)
setTotalWorkingTime(string $totalWorkingTime)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$cols
Definition: xhr_table.php:11