ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_once('./Services/Table/classes/class.ilTable2GUI.php');
5 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6 
17 {
21  protected $questionTitleLinksEnabled = false;
22 
27 
31  protected $questionManagingEnabled = false;
32 
36  protected $positionInsertCommandsEnabled = false;
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  'working_time' => array('txt' => $this->lng->txt('working_time'), 'default' => false)
101  );
102 
103  return $cols;
104  }
105 
109  public function init()
110  {
111  $this->initColumns();
112  $this->initCommands();
113 
114  if ($this->isQuestionManagingEnabled()) {
115  $this->setSelectAllCheckbox('q_id');
116  }
117  }
118 
122  protected function initColumns()
123  {
124  if ($this->isCheckboxColumnRequired()) {
125  $this->addColumn('', 'f', '1%', true);
126  }
127 
128  if ($this->isQuestionPositioningEnabled()) {
129  $this->addColumn('', 'f', '1%');
130  }
131 
132  if ($this->isColumnSelected('qid')) {
133  $this->addColumn($this->lng->txt('question_id'), 'qid', '');
134  }
135 
136  $this->addColumn($this->lng->txt("tst_question_title"), 'title', '');
137 
139  $this->addColumn($this->lng->txt("obligatory"), 'obligatory', '');
140  }
141 
142  if ($this->isColumnSelected('description')) {
143  $this->addColumn($this->lng->txt('description'), 'description', '');
144  }
145 
146  $this->addColumn($this->lng->txt("tst_question_type"), 'type', '');
147  $this->addColumn($this->buildPointsHeader(), '', '');
148 
149  if ($this->isColumnSelected('author')) {
150  $this->addColumn($this->lng->txt('author'), 'author', '');
151  }
152  if ($this->isColumnSelected('working_time')) {
153  $this->addColumn($this->buildWorkingTimeHeader(), 'working_time', '');
154  }
155 
156  $this->addColumn($this->lng->txt('qpl'), 'qpl', '');
157 
158  if ($this->isQuestionRemoveRowButtonEnabled()) {
159  $this->addColumn('', '', '1%');
160  }
161  }
162 
163  protected function initCommands()
164  {
165  if ($this->isQuestionManagingEnabled()) {
166  $this->addMultiCommand('removeQuestions', $this->lng->txt('remove_question'));
167  $this->addMultiCommand('moveQuestions', $this->lng->txt('move'));
168  }
169 
170  if ($this->isPositionInsertCommandsEnabled()) {
171  $this->addMultiCommand('insertQuestionsBefore', $this->lng->txt('insert_before'));
172  $this->addMultiCommand('insertQuestionsAfter', $this->lng->txt('insert_after'));
173  }
174 
175  if ($this->isQuestionManagingEnabled()) {
176  $this->addMultiCommand('copyQuestion', $this->lng->txt('copy'));
177  $this->addMultiCommand('copyAndLinkToQuestionpool', $this->lng->txt('copy_and_link_to_questionpool'));
178  }
179 
180  if ($this->isTableSaveCommandRequired()) {
181  $this->addCommandButton('saveOrderAndObligations', $this->buildTableSaveCommandLabel());
182  }
183  }
184 
192  public function fillRow($data)
193  {
194  if ($this->isCheckboxColumnRequired()) {
195  $this->tpl->setVariable("CHECKBOX_QID", $data['question_id']);
196  }
197 
198  if ($this->isQuestionPositioningEnabled()) {
199  $this->position += 10;
200  $inputField = $this->buildPositionInput($data['question_id'], $this->position);
201 
202  $this->tpl->setVariable("QUESTION_POSITION", $inputField);
203  $this->tpl->setVariable("POSITION_QID", $data['question_id']);
204  }
205 
206  if ($this->isColumnSelected('qid')) {
207  $this->tpl->setVariable("QUESTION_ID_PRESENTATION", $data['question_id']);
208  }
209 
210  if ($this->isQuestionTitleLinksEnabled()) {
211  $this->tpl->setVariable("QUESTION_TITLE", $this->buildQuestionTitleLink($data));
212  } else {
213  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
214  }
215 
216  if (!$data['complete']) {
217  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("icon_alert.svg"));
218  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
219  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
220  }
221 
223  $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->buildObligatoryColumnContent($data));
224  }
225 
226  if ($this->isColumnSelected('description')) {
227  $this->tpl->setVariable("QUESTION_COMMENT", $data["description"] ? $data["description"] : '&nbsp;');
228  }
229 
230  $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($data["type_tag"]));
231  $this->tpl->setVariable("QUESTION_POINTS", $data["points"]);
232 
233  if ($this->isColumnSelected('author')) {
234  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
235  }
236 
237  if ($this->isColumnSelected('working_time')) {
238  $this->tpl->setVariable("QUESTION_WORKING_TIME", $data["working_time"]);
239  }
240 
241  if (ilObject::_lookupType($data["orig_obj_fi"]) == 'qpl') {
242  $this->tpl->setVariable("QUESTION_POOL", ilObject::_lookupTitle($data["orig_obj_fi"]));
243  } else {
244  $this->tpl->setVariable("QUESTION_POOL", $this->lng->txt('tst_question_not_from_pool_info'));
245  }
246 
247  if ($this->isQuestionRemoveRowButtonEnabled()) {
248  $this->tpl->setVariable('ROW_ACTIONS', $this->buildQuestionRemoveButton($data));
249  }
250  }
251 
256  protected function buildQuestionRemoveButton(array $rowData) : string
257  {
258  $this->ctrl->setParameter($this->getParentObject(), 'removeQid', $rowData['question_id']);
259  $removeUrl = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
260  $this->ctrl->setParameter($this->getParentObject(), 'removeQid', '');
261 
262  $button = ilLinkButton::getInstance();
263  $button->setCaption('remove_question');
264  $button->setUrl($removeUrl);
265 
266  return $button->render();
267  }
268 
273  protected function buildQuestionTitleLink(array $rowData) : string
274  {
275  $this->ctrl->setParameter(
276  $this->getParentObject(),
277  'eqpl',
278  current(ilObject::_getAllReferences($rowData['obj_fi']))
279  );
280 
281  $this->ctrl->setParameter(
282  $this->getParentObject(),
283  'eqid',
284  $rowData['question_id']
285  );
286 
287  $questionHref = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
288 
289  $this->ctrl->setParameter($this->getParentObject(), 'eqpl', '');
290  $this->ctrl->setParameter($this->getParentObject(), 'eqid', '');
291 
292  return '<a href="' . $questionHref . '">' . $rowData["title"] . '</a>';
293  }
294 
299  protected function buildObligatoryColumnContent(array $rowData) : string
300  {
301  if (!$rowData['obligationPossible']) {
302  return '&nbsp;';
303  }
304 
305  if ($rowData['obligatory'] && !$this->isQuestionManagingEnabled()) {
306  // obligatory icon
307  return ilGlyphGUI::get(ilGlyphGUI::EXCLAMATION, $this->lng->txt('question_obligatory'));
308  }
309 
310  $checkedAttr = $rowData['obligatory'] ? 'checked="checked"' : '';
311  return '<input type="checkbox" name="obligatory[' . $rowData['question_id'] . ']" value="1" ' . $checkedAttr . ' />';
312  }
313 
319  protected function buildPositionInput($questionId, $position) : string
320  {
321  return '<input type="text" name="order[q_' . $questionId . ']" value="' . $position . '" maxlength="3" size="3" />';
322  }
323 
327  protected function buildTableSaveCommandLabel() : string
328  {
330  return $this->lng->txt('saveOrderAndObligations');
331  }
332 
334  return $this->lng->txt('saveObligations');
335  }
336 
337  if ($this->isQuestionPositioningEnabled()) {
338  return $this->lng->txt('saveOrder');
339  }
340 
341  return $this->lng->txt('save');
342  }
343 
347  protected function buildPointsHeader() : string
348  {
349  if ($this->getTotalPoints()) {
350  return $this->lng->txt('points') . ' (' . $this->getTotalPoints() . ')';
351  }
352 
353  return $this->lng->txt('points');
354  }
355 
359  protected function buildWorkingTimeHeader() : string
360  {
361  if (strlen($this->getTotalWorkingTime())) {
362  return $this->lng->txt('working_time') . ' (' . $this->getTotalWorkingTime() . ')';
363  }
364 
365  return $this->lng->txt('working_time');
366  }
367 
371  protected function isTableSaveCommandRequired() : bool
372  {
373  if (!$this->isQuestionManagingEnabled()) {
374  return false;
375  }
376 
378  }
379 
383  protected function isCheckboxColumnRequired() : bool
384  {
386  }
387 
391  public function isQuestionManagingEnabled() : bool
392  {
394  }
395 
400  {
401  $this->questionManagingEnabled = $questionManagingEnabled;
402  }
403 
407  public function isPositionInsertCommandsEnabled() : bool
408  {
410  }
411 
416  {
417  $this->positionInsertCommandsEnabled = $positionInsertCommandsEnabled;
418  }
419 
423  public function isQuestionPositioningEnabled() : bool
424  {
426  }
427 
432  {
433  $this->questionPositioningEnabled = $questionPositioningEnabled;
434  }
435 
439  public function isObligatoryQuestionsHandlingEnabled() : bool
440  {
442  }
443 
448  {
449  $this->obligatoryQuestionsHandlingEnabled = $obligatoryQuestionsHandlingEnabled;
450  }
451 
455  public function getTotalPoints() : float
456  {
457  return $this->totalPoints;
458  }
459 
463  public function setTotalPoints(float $totalPoints)
464  {
465  $this->totalPoints = $totalPoints;
466  }
467 
471  public function getTotalWorkingTime() : string
472  {
474  }
475 
479  public function setTotalWorkingTime(string $totalWorkingTime)
480  {
481  $this->totalWorkingTime = $totalWorkingTime;
482  }
483 
487  public function isQuestionTitleLinksEnabled() : bool
488  {
490  }
491 
496  {
497  $this->questionTitleLinksEnabled = $questionTitleLinksEnabled;
498  }
499 
503  public function isQuestionRemoveRowButtonEnabled() : bool
504  {
506  }
507 
512  {
513  $this->questionRemoveRowButtonEnabled = $questionRemoveRowButtonEnabled;
514  }
515 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setQuestionManagingEnabled(bool $questionManagingEnabled)
setQuestionTitleLinksEnabled(bool $questionTitleLinksEnabled)
setStyle($a_element, $a_style)
setObligatoryQuestionsHandlingEnabled(bool $obligatoryQuestionsHandlingEnabled)
setExternalSegmentation($a_val)
Set external segmentation.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
static get($a_glyph, $a_text="")
Get glyph html.
static _lookupTitle($a_id)
lookup object title
setQuestionRemoveRowButtonEnabled(bool $questionRemoveRowButtonEnabled)
getParentCmd()
Get parent command.
getParentObject()
Get parent object.
setId($a_val)
Set id.
static _getAllReferences($a_id)
get all reference ids of object
Class ilTable2GUI.
setTotalWorkingTime(string $totalWorkingTime)
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.
setPositionInsertCommandsEnabled(bool $positionInsertCommandsEnabled)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
buildPositionInput($questionId, $position)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _lookupType($a_id, $a_reference=false)
lookup object type
setQuestionPositioningEnabled(bool $questionPositioningEnabled)
isColumnSelected($a_col)
Is given column selected?
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
setFormName($a_formname="")
Set Form name.
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.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
__construct($a_parent_obj, $a_parent_cmd, $parentRefId)
Constructor.
$cols
Definition: xhr_table.php:11