ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyQuestionsTableGUI.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 
46  public function __construct($a_parent_obj, $a_parent_cmd, $a_write_access = false)
47  {
48  $this->setId("spl");
49  parent::__construct($a_parent_obj, $a_parent_cmd);
50 
51  global $lng, $ilCtrl;
52 
53  $this->lng = $lng;
54  $this->ctrl = $ilCtrl;
55 
56  $this->setWriteAccess($a_write_access);
57 
58  $qplSetting = new ilSetting("spl");
59 
60  $this->setFormName('questionbrowser');
61  $this->setStyle('table', 'fullwidth');
62 
63  if ($this->getWriteAccess())
64  {
65  $this->addColumn('','','1%');
66  }
67 
68  $this->addColumn($this->lng->txt("title"),'title', '');
69  $this->addColumn($this->lng->txt("obligatory"), "");
70 
71  foreach ($this->getSelectedColumns() as $c)
72  {
73  if (strcmp($c, 'description') == 0) $this->addColumn($this->lng->txt("description"),'description', '');
74  if (strcmp($c, 'type') == 0) $this->addColumn($this->lng->txt("question_type"),'type', '');
75  if (strcmp($c, 'author') == 0) $this->addColumn($this->lng->txt("author"),'author', '');
76  if (strcmp($c, 'created') == 0) $this->addColumn($this->lng->txt("create_date"),'created', '');
77  if (strcmp($c, 'updated') == 0) $this->addColumn($this->lng->txt("last_update"),'tstamp', '');
78  }
79 
80  $this->setPrefix('q_id');
81 
82  if ($this->getWriteAccess())
83  {
84  $this->setSelectAllCheckbox('q_id');
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  if (array_key_exists("spl_clipboard", $_SESSION))
92  {
93  $this->addCommandButton('paste', $this->lng->txt('paste'));
94  }
95 
96  $this->addCommandButton("saveObligatory", $this->lng->txt("spl_save_obligatory_state"));
97  }
98 
99  $this->addColumn("", "");
100 
101  $this->setRowTemplate("tpl.il_svy_qpl_questions_row.html", "Modules/SurveyQuestionPool");
102 
103  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
104  $this->setDefaultOrderField("title");
105  $this->setDefaultOrderDirection("asc");
106 
107  $this->enable('sort');
108  $this->enable('header');
109  $this->enable('select_all');
110  $this->setFilterCommand('filterQuestionBrowser');
111  $this->setResetCommand('resetfilterQuestionBrowser');
112 
113  $this->initFilter();
114  }
115 
119  function initFilter()
120  {
121  global $lng, $rbacreview, $ilUser;
122 
123  // title
124  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
125  $ti = new ilTextInputGUI($lng->txt("title"), "title");
126  $ti->setMaxLength(64);
127  $ti->setSize(20);
128  $ti->setValidationRegexp('/^[^%]+$/is');
129  $this->addFilterItem($ti);
130  $ti->readFromSession();
131  $this->filter["title"] = $ti->getValue();
132 
133  // description
134  $ti = new ilTextInputGUI($lng->txt("description"), "description");
135  $ti->setMaxLength(64);
136  $ti->setSize(20);
137  $ti->setValidationRegexp('/^[^%]+$/is');
138  $this->addFilterItem($ti);
139  $ti->readFromSession();
140  $this->filter["description"] = $ti->getValue();
141 
142  // author
143  $ti = new ilTextInputGUI($lng->txt("author"), "author");
144  $ti->setMaxLength(64);
145  $ti->setSize(20);
146  $ti->setValidationRegexp('/^[^%]+$/is');
147  $this->addFilterItem($ti);
148  $ti->readFromSession();
149  $this->filter["author"] = $ti->getValue();
150 
151  // questiontype
152  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
153  include_once("./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php");
154  $types = ilObjSurveyQuestionPool::_getQuestionTypes();
155  $options = array();
156  $options[""] = $lng->txt('filter_all_question_types');
157  foreach ($types as $translation => $row)
158  {
159  $options[$row['type_tag']] = $translation;
160  }
161 
162  $si = new ilSelectInputGUI($this->lng->txt("question_type"), "type");
163  $si->setOptions($options);
164  $this->addFilterItem($si);
165  $si->readFromSession();
166  $this->filter["type"] = $si->getValue();
167 
168  }
169 
171  {
172  global $lng;
173  $cols["description"] = array(
174  "txt" => $lng->txt("description"),
175  "default" => true
176  );
177  $cols["type"] = array(
178  "txt" => $lng->txt("question_type"),
179  "default" => true
180  );
181  $cols["author"] = array(
182  "txt" => $lng->txt("author"),
183  "default" => true
184  );
185  $cols["created"] = array(
186  "txt" => $lng->txt("create_date"),
187  "default" => true
188  );
189  $cols["updated"] = array(
190  "txt" => $lng->txt("last_update"),
191  "default" => true
192  );
193  return $cols;
194  }
195 
203  public function fillRow($data)
204  {
205  global $ilUser,$ilAccess;
206 
207  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
208  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
209  $class = strtolower(SurveyQuestionGUI::_getGUIClassNameForId($data["question_id"]));
210  $guiclass = $class . "GUI";
211  $this->ctrl->setParameterByClass(strtolower($guiclass), "q_id", $data["question_id"]);
212 
213  if ($this->getEditable())
214  {
215  $url_edit = $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "editQuestion");
216 
217  $this->tpl->setCurrentBlock("title_link_bl");
218  $this->tpl->setVariable("QUESTION_TITLE_LINK", $data["title"]);
219  $this->tpl->setVariable("URL_TITLE", $url_edit);
220  $this->tpl->parseCurrentBlock();
221  }
222  else
223  {
224  $this->tpl->setCurrentBlock("title_nolink_bl");
225  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
226  $this->tpl->parseCurrentBlock();
227  }
228 
229  if ($data["complete"] == 0)
230  {
231  $this->tpl->setCurrentBlock("qpl_warning");
232  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("warning.png"));
233  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
234  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
235  $this->tpl->parseCurrentBlock();
236  }
237 
238  foreach ($this->getSelectedColumns() as $c)
239  {
240  if (strcmp($c, 'description') == 0)
241  {
242  $this->tpl->setCurrentBlock('description');
243  $this->tpl->setVariable("QUESTION_COMMENT", (strlen($data["description"])) ? $data["description"] : "&nbsp;");
244  $this->tpl->parseCurrentBlock();
245  }
246  if (strcmp($c, 'type') == 0)
247  {
248  $this->tpl->setCurrentBlock('type');
249  $this->tpl->setVariable("QUESTION_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
250  $this->tpl->parseCurrentBlock();
251  }
252  if (strcmp($c, 'author') == 0)
253  {
254  $this->tpl->setCurrentBlock('author');
255  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
256  $this->tpl->parseCurrentBlock();
257  }
258  if (strcmp($c, 'created') == 0)
259  {
260  $this->tpl->setCurrentBlock('created');
261  $this->tpl->setVariable("QUESTION_CREATED", ilDatePresentation::formatDate(new ilDate($data['created'],IL_CAL_UNIX)));
262  $this->tpl->parseCurrentBlock();
263  }
264  if (strcmp($c, 'updated') == 0)
265  {
266  $this->tpl->setCurrentBlock('updated');
267  $this->tpl->setVariable("QUESTION_UPDATED", ilDatePresentation::formatDate(new ilDate($data["tstamp"],IL_CAL_UNIX)));
268  $this->tpl->parseCurrentBlock();
269  }
270  }
271 
272  // actions
273  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
274  $list = new ilAdvancedSelectionListGUI();
275  $list->setId($data["question_id"]);
276  $list->setListTitle($this->lng->txt("actions"));
277  if ($url_edit)
278  {
279  $list->addItem($this->lng->txt("edit"), "", $url_edit);
280  }
281  $list->addItem($this->lng->txt("preview"), "", $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "preview"));
282  $this->tpl->setVariable("ACTION", $list->getHTML());
283  $this->tpl->parseCurrentBlock();
284 
285  // obligatory
286  if ($this->getEditable())
287  {
288  $checked = $data["obligatory"] ? " checked=\"checked\"" : "";
289  $obligatory = "<input type=\"checkbox\" name=\"obligatory_".
290  $data["question_id"] . "\" value=\"1\"".$checked." />";
291  }
292  else if($data["obligatory"])
293  {
294  $obligatory = "<img src=\"".ilUtil::getImagePath("obligatory.png", "Modules/Survey").
295  "\" alt=\"".$this->lng->txt("question_obligatory").
296  "\" title=\"".$this->lng->txt("question_obligatory")."\" />";
297  }
298  $this->tpl->setVariable("OBLIGATORY", $obligatory);
299 
300  if ($this->getWriteAccess())
301  {
302  $this->tpl->setVariable('CBOX_ID', $data["question_id"]);
303  }
304  $this->tpl->setVariable('QUESTION_ID', $data["question_id"]);
305  }
306 
307  public function setEditable($value)
308  {
309  $this->editable = $value;
310  }
311 
312  public function getEditable()
313  {
314  return $this->editable;
315  }
316 
317  public function setWriteAccess($value)
318  {
319  $this->writeAccess = $value;
320  }
321 
322  public function getWriteAccess()
323  {
324  return $this->writeAccess;
325  }
326 }
327 ?>