ILIAS  eassessment Revision 61809
 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  $this->addColumn('','f','1%');
63  $this->addColumn($this->lng->txt("title"),'title', '');
64  $this->addColumn('','edit', '');
65  $this->addColumn('','preview', '');
66  foreach ($this->getSelectedColumns() as $c)
67  {
68  if (strcmp($c, 'description') == 0) $this->addColumn($this->lng->txt("description"),'description', '');
69  if (strcmp($c, 'type') == 0) $this->addColumn($this->lng->txt("question_type"),'type', '');
70  if (strcmp($c, 'author') == 0) $this->addColumn($this->lng->txt("author"),'author', '');
71  if (strcmp($c, 'created') == 0) $this->addColumn($this->lng->txt("create_date"),'created', '');
72  if (strcmp($c, 'updated') == 0) $this->addColumn($this->lng->txt("last_update"),'tstamp', '');
73  }
74 
75  $this->setPrefix('q_id');
76  $this->setSelectAllCheckbox('q_id');
77 
78  if ($this->getWriteAccess())
79  {
80  $this->addMultiCommand('copy', $this->lng->txt('copy'));
81  $this->addMultiCommand('move', $this->lng->txt('move'));
82  $this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
83  $this->addMultiCommand('deleteQuestions', $this->lng->txt('delete'));
84 
85  $this->addCommandButton('importQuestions', $this->lng->txt('import'));
86  if (array_key_exists("spl_clipboard", $_SESSION))
87  {
88  $this->addCommandButton('paste', $this->lng->txt('paste'));
89  }
90  }
91 
92 
93  $this->setRowTemplate("tpl.il_svy_qpl_questions_row.html", "Modules/SurveyQuestionPool");
94 
95  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
96  $this->setDefaultOrderField("title");
97  $this->setDefaultOrderDirection("asc");
98 
99  $this->enable('sort');
100  $this->enable('header');
101  $this->enable('select_all');
102  $this->setFilterCommand('filterQuestionBrowser');
103  $this->setResetCommand('resetfilterQuestionBrowser');
104 
105  $this->initFilter();
106  }
107 
111  function initFilter()
112  {
113  global $lng, $rbacreview, $ilUser;
114 
115  // title
116  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
117  $ti = new ilTextInputGUI($lng->txt("title"), "title");
118  $ti->setMaxLength(64);
119  $ti->setSize(20);
120  $ti->setValidationRegexp('/^[^%]+$/is');
121  $this->addFilterItem($ti);
122  $ti->readFromSession();
123  $this->filter["title"] = $ti->getValue();
124 
125  // description
126  $ti = new ilTextInputGUI($lng->txt("description"), "description");
127  $ti->setMaxLength(64);
128  $ti->setSize(20);
129  $ti->setValidationRegexp('/^[^%]+$/is');
130  $this->addFilterItem($ti);
131  $ti->readFromSession();
132  $this->filter["description"] = $ti->getValue();
133 
134  // author
135  $ti = new ilTextInputGUI($lng->txt("author"), "author");
136  $ti->setMaxLength(64);
137  $ti->setSize(20);
138  $ti->setValidationRegexp('/^[^%]+$/is');
139  $this->addFilterItem($ti);
140  $ti->readFromSession();
141  $this->filter["author"] = $ti->getValue();
142 
143  // questiontype
144  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
145  include_once("./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php");
146  $types = ilObjSurveyQuestionPool::_getQuestionTypes();
147  $options = array();
148  $options[""] = $lng->txt('filter_all_question_types');
149  foreach ($types as $translation => $row)
150  {
151  $options[$row['type_tag']] = $translation;
152  }
153 
154  $si = new ilSelectInputGUI($this->lng->txt("question_type"), "type");
155  $si->setOptions($options);
156  $this->addFilterItem($si);
157  $si->readFromSession();
158  $this->filter["type"] = $si->getValue();
159 
160  }
161 
163  {
164  global $lng;
165  $cols["description"] = array(
166  "txt" => $lng->txt("description"),
167  "default" => true
168  );
169  $cols["type"] = array(
170  "txt" => $lng->txt("question_type"),
171  "default" => true
172  );
173  $cols["author"] = array(
174  "txt" => $lng->txt("author"),
175  "default" => true
176  );
177  $cols["created"] = array(
178  "txt" => $lng->txt("create_date"),
179  "default" => true
180  );
181  $cols["updated"] = array(
182  "txt" => $lng->txt("last_update"),
183  "default" => true
184  );
185  return $cols;
186  }
187 
195  public function fillRow($data)
196  {
197  global $ilUser,$ilAccess;
198  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
199  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
200  $class = strtolower(SurveyQuestionGUI::_getGUIClassNameForId($data["question_id"]));
201  $guiclass = $class . "GUI";
202  $this->ctrl->setParameterByClass(strtolower($guiclass), "q_id", $data["question_id"]);
203  if ($this->getEditable())
204  {
205  $this->tpl->setCurrentBlock("edit_link");
206  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
207  $this->tpl->setVariable("LINK_EDIT", $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "editQuestion"));
208  $this->tpl->parseCurrentBlock();
209  }
210  if ($data["complete"] == 0)
211  {
212  $this->tpl->setCurrentBlock("qpl_warning");
213  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("warning.gif"));
214  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
215  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
216  $this->tpl->parseCurrentBlock();
217  }
218  foreach ($this->getSelectedColumns() as $c)
219  {
220  if (strcmp($c, 'description') == 0)
221  {
222  $this->tpl->setCurrentBlock('description');
223  $this->tpl->setVariable("QUESTION_COMMENT", (strlen($data["description"])) ? $data["description"] : "&nbsp;");
224  $this->tpl->parseCurrentBlock();
225  }
226  if (strcmp($c, 'type') == 0)
227  {
228  $this->tpl->setCurrentBlock('type');
229  $this->tpl->setVariable("QUESTION_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
230  $this->tpl->parseCurrentBlock();
231  }
232  if (strcmp($c, 'author') == 0)
233  {
234  $this->tpl->setCurrentBlock('author');
235  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
236  $this->tpl->parseCurrentBlock();
237  }
238  include_once "./classes/class.ilFormat.php";
239  if (strcmp($c, 'created') == 0)
240  {
241  $this->tpl->setCurrentBlock('created');
242  $this->tpl->setVariable("QUESTION_CREATED", ilDatePresentation::formatDate(new ilDate($data['created'],IL_CAL_UNIX)));
243  $this->tpl->parseCurrentBlock();
244  }
245  if (strcmp($c, 'updated') == 0)
246  {
247  $this->tpl->setCurrentBlock('updated');
248  $this->tpl->setVariable("QUESTION_UPDATED", ilDatePresentation::formatDate(new ilDate($data["tstamp"],IL_CAL_UNIX)));
249  $this->tpl->parseCurrentBlock();
250  }
251  }
252  $this->tpl->setVariable('QUESTION_ID', $data["question_id"]);
253  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
254 
255  $this->tpl->setVariable("TXT_PREVIEW", $this->lng->txt("preview"));
256  $this->tpl->setVariable("LINK_PREVIEW", $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "preview"));
257  }
258 
259  public function setEditable($value)
260  {
261  $this->editable = $value;
262  }
263 
264  public function getEditable()
265  {
266  return $this->editable;
267  }
268 
269  public function setWriteAccess($value)
270  {
271  $this->writeAccess = $value;
272  }
273 
274  public function getWriteAccess()
275  {
276  return $this->writeAccess;
277  }
278 }
279 ?>