ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
16 {
17  protected $writeAccess = false;
18  protected $totalPoints = 0;
19  protected $checked_move = false;
20  protected $total = 0;
21 
22  protected $position = 0;
23 
27  protected $visibleOptionalColumns = array();
28 
32  protected $optionalColumns = array();
33 
41  public function __construct($a_parent_obj, $a_parent_cmd, $a_write_access = false, $a_checked_move = false, $a_total = 0)
42  {
43  $this->setId('tst_qst_lst_'.$a_parent_obj->object->getRefId());
44 
45  parent::__construct($a_parent_obj, $a_parent_cmd);
46 
47  global $lng, $ilCtrl;
48 
49  $this->lng = $lng;
50  $this->ctrl = $ilCtrl;
51  $this->total = $a_total;
52 
53  $this->setWriteAccess($a_write_access);
54  $this->setCheckedMove($a_checked_move);
55 
56  $this->setFormName('questionbrowser');
57  $this->setStyle('table', 'fullwidth');
58  $this->addColumn('','f','1%', true);
59  $this->addColumn('','f','1%');
60  $this->visibleOptionalColumns = (array)$this->getSelectedColumns();
61  $this->optionalColumns = (array)$this->getSelectableColumns();
62  if(isset($this->visibleOptionalColumns['qid']))
63  {
64  $this->addColumn($this->optionalColumns['qid']['txt'],'qid', '');
65  }
66  $this->addColumn($this->lng->txt("tst_question_title"),'title', '');
67  //$this->addColumn($this->lng->txt("tst_sequence"),'sequence', '');
68  if( $a_parent_obj->object->areObligationsEnabled() )
69  {
70  $this->addColumn($this->lng->txt("obligatory"),'obligatory', '');
71  }
72  if(isset($this->visibleOptionalColumns['description']))
73  {
74  $this->addColumn($this->optionalColumns['description']['txt'],'description', '');
75  }
76  $this->addColumn($this->lng->txt("tst_question_type"),'type', '');
77  $this->addColumn($this->lng->txt("points"),'', '');
78  if(isset($this->visibleOptionalColumns['author']))
79  {
80  $this->addColumn($this->optionalColumns['author']['txt'],'author', '');
81  }
82  $this->addColumn($this->lng->txt("qpl"),'qpl', '');
83 
84  $this->setSelectAllCheckbox('q_id');
85 
86  $this->setExternalSegmentation(true);
87 
88  if ($this->getWriteAccess() && !$this->getTotal())
89  {
90  $this->addMultiCommand('removeQuestions', $this->lng->txt('remove_question'));
91  $this->addMultiCommand('moveQuestions', $this->lng->txt('move'));
92  if ($this->checked_move)
93  {
94  $this->addMultiCommand('insertQuestionsBefore', $this->lng->txt('insert_before'));
95  $this->addMultiCommand('insertQuestionsAfter', $this->lng->txt('insert_after'));
96  }
97  //$this->addMultiCommand('copyToQuestionpool', $this->lng->txt('copy_to_questionpool'));
98  $this->addMultiCommand('copyQuestion', $this->lng->txt('copy'));
99  $this->addMultiCommand('copyAndLinkToQuestionpool', $this->lng->txt('copy_and_link_to_questionpool'));
100 
101  }
102 
103 
104  $this->setRowTemplate("tpl.il_as_tst_questions_row.html", "Modules/Test");
105 
106  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
107 
108  if( $a_parent_obj->object->areObligationsEnabled() )
109  {
110  $this->addCommandButton('saveOrderAndObligations', $this->lng->txt('saveOrderAndObligations'));
111  }
112  else
113  {
114  $this->addCommandButton('saveOrderAndObligations', $this->lng->txt('saveOrder'));
115  }
116 
117  $this->disable('sort');
118  $this->enable('header');
119  $this->enable('select_all');
120  }
121 
125  public function getSelectableColumns()
126  {
127  $cols = array(
128  'qid' => array('txt' => $this->lng->txt('question_id'), 'default' => true),
129  'description' => array('txt' => $this->lng->txt('description'), 'default' => false),
130  'author' => array('txt' => $this->lng->txt('author'), 'default' => false)
131  );
132 
133  return $cols;
134  }
135 
136  function fillHeader()
137  {
138  foreach ($this->column as $key => $column)
139  {
140  if (strcmp($column['text'], $this->lng->txt("points")) == 0)
141  {
142  $this->column[$key]['text'] = $this->lng->txt("points") . "&nbsp;(" . $this->totalPoints . ")";
143  }
144  }
146  }
147 
155  public function fillRow($data)
156  {
157  global $ilUser,$ilAccess;
158 
159  $q_id = $data["question_id"];
160 
161  $this->tpl->setVariable("QUESTION_ID", $q_id);
162  if(isset($this->visibleOptionalColumns['qid']))
163  {
164  $this->tpl->setVariable("QUESTION_ID_PRESENTATION", $q_id);
165  }
166  if ($this->getWriteAccess() && !$this->getTotal() && $data["obj_fi"] > 0)
167  {
168  if (!$data['complete']) {
169  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("warning.png"));
170  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
171  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
172  }
173 
174 
175  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
176  $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $this->ctrl->getLinkTarget($this->getParentObject(), "questions") . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
177 
178  // obligatory checkbox (when obligation is possible)
179  if( $data["obligationPossible"] )
180  {
181  $CHECKED = $data["obligatory"] ? "checked=\"checked\" " : "";
182  $OBLIGATORY = "<input type=\"checkbox\" name=\"obligatory[$q_id]\" value=\"1\" $CHECKED/>";
183  }
184  else
185  {
186  $OBLIGATORY = "";
187  }
188  }
189  else
190  {
191  global $lng;
192 
193  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
194 
195  // obligatory icon
196  if( $data["obligatory"] )
197  {
198  $OBLIGATORY = "<img src=\"".ilUtil::getImagePath("obligatory.gif", "Modules/Test").
199  "\" alt=\"".$lng->txt("question_obligatory").
200  "\" title=\"".$lng->txt("question_obligatory")."\" />";
201  }
202  else $OBLIGATORY = '';
203  }
204 
205  if( $this->parent_obj->object->areObligationsEnabled() )
206  {
207  $this->tpl->setVariable("QUESTION_OBLIGATORY", $OBLIGATORY);
208  }
209 
210  $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("tst_sequence"));
211 
212  if ($this->getWriteAccess() && !$this->getTotal())
213  {
214  if ($data["sequence"] != 1)
215  {
216  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this->getParentObject(), "questions") . "&up=".$data["question_id"]."\"><img src=\"" . ilUtil::getImagePath("a_up.png") . "\" alt=\"" . $this->lng->txt("up") . "\" border=\"0\" /></a>");
217  }
218  if ($data["sequence"] != count($this->getData()))
219  {
220  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this->getParentObject(), "questions") . "&down=".$data["question_id"]."\"><img src=\"" . ilUtil::getImagePath("a_down.png") . "\" alt=\"" . $this->lng->txt("down") . "\" border=\"0\" /></a>");
221  }
222  }
223 
224  if(isset($this->visibleOptionalColumns['description']))
225  {
226  if($data["description"])
227  {
228  $this->tpl->setVariable("QUESTION_COMMENT", $data["description"] ? $data["description"] : '&nbsp;');
229  }
230  else
231  {
232  $this->tpl->touchBlock('question_comment_block');
233  }
234  }
235  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
236  $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($data["type_tag"]));
237  $this->tpl->setVariable("QUESTION_POINTS", $data["points"]);
238  $this->totalPoints += $data["points"];
239 
240  if(isset($this->visibleOptionalColumns['author']))
241  {
242  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
243  }
244  if (ilObject::_lookupType($data["orig_obj_fi"]) == 'qpl') {
245  $this->tpl->setVariable("QUESTION_POOL", ilObject::_lookupTitle($data["orig_obj_fi"]));
246  }
247  else {
248  $this->tpl->setVariable("QUESTION_POOL", $this->lng->txt('tst_question_not_from_pool_info'));
249  }
250 
251 
252  $this->position += 10;
253  $field = "<input type=\"text\" name=\"order[q_".$data["question_id"].
254  "]\" value=\"".$this->position."\" maxlength=\"3\" style=\"width:30px\" />";
255  $this->tpl->setVariable("QUESTION_POSITION", $field);
256  }
257 
258  public function setWriteAccess($value)
259  {
260  $this->writeAccess = $value;
261  }
262 
263  public function getWriteAccess()
264  {
265  return $this->writeAccess;
266  }
267 
268  public function setCheckedMove($value)
269  {
270  $this->checked_move = $value;
271  }
272 
273  public function getCheckedMove()
274  {
275  return $this->checked_move;
276  }
277 
278  public function setTotal($value)
279  {
280  $this->total = $value;
281  }
282 
283  public function getTotal()
284  {
285  return $this->total;
286  }
287 }
288 ?>