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