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