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