ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  $this->setPrefix('q_id'); // #16982
50 
51  parent::__construct($a_parent_obj, $a_parent_cmd);
52 
53  global $lng, $ilCtrl;
54 
55  $this->lng = $lng;
56  $this->ctrl = $ilCtrl;
57 
58  $this->setWriteAccess($a_write_access);
59 
60  //$qplSetting = new ilSetting("spl");
61 
62  //$this->setFormName('questionbrowser');
63  //$this->setStyle('table', 'fullwidth');
64 
65  if ($this->getWriteAccess())
66  {
67  $this->addColumn('','','1%');
68  }
69 
70  $this->addColumn($this->lng->txt("title"),'title', '');
71  $this->addColumn($this->lng->txt("obligatory"), "");
72 
73  foreach ($this->getSelectedColumns() as $c)
74  {
75  if (strcmp($c, 'description') == 0) $this->addColumn($this->lng->txt("description"),'description', '');
76  if (strcmp($c, 'type') == 0) $this->addColumn($this->lng->txt("question_type"),'type', '');
77  if (strcmp($c, 'author') == 0) $this->addColumn($this->lng->txt("author"),'author', '');
78  if (strcmp($c, 'created') == 0) $this->addColumn($this->lng->txt("create_date"),'created', '');
79  if (strcmp($c, 'updated') == 0) $this->addColumn($this->lng->txt("last_update"),'tstamp', '');
80  }
81 
82  $this->addColumn("", "");
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  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
209  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
210  $class = strtolower(SurveyQuestionGUI::_getGUIClassNameForId($data["question_id"]));
211  $guiclass = $class . "GUI";
212  $this->ctrl->setParameterByClass(strtolower($guiclass), "q_id", $data["question_id"]);
213 
214  if ($this->getEditable())
215  {
216  $url_edit = $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "editQuestion");
217 
218  $this->tpl->setCurrentBlock("title_link_bl");
219  $this->tpl->setVariable("QUESTION_TITLE_LINK", $data["title"]);
220  $this->tpl->setVariable("URL_TITLE", $url_edit);
221  $this->tpl->parseCurrentBlock();
222  }
223  else
224  {
225  $this->tpl->setCurrentBlock("title_nolink_bl");
226  $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
227  $this->tpl->parseCurrentBlock();
228  }
229 
230  if ($data["complete"] == 0)
231  {
232  $this->tpl->setCurrentBlock("qpl_warning");
233  $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("icon_alert.svg"));
234  $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete"));
235  $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete"));
236  $this->tpl->parseCurrentBlock();
237  }
238 
239  foreach ($this->getSelectedColumns() as $c)
240  {
241  if (strcmp($c, 'description') == 0)
242  {
243  $this->tpl->setCurrentBlock('description');
244  $this->tpl->setVariable("QUESTION_COMMENT", (strlen($data["description"])) ? $data["description"] : "&nbsp;");
245  $this->tpl->parseCurrentBlock();
246  }
247  if (strcmp($c, 'type') == 0)
248  {
249  $this->tpl->setCurrentBlock('type');
250  $this->tpl->setVariable("QUESTION_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
251  $this->tpl->parseCurrentBlock();
252  }
253  if (strcmp($c, 'author') == 0)
254  {
255  $this->tpl->setCurrentBlock('author');
256  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
257  $this->tpl->parseCurrentBlock();
258  }
259  if (strcmp($c, 'created') == 0)
260  {
261  $this->tpl->setCurrentBlock('created');
262  $this->tpl->setVariable("QUESTION_CREATED", ilDatePresentation::formatDate(new ilDate($data['created'],IL_CAL_UNIX)));
263  $this->tpl->parseCurrentBlock();
264  }
265  if (strcmp($c, 'updated') == 0)
266  {
267  $this->tpl->setCurrentBlock('updated');
268  $this->tpl->setVariable("QUESTION_UPDATED", ilDatePresentation::formatDate(new ilDate($data["tstamp"],IL_CAL_UNIX)));
269  $this->tpl->parseCurrentBlock();
270  }
271  }
272 
273  // actions
274  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
275  $list = new ilAdvancedSelectionListGUI();
276  $list->setId($data["question_id"]);
277  $list->setListTitle($this->lng->txt("actions"));
278  if ($url_edit)
279  {
280  $list->addItem($this->lng->txt("edit"), "", $url_edit);
281  }
282  $list->addItem($this->lng->txt("preview"), "", $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "preview"));
283  $this->tpl->setVariable("ACTION", $list->getHTML());
284  $this->tpl->parseCurrentBlock();
285 
286  // obligatory
287  if ($this->getEditable())
288  {
289  $checked = $data["obligatory"] ? " checked=\"checked\"" : "";
290  $obligatory = "<input type=\"checkbox\" name=\"obligatory_".
291  $data["question_id"] . "\" value=\"1\"".$checked." />";
292  }
293  else if($data["obligatory"])
294  {
295  $obligatory = "<img src=\"".ilUtil::getImagePath("obligatory.png", "Modules/Survey").
296  "\" alt=\"".$this->lng->txt("question_obligatory").
297  "\" title=\"".$this->lng->txt("question_obligatory")."\" />";
298  }
299  $this->tpl->setVariable("OBLIGATORY", $obligatory);
300 
301  if ($this->getWriteAccess())
302  {
303  $this->tpl->setVariable('CBOX_ID', $data["question_id"]);
304  }
305  $this->tpl->setVariable('QUESTION_ID', $data["question_id"]);
306  }
307 
308  public function setEditable($value)
309  {
310  $this->editable = $value;
311  }
312 
313  public function getEditable()
314  {
315  return $this->editable;
316  }
317 
318  public function setWriteAccess($value)
319  {
320  $this->writeAccess = $value;
321  }
322 
323  public function getWriteAccess()
324  {
325  return $this->writeAccess;
326  }
327 }
328 ?>
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
const IL_CAL_UNIX
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
Class ilTable2GUI.
Class for single dates.
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
if(!is_array($argv)) $options
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
This class represents a text property in a property form.
static formatDate(ilDateTime $date)
Format a date public.
setPrefix($a_prefix)
$ilUser
Definition: imgupload.php:18
getSelectedColumns()
Get selected columns.
setMaxLength($a_maxlength)
Set Max Length.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static _getGUIClassNameForId($a_q_id)
global $lng
Definition: privfeed.php:17
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
__construct($a_parent_obj, $a_parent_cmd, $a_write_access=false)
Constructor.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setFilterCommand($a_val, $a_caption=null)
Set filter command.