ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilQuestionBrowserTableGUI.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 
17 {
18  protected $editable = true;
19  protected $writeAccess = false;
20  protected $totalPoints = 0;
21  protected $confirmdelete;
22 
23  protected $taxIds = array();
24 
32  public function __construct($a_parent_obj, $a_parent_cmd, $a_write_access = false, $confirmdelete = false, $taxIds = array())
33  {
34  $this->setId("qpl_qst_brows_" . $a_parent_obj->object->getRefId());
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 
37  global $lng, $ilCtrl;
38 
39  $this->lng = $lng;
40  $this->ctrl = $ilCtrl;
41 
42  $this->confirmdelete = $confirmdelete;
43  $this->setWriteAccess($a_write_access);
44  $this->taxIds = $taxIds;
45 
46  $qplSetting = new ilSetting("qpl");
47 
48  $this->setFormName('questionbrowser');
49  $this->setStyle('table', 'fullwidth');
50  if (!$confirmdelete)
51  {
52  $this->addColumn('','','1%');
53  $this->addColumn($this->lng->txt("title"),'title', '');
54  $this->addColumn('','', '');
55  $this->addColumn('','', '');
56  foreach ($this->getSelectedColumns() as $c)
57  {
58  if (strcmp($c, 'description') == 0) $this->addColumn($this->lng->txt("description"),'description', '');
59  if (strcmp($c, 'type') == 0) $this->addColumn($this->lng->txt("question_type"),'ttype', '');
60  // According to mantis #12713
61  if (strcmp($c, 'points') == 0) $this->addColumn($this->lng->txt("points"),'points', '', false, 'ilCenterForced');
62  if (strcmp($c, 'statistics') == 0) $this->addColumn($this->lng->txt('statistics'),'', '');
63  if (strcmp($c, 'author') == 0) $this->addColumn($this->lng->txt("author"),'author', '');
64  if (strcmp($c, 'created') == 0) $this->addColumn($this->lng->txt("create_date"),'created', '');
65  if (strcmp($c, 'tstamp') == 0) $this->addColumn($this->lng->txt("last_update"),'tstamp', '');
66  }
67  $this->setSelectAllCheckbox('q_id');
68  }
69  else
70  {
71  $this->addColumn($this->lng->txt("title"),'title', '');
72  $this->addColumn('','f','1%');
73  foreach ($this->getSelectedColumns() as $c)
74  {
75  if (strcmp($c, 'description') == 0) $this->addColumn($this->lng->txt("description"),'description', '');
76  if (strcmp($c, 'type') == 0) $this->addColumn($this->lng->txt("question_type"),'ttype', '');
77  }
78  }
79 
80  if ($this->getWriteAccess())
81  {
82  if ($confirmdelete)
83  {
84  $this->addCommandButton('confirmDeleteQuestions', $this->lng->txt('confirm'));
85  $this->addCommandButton('cancelDeleteQuestions', $this->lng->txt('cancel'));
86  }
87  else
88  {
89  $this->addMultiCommand('copy', $this->lng->txt('copy'));
90  $this->addMultiCommand('move', $this->lng->txt('move'));
91  $this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
92  $this->addMultiCommand('deleteQuestions', $this->lng->txt('delete'));
93 
94  $this->addCommandButton('importQuestions', $this->lng->txt('import'));
95 
96  if (array_key_exists("qpl_clipboard", $_SESSION) && count($_SESSION['qpl_clipboard']))
97  {
98  $this->addCommandButton('paste', $this->lng->txt('paste'));
99  }
100  }
101  }
102 
103  $this->setRowTemplate("tpl.il_as_qpl_questionbrowser_row.html", "Modules/TestQuestionPool");
104 
105  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
106  $this->setDefaultOrderField("title");
107  $this->setDefaultOrderDirection("asc");
108 
109  $this->setShowRowsSelector(true);
110 
111  if ($confirmdelete)
112  {
113  $this->disable('sort');
114  $this->disable('select_all');
115  }
116  else
117  {
118  $this->enable('sort');
119  $this->enable('header');
120  $this->enable('select_all');
121  $this->setFilterCommand('filterQuestionBrowser');
122  $this->setResetCommand('resetQuestionBrowser');
123  $this->initFilter();
124  }
125 
126  }
127 
129  {
130  global $lng;
131  $cols["description"] = array(
132  "txt" => $lng->txt("description"),
133  "default" => true
134  );
135  $cols["type"] = array(
136  "txt" => $lng->txt("question_type"),
137  "default" => true
138  );
139  if (!$this->confirmdelete)
140  {
141  $cols["points"] = array(
142  "txt" => $lng->txt("points"),
143  "default" => true
144  );
145  $cols["statistics"] = array(
146  "txt" => $lng->txt("statistics"),
147  "default" => true
148  );
149  $cols["author"] = array(
150  "txt" => $lng->txt("author"),
151  "default" => true
152  );
153  $cols["created"] = array(
154  "txt" => $lng->txt("create_date"),
155  "default" => true
156  );
157  $cols["tstamp"] = array(
158  "txt" => $lng->txt("last_update"),
159  "default" => true
160  );
161  }
162  return $cols;
163  }
164 
168  function initFilter()
169  {
170  global $lng, $rbacreview, $ilUser;
171 
172  // title
173  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
174  $ti = new ilTextInputGUI($lng->txt("title"), "title");
175  $ti->setMaxLength(64);
176  $ti->setValidationRegexp('/^[^%]+$/is');
177  $ti->setSize(20);
178  $this->addFilterItem($ti);
179  $ti->readFromSession();
180  $this->filter["title"] = $ti->getValue();
181 
182  // description
183  $ti = new ilTextInputGUI($lng->txt("description"), "description");
184  $ti->setMaxLength(64);
185  $ti->setSize(20);
186  $ti->setValidationRegexp('/^[^%]+$/is');
187  $this->addFilterItem($ti);
188  $ti->readFromSession();
189  $this->filter["description"] = $ti->getValue();
190 
191  if (!$this->confirmdelete)
192  {
193  // author
194  $ti = new ilTextInputGUI($lng->txt("author"), "author");
195  $ti->setMaxLength(64);
196  $ti->setSize(20);
197  $ti->setValidationRegexp('/^[^%]+$/is');
198  $this->addFilterItem($ti);
199  $ti->readFromSession();
200  $this->filter["author"] = $ti->getValue();
201  }
202  // questiontype
203  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
204  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
206  $options = array();
207  $options[""] = $lng->txt('filter_all_question_types');
208  foreach ($types as $translation => $row)
209  {
210  $options[$row['type_tag']] = $translation;
211  }
212 
213  $si = new ilSelectInputGUI($this->lng->txt("question_type"), "type");
214  $si->setOptions($options);
215  $this->addFilterItem($si);
216  $si->readFromSession();
217  $this->filter["type"] = $si->getValue();
218 
219  if( $this->parent_obj->object->getShowTaxonomies() )
220  {
221  require_once 'Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php';
222 
223  foreach($this->taxIds as $taxId)
224  {
225  if( $taxId == $this->parent_obj->object->getNavTaxonomyId() )
226  {
227  continue;
228  }
229 
230  $postvar = "tax_$taxId";
231 
232  $inp = new ilTaxSelectInputGUI($taxId, $postvar, true);
233  $this->addFilterItem($inp);
234  $inp->readFromSession();
235  $this->filter[$postvar] = $inp->getValue();
236  }
237  }
238 
239  }
240 
241  function fillHeader()
242  {
243  foreach ($this->column as $key => $column)
244  {
245  if (strcmp($column['text'], $this->lng->txt("points")) == 0)
246  {
247  $this->column[$key]['text'] = $this->lng->txt("points") . "&nbsp;(" . $this->totalPoints . ")";
248  }
249  }
251  }
252 
260  public function fillRow($data)
261  {
262  global $ilUser,$ilAccess;
263  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
264  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
265  $class = strtolower(assQuestionGUI::_getGUIClassNameForId($data["question_id"]));
266  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $data["question_id"]);
267  $this->ctrl->setParameterByClass($class, "q_id", $data["question_id"]);
268  $points = 0;
269 
270  if (!$this->confirmdelete)
271  {
272  $this->tpl->setCurrentBlock('checkbox');
273  $this->tpl->setVariable('CB_QUESTION_ID', $data["question_id"]);
274  $this->tpl->parseCurrentBlock();
275 
276  if ($this->getEditable())
277  {
278  $this->tpl->setCurrentBlock("edit_link");
279  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
280  $this->tpl->setVariable("LINK_EDIT", $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"));
281  $this->tpl->parseCurrentBlock();
282  }
283  if ($data["complete"] == 0)
284  {
285  $this->tpl->setCurrentBlock("qpl_warning");
286  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("warning.png"));
287  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
288  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
289  $this->tpl->parseCurrentBlock();
290  }
291  else
292  {
293  $points = $data["points"];
294  }
295  $this->totalPoints += $points;
296 
297  foreach ($this->getSelectedColumns() as $c)
298  {
299  if (strcmp($c, 'points') == 0)
300  {
301  $this->tpl->setCurrentBlock('points');
302  $this->tpl->setVariable("QUESTION_POINTS", $points);
303  $this->tpl->parseCurrentBlock();
304  }
305  if (strcmp($c, 'statistics') == 0)
306  {
307  $this->tpl->setCurrentBlock('statistics');
308  $this->tpl->setVariable("LINK_ASSESSMENT", $this->ctrl->getLinkTargetByClass($class, "assessment"));
309  $this->tpl->setVariable("TXT_ASSESSMENT", $this->lng->txt("statistics"));
310  include_once "./Services/Utilities/classes/class.ilUtil.php";
311  $this->tpl->setVariable("IMG_ASSESSMENT", ilUtil::getImagePath("assessment.gif", "Modules/TestQuestionPool"));
312  $this->tpl->parseCurrentBlock();
313  }
314  if (strcmp($c, 'author') == 0)
315  {
316  $this->tpl->setCurrentBlock('author');
317  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
318  $this->tpl->parseCurrentBlock();
319  }
320  if(strcmp($c, 'created') == 0)
321  {
322  $this->tpl->setCurrentBlock('created');
323  $this->tpl->setVariable('QUESTION_CREATED', ilDatePresentation::formatDate(new ilDateTime($data['created'], IL_CAL_UNIX)));
324  $this->tpl->parseCurrentBlock();
325  }
326  if(strcmp($c, 'tstamp') == 0)
327  {
328  $this->tpl->setCurrentBlock('updated');
329  $this->tpl->setVariable('QUESTION_UPDATED', ilDatePresentation::formatDate(new ilDateTime($data['tstamp'], IL_CAL_UNIX)));
330  $this->tpl->parseCurrentBlock();
331  }
332  }
333  $this->tpl->setCurrentBlock('preview');
334  $this->tpl->setVariable("TXT_PREVIEW", $this->lng->txt("preview"));
335  $this->tpl->setVariable("LINK_PREVIEW", $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "preview"));
336  $this->tpl->parseCurrentBlock();
337  }
338  else
339  {
340  $this->tpl->setCurrentBlock('hidden');
341  $this->tpl->setVariable('HIDDEN_QUESTION_ID', $data["question_id"]);
342  $this->tpl->parseCurrentBlock();
343  }
344 
345  foreach ($this->getSelectedColumns() as $c)
346  {
347  if (strcmp($c, 'description') == 0)
348  {
349  $this->tpl->setCurrentBlock('description');
350  $this->tpl->setVariable("QUESTION_COMMENT", (strlen($data["description"])) ? $data["description"] : "&nbsp;");
351  $this->tpl->parseCurrentBlock();
352  }
353  if (strcmp($c, 'type') == 0)
354  {
355  $this->tpl->setCurrentBlock('type');
356  $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($data["type_tag"]));
357  $this->tpl->parseCurrentBlock();
358  }
359  }
360  $this->tpl->setVariable('QUESTION_ID', $data["question_id"]);
361  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
362  }
363 
364  public function setEditable($value)
365  {
366  $this->editable = $value;
367  }
368 
369  public function getEditable()
370  {
371  return $this->editable;
372  }
373 
374  public function setWriteAccess($value)
375  {
376  $this->writeAccess = $value;
377  }
378 
379  public function getWriteAccess()
380  {
381  return $this->writeAccess;
382  }
383 
388  public function numericOrdering($column)
389  {
390  if(in_array($column, array('points', 'created', 'tstamp')))
391  {
392  return true;
393  }
394 
395  return false;
396  }
397 }