ILIAS  Release_4_0_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 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Table/classes/class.ilTable2GUI.php');
25 
35 {
36  protected $editable = true;
37  protected $writeAccess = false;
38  protected $totalPoints = 0;
39  protected $browsercolumns = array();
40  protected $confirmdelete;
41 
49  public function __construct($a_parent_obj, $a_parent_cmd, $a_write_access = false, $confirmdelete = false)
50  {
51  parent::__construct($a_parent_obj, $a_parent_cmd);
52 
53  global $lng, $ilCtrl;
54 
55  $this->lng = $lng;
56  $this->ctrl = $ilCtrl;
57 
58  $this->confirmdelete = $confirmdelete;
59  $this->setWriteAccess($a_write_access);
60 
61  $qplSetting = new ilSetting("qpl");
62 
63  $this->setId("qplqst".$a_parent_obj->object->getId());
64  $this->setFormName('questionbrowser');
65  $this->setStyle('table', 'fullwidth');
66  if (!$confirmdelete)
67  {
68  $this->addColumn('','f','1%');
69  $this->addColumn($this->lng->txt("title"),'title', '');
70  $this->addColumn('','edit', '');
71  $this->addColumn('','preview', '');
72  $this->browsercolumns['description'] = $qplSetting->get("description", 1) ? true : false;
73  $this->browsercolumns['type'] = $qplSetting->get("type", 1) ? true : false;
74  $this->browsercolumns['points'] = $qplSetting->get("points", 1) ? true : false;
75  $this->browsercolumns['statistics'] = $qplSetting->get("statistics", 1) ? true : false;
76  $this->browsercolumns['author'] = $qplSetting->get("author", 1) ? true : false;
77  $this->browsercolumns['created'] = $qplSetting->get("created", 1) ? true : false;
78  $this->browsercolumns['updated'] = $qplSetting->get("updated", 1) ? true : false;
79  if ($this->browsercolumns['description']) $this->addColumn($this->lng->txt("description"),'description', '');
80  if ($this->browsercolumns['type']) $this->addColumn($this->lng->txt("question_type"),'ttype', '');
81  if ($this->browsercolumns['points']) $this->addColumn($this->lng->txt("points"),'', '', false, 'right');
82  if ($this->browsercolumns['statistics']) $this->addColumn('','statistics', '');
83  if ($this->browsercolumns['author']) $this->addColumn($this->lng->txt("author"),'author', '');
84  if ($this->browsercolumns['created']) $this->addColumn($this->lng->txt("create_date"),'created', '');
85  if ($this->browsercolumns['updated']) $this->addColumn($this->lng->txt("last_update"),'tstamp', '');
86 
87  $this->setPrefix('q_id');
88  $this->setSelectAllCheckbox('q_id');
89  }
90  else
91  {
92  $this->addColumn($this->lng->txt("title"),'title', '');
93  $this->addColumn('','f','1%');
94  $this->browsercolumns['description'] = $qplSetting->get("description", 1) ? true : false;
95  $this->browsercolumns['type'] = $qplSetting->get("type", 1) ? true : false;
96  if ($this->browsercolumns['description']) $this->addColumn($this->lng->txt("description"),'description', '');
97  if ($this->browsercolumns['type']) $this->addColumn($this->lng->txt("question_type"),'ttype', '');
98  }
99 
100  if ($this->getWriteAccess())
101  {
102  if ($confirmdelete)
103  {
104  $this->addCommandButton('confirmDeleteQuestions', $this->lng->txt('confirm'));
105  $this->addCommandButton('cancelDeleteQuestions', $this->lng->txt('cancel'));
106  }
107  else
108  {
109  $this->addMultiCommand('copy', $this->lng->txt('copy'));
110  $this->addMultiCommand('move', $this->lng->txt('move'));
111  $this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
112  $this->addMultiCommand('deleteQuestions', $this->lng->txt('delete'));
113 
114  $this->addCommandButton('importQuestions', $this->lng->txt('import'));
115  if (array_key_exists("qpl_clipboard", $_SESSION))
116  {
117  $this->addCommandButton('paste', $this->lng->txt('paste'));
118  }
119  }
120  }
121 
122 
123  $this->setRowTemplate("tpl.il_as_qpl_questionbrowser_row.html", "Modules/TestQuestionPool");
124 
125  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
126  $this->setDefaultOrderField("title");
127  $this->setDefaultOrderDirection("asc");
128 
129  if ($confirmdelete)
130  {
131  $this->disable('sort');
132  $this->disable('select_all');
133  }
134  else
135  {
136  $this->enable('sort');
137  $this->enable('header');
138  $this->enable('select_all');
139  $this->setFilterCommand('filterQuestionBrowser');
140  $this->setResetCommand('resetQuestionBrowser');
141  $this->initFilter();
142  }
143 
144  }
145 
149  function initFilter()
150  {
151  global $lng, $rbacreview, $ilUser;
152 
153  // title
154  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
155  $ti = new ilTextInputGUI($lng->txt("title"), "title");
156  $ti->setMaxLength(64);
157  $ti->setSize(20);
158  $ti->setValidationRegexp('/^[^%]+$/is');
159  $this->addFilterItem($ti);
160  $ti->readFromSession();
161  $this->filter["title"] = $ti->getValue();
162 
163  // description
164  $ti = new ilTextInputGUI($lng->txt("description"), "description");
165  $ti->setMaxLength(64);
166  $ti->setSize(20);
167  $ti->setValidationRegexp('/^[^%]+$/is');
168  $this->addFilterItem($ti);
169  $ti->readFromSession();
170  $this->filter["description"] = $ti->getValue();
171 
172  // author
173  $ti = new ilTextInputGUI($lng->txt("author"), "author");
174  $ti->setMaxLength(64);
175  $ti->setValidationRegexp('/^[^%]+$/is');
176  $ti->setSize(20);
177  $this->addFilterItem($ti);
178  $ti->readFromSession();
179  $this->filter["author"] = $ti->getValue();
180 
181  // questiontype
182  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
183  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
185  $options = array();
186  $options[""] = $lng->txt('filter_all_question_types');
187  foreach ($types as $translation => $row)
188  {
189  $options[$row['type_tag']] = $translation;
190  }
191 
192  $si = new ilSelectInputGUI($this->lng->txt("question_type"), "type");
193  $si->setOptions($options);
194  $this->addFilterItem($si);
195  $si->readFromSession();
196  $this->filter["type"] = $si->getValue();
197 
198  }
199 
200  function fillHeader()
201  {
202  foreach ($this->column as $key => $column)
203  {
204  if (strcmp($column['text'], $this->lng->txt("points")) == 0)
205  {
206  $this->column[$key]['text'] = $this->lng->txt("points") . "&nbsp;(" . $this->totalPoints . ")";
207  }
208  }
210  }
211 
219  public function fillRow($data)
220  {
221  global $ilUser,$ilAccess;
222  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
223  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
224  $class = strtolower(assQuestionGUI::_getGUIClassNameForId($data["question_id"]));
225  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $data["question_id"]);
226  $this->ctrl->setParameterByClass($class, "q_id", $data["question_id"]);
227  $points = 0;
228 
229  if (!$this->confirmdelete)
230  {
231  $this->tpl->setCurrentBlock('checkbox');
232  $this->tpl->setVariable('CB_QUESTION_ID', $data["question_id"]);
233  $this->tpl->parseCurrentBlock();
234 
235  if ($this->getEditable())
236  {
237  $this->tpl->setCurrentBlock("edit_link");
238  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
239  $this->tpl->setVariable("LINK_EDIT", $this->ctrl->getLinkTargetByClass("ilpageobjectgui", "edit"));
240  $this->tpl->parseCurrentBlock();
241  }
242  if ($data["complete"] == 0)
243  {
244  $this->tpl->setCurrentBlock("qpl_warning");
245  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("warning.gif"));
246  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
247  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
248  $this->tpl->parseCurrentBlock();
249  }
250  else
251  {
252  $points = $data["points"];
253  }
254  $this->totalPoints += $points;
255 
256  if ($this->browsercolumns['points'])
257  {
258  $this->tpl->setCurrentBlock('points');
259  $this->tpl->setVariable("QUESTION_POINTS", $points);
260  $this->tpl->parseCurrentBlock();
261  }
262  if ($this->browsercolumns['statistics'])
263  {
264  $this->tpl->setCurrentBlock('statistics');
265  $this->tpl->setVariable("LINK_ASSESSMENT", $this->ctrl->getLinkTargetByClass($class, "assessment"));
266  $this->tpl->setVariable("TXT_ASSESSMENT", $this->lng->txt("statistics"));
267  include_once "./Services/Utilities/classes/class.ilUtil.php";
268  $this->tpl->setVariable("IMG_ASSESSMENT", ilUtil::getImagePath("assessment.gif", "Modules/TestQuestionPool"));
269  $this->tpl->parseCurrentBlock();
270  }
271  if ($this->browsercolumns['author'])
272  {
273  $this->tpl->setCurrentBlock('author');
274  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
275  $this->tpl->parseCurrentBlock();
276  }
277  include_once "./classes/class.ilFormat.php";
278  if ($this->browsercolumns['created'])
279  {
280  $this->tpl->setCurrentBlock('created');
281  $this->tpl->setVariable("QUESTION_CREATED", ilDatePresentation::formatDate(new ilDate($data['created'],IL_CAL_UNIX)));
282  $this->tpl->parseCurrentBlock();
283  }
284  if ($this->browsercolumns['updated'])
285  {
286  $this->tpl->setCurrentBlock('updated');
287  $this->tpl->setVariable("QUESTION_UPDATED", ilDatePresentation::formatDate(new ilDate($data["tstamp"],IL_CAL_UNIX)));
288  $this->tpl->parseCurrentBlock();
289  }
290  $this->tpl->setCurrentBlock('preview');
291  $this->tpl->setVariable("TXT_PREVIEW", $this->lng->txt("preview"));
292  $this->tpl->setVariable("LINK_PREVIEW", $this->ctrl->getLinkTargetByClass("ilpageobjectgui", "preview"));
293  $this->tpl->parseCurrentBlock();
294  }
295  else
296  {
297  $this->tpl->setCurrentBlock('hidden');
298  $this->tpl->setVariable('HIDDEN_QUESTION_ID', $data["question_id"]);
299  $this->tpl->parseCurrentBlock();
300  }
301 
302 
303  if ($this->browsercolumns['description'])
304  {
305  $this->tpl->setCurrentBlock('description');
306  $this->tpl->setVariable("QUESTION_COMMENT", (strlen($data["description"])) ? $data["description"] : "&nbsp;");
307  $this->tpl->parseCurrentBlock();
308  }
309  if ($this->browsercolumns['type'])
310  {
311  $this->tpl->setCurrentBlock('type');
312  $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($data["type_tag"]));
313  $this->tpl->parseCurrentBlock();
314  }
315 
316  $this->tpl->setVariable('QUESTION_ID', $data["question_id"]);
317  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
318  }
319 
320  public function setEditable($value)
321  {
322  $this->editable = $value;
323  }
324 
325  public function getEditable()
326  {
327  return $this->editable;
328  }
329 
330  public function setWriteAccess($value)
331  {
332  $this->writeAccess = $value;
333  }
334 
335  public function getWriteAccess()
336  {
337  return $this->writeAccess;
338  }
339 }
340 ?>