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