ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
SurveySingleChoiceQuestionGUI Class Reference

SingleChoice survey question GUI representation. More...

+ Inheritance diagram for SurveySingleChoiceQuestionGUI:
+ Collaboration diagram for SurveySingleChoiceQuestionGUI:

Public Member Functions

 setQuestionTabs ()
 
 getParsedAnswers (array $a_working_data=null, $a_only_user_anwers=false)
 
 getPrintView ($question_title=1, $show_questiontext=1, $survey_id=null, array $a_working_data=null)
 Creates a HTML representation of the question. More...
 
 getWorkingForm ($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null)
 Creates the question output form for the learner. More...
 
- Public Member Functions inherited from SurveyQuestionGUI
 __construct ($a_id=-1)
 
 setQuestionTabs ()
 
executeCommand ()
 
 getQuestionType ()
 Returns the question type string. More...
 
 setBackUrl ($a_url)
 
 setQuestionTabsForClass ($guiclass)
 
 getPrintView ($question_title=1, $show_questiontext=1)
 
 preview ()
 Creates a preview of the question. More...
 
 getWorkingForm ($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null)
 
 material ($checkonly=FALSE)
 Material tab of the survey questions. More...
 
 deleteMaterial ()
 
 addMaterial ()
 Add materials to a question. More...
 
 removeMaterial ()
 
 cancelExplorer ()
 
 addPG ()
 
 addST ()
 
 addGIT ()
 
 linkChilds ()
 
 savePhrase ($a_reload=false)
 Creates an output to save the current answers as a phrase. More...
 
 confirmSavePhrase ()
 Save a new phrase to the database. More...
 

Protected Member Functions

 initObject ()
 
 addFieldsToEditForm (ilPropertyFormGUI $a_form)
 
 importEditFormValues (ilPropertyFormGUI $a_form)
 
- Protected Member Functions inherited from SurveyQuestionGUI
 initObject ()
 
 outQuestionText ($template)
 
 initEditForm ()
 
 addCommandButtons ($a_form)
 
 editQuestion (ilPropertyFormGUI $a_form=null)
 
 saveSync ()
 
 saveReturn ()
 
 saveForm ()
 
 save ($a_return=false, $a_sync=false)
 
 copySyncForm ()
 
 syncCopies ()
 
 originalSyncForm ()
 
 sync ()
 
 cancelSync ()
 
 redirectAfterSaving ($a_return=false)
 Redirect to calling survey or to edit form. More...
 
 cancel ()
 
 validateEditForm (ilPropertyFormGUI $a_form)
 
 addFieldsToEditForm (ilPropertyFormGUI $a_form)
 
 importEditFormValues (ilPropertyFormGUI $a_form)
 
 getPrintViewQuestionTitle ($question_title=1)
 
 getMaterialOutput ()
 Creates the HTML output of the question material(s) More...
 
 initPhrasesForm ()
 
 addPhrase (ilPropertyFormGUI $a_form=null)
 Creates an output for the addition of phrases. More...
 
 addSelectedPhrase ()
 
 renderStatisticsDetailsTable (array $a_head, array $a_rows, array $a_foot=null)
 

Additional Inherited Members

- Static Public Member Functions inherited from SurveyQuestionGUI
static _getQuestionGUI ($questiontype, $question_id=-1)
 Creates a question gui representation. More...
 
static _getGUIClassNameForId ($a_q_id)
 
static _getClassNameForQType ($q_type)
 
- Data Fields inherited from SurveyQuestionGUI
 $object
 
- Protected Attributes inherited from SurveyQuestionGUI
 $tpl
 
 $lng
 
 $ctrl
 
 $cumulated
 
 $parent_url
 
 $log
 

Detailed Description

SingleChoice survey question GUI representation.

The SurveySingleChoiceQuestionGUI class encapsulates the GUI representation for single choice survey question types.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 37 of file class.SurveySingleChoiceQuestionGUI.php.

Member Function Documentation

◆ addFieldsToEditForm()

SurveySingleChoiceQuestionGUI::addFieldsToEditForm ( ilPropertyFormGUI  $a_form)
protected

Definition at line 55 of file class.SurveySingleChoiceQuestionGUI.php.

References ilPropertyFormGUI\addItem(), object, and ilFormPropertyGUI\setRequired().

56  {
57  // orientation
58  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
59  $orientation->setRequired(false);
60  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
61  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
62  $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
63  $a_form->addItem($orientation);
64 
65  // Answers
66  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
67  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
68  $answers->setRequired(false);
69  $answers->setAllowMove(true);
70  $answers->setShowWizard(true);
71  $answers->setShowSavePhrase(true);
72  $answers->setUseOtherAnswer(true);
73  $answers->setShowNeutralCategory(true);
74  $answers->setNeutralCategoryTitle($this->lng->txt('svy_neutral_answer'));
75  $answers->setDisabledScale(false);
76  $a_form->addItem($answers);
77 
78  // values
79  $orientation->setValue($this->object->getOrientation());
80  if (!$this->object->getCategories()->getCategoryCount())
81  {
82  $this->object->getCategories()->addCategory("");
83  }
84  $answers->setValues($this->object->getCategories());
85  }
This class represents an option in a radio group.
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a property in a property form.
This class represents a survey question category wizard property in a property form.
Create new PHPExcel object
obj_idprivate
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:

◆ getParsedAnswers()

SurveySingleChoiceQuestionGUI::getParsedAnswers ( array  $a_working_data = null,
  $a_only_user_anwers = false 
)

Definition at line 104 of file class.SurveySingleChoiceQuestionGUI.php.

References $options, $text, and array.

Referenced by getPrintView().

105  {
106  if(is_array($a_working_data))
107  {
108  $user_answer = $a_working_data[0];
109  }
110 
111  $options = array();
112  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
113  {
114  $cat = $this->object->categories->getCategory($i);
115  $value = ($cat->scale) ? ($cat->scale - 1) : $i;
116 
117  $checked = "unchecked";
118  $text = null;
119  if(is_array($a_working_data) &&
120  is_array($user_answer))
121  {
122  if($value == $user_answer["value"])
123  {
124  $checked = "checked";
125  if($user_answer["textanswer"])
126  {
127  $text = $user_answer["textanswer"];
128  }
129  }
130  }
131 
132  // "other" options have to be last or horizontal will be screwed
133  $idx = $cat->other."_".$value;
134 
135  if(!$a_only_user_anwers || $checked == "checked")
136  {
137  $options[$idx] = array(
138  "value" => $value
139  ,"title" => trim($cat->title)
140  ,"other" => (bool)$cat->other
141  ,"checked" => $checked
142  ,"textanswer" => $text
143  );
144  }
145 
146  ksort($options);
147  }
148 
149  return array_values($options);
150  }
if(!is_array($argv)) $options
Create styles array
The data for the language used.
$text
+ Here is the caller graph for this function:

◆ getPrintView()

SurveySingleChoiceQuestionGUI::getPrintView (   $question_title = 1,
  $show_questiontext = 1,
  $survey_id = null,
array  $a_working_data = null 
)

Creates a HTML representation of the question.

private

Definition at line 157 of file class.SurveySingleChoiceQuestionGUI.php.

References $options, ilUtil\getHtmlPath(), ilUtil\getImagePath(), getParsedAnswers(), SurveyQuestionGUI\getPrintViewQuestionTitle(), object, SurveyQuestionGUI\outQuestionText(), and ilUtil\prepareFormOutput().

158  {
159  $options = $this->getParsedAnswers($a_working_data);
160 
161  // rendering
162 
163  $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
164  switch ($this->object->orientation)
165  {
166  case 0:
167  // vertical orientation
168  foreach($options as $option)
169  {
170  if ($option["other"])
171  {
172  $template->setCurrentBlock("other_row");
173  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
174  $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
175  $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
176  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($option["title"]));
177  $template->setVariable("OTHER_ANSWER", $option["textanswer"]
178  ? ilUtil::prepareFormOutput($option["textanswer"])
179  : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
180  $template->parseCurrentBlock();
181  }
182  else
183  {
184 
185  $template->setCurrentBlock("row");
186  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
187  $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
188  $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
189  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
190  $template->parseCurrentBlock();
191  }
192  }
193  break;
194  case 1:
195  // horizontal orientation
196  foreach($options as $option)
197  {
198  $template->setCurrentBlock("radio_col");
199  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
200  $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
201  $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
202  $template->parseCurrentBlock();
203  }
204  foreach($options as $option)
205  {
206  if ($option["other"])
207  {
208  $template->setCurrentBlock("other_text_col");
209  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($option["title"]));
210  $template->setVariable("OTHER_ANSWER", $option["textanswer"]
211  ? ilUtil::prepareFormOutput($option["textanswer"])
212  : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
213  $template->parseCurrentBlock();
214  }
215  else
216  {
217  $template->setCurrentBlock("text_col");
218  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
219  $template->parseCurrentBlock();
220  }
221  }
222  break;
223  case 2:
224  foreach($options as $option)
225  {
226  $template->setCurrentBlock("comborow");
227  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
228  $template->setVariable("VALUE_SC", $option["value"]);
229  if($option["checked"] == "checked")
230  {
231  $template->setVariable("SELECTED_SC", ' selected="selected"');
232  }
233  $template->parseCurrentBlock();
234  }
235  $template->setCurrentBlock("combooutput");
236  $template->setVariable("QUESTION_ID", $this->object->getId());
237  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
238  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
239  $template->parseCurrentBlock();
240  break;
241  }
242  if ($question_title)
243  {
244  $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
245  }
246  if ($show_questiontext)
247  {
248  $this->outQuestionText($template);
249  }
250  $template->parseCurrentBlock();
251  return $template->get();
252  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getParsedAnswers(array $a_working_data=null, $a_only_user_anwers=false)
if(!is_array($argv)) $options
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
static getHtmlPath($relative_path)
get url of path
Create new PHPExcel object
obj_idprivate
getPrintViewQuestionTitle($question_title=1)
+ Here is the call graph for this function:

◆ getWorkingForm()

SurveySingleChoiceQuestionGUI::getWorkingForm (   $working_data = "",
  $question_title = 1,
  $show_questiontext = 1,
  $error_message = "",
  $survey_id = null 
)

Creates the question output form for the learner.

public

Definition at line 264 of file class.SurveySingleChoiceQuestionGUI.php.

References SurveyQuestionGUI\getMaterialOutput(), object, SurveyQuestionGUI\outQuestionText(), and ilUtil\prepareFormOutput().

265  {
266  $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
267  $template->setCurrentBlock("material");
268  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
269  $template->parseCurrentBlock();
270  switch ($this->object->orientation)
271  {
272  case 0:
273  // vertical orientation
274  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
275  {
276  $cat = $this->object->categories->getCategory($i);
277 
278  $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
279  $this->log->debug("Vertical orientation - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
280 
281  if ($cat->other)
282  {
283  $template->setCurrentBlock("other_row");
284  if (strlen($cat->title))
285  {
286  $template->setVariable("OTHER_LABEL", $cat->title);
287  }
288  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
289  $template->setVariable("QUESTION_ID", $this->object->getId());
290  if (is_array($working_data))
291  {
292  foreach ($working_data as $value)
293  {
294  if (strlen($value["value"]))
295  {
296  if ($value["value"] == $cat->scale-1)
297  {
298  if (strlen($value['textanswer'])) $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
299  if (!$value['uncheck'])
300  {
301  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
302  }
303  }
304  }
305  }
306  }
307  $template->parseCurrentBlock();
308  }
309  else
310  {
311  $template->setCurrentBlock("row");
312  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
313  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
314  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
315  $template->setVariable("QUESTION_ID", $this->object->getId());
316  if (is_array($working_data))
317  {
318  foreach ($working_data as $value)
319  {
320  if (strcmp($value["value"], "") != 0)
321  {
322  if ($value["value"] == $cat->scale-1)
323  {
324  if (!$value['uncheck'])
325  {
326  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
327  }
328  }
329  }
330  }
331  }
332  $template->parseCurrentBlock();
333  }
334  $template->touchBlock('outer_row');
335  }
336  break;
337  case 1:
338  // horizontal orientation
339  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
340  {
341  $cat = $this->object->categories->getCategory($i);
342 
343  $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
344  $this->log->debug("Horizontal orientation - Original NEUTRAL scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
345 
346  $template->setCurrentBlock("radio_col");
347  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
348  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
349  $template->setVariable("QUESTION_ID", $this->object->getId());
350  if (is_array($working_data))
351  {
352  foreach ($working_data as $value)
353  {
354  if (strcmp($value["value"], "") != 0)
355  {
356  if ($value["value"] == $cat->scale-1)
357  {
358  if (!$value['uncheck'])
359  {
360  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
361  }
362  }
363  }
364  }
365  }
366  $template->parseCurrentBlock();
367  }
368  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
369  {
370  $cat = $this->object->categories->getCategory($i);
371 
372  $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
373  $this->log->debug("Horizontal orientation - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
374 
375  if ($cat->other)
376  {
377  $template->setCurrentBlock("text_other_col");
378  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
379  $template->setVariable("QUESTION_ID", $this->object->getId());
380  if (strlen($cat->title))
381  {
382  $template->setVariable("OTHER_LABEL", $cat->title);
383  }
384  if (is_array($working_data))
385  {
386  foreach ($working_data as $value)
387  {
388  if (strlen($value["value"]))
389  {
390  if ($value["value"] == $cat->scale-1 && strlen($value['textanswer']))
391  {
392  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
393  }
394  }
395  }
396  }
397  $template->parseCurrentBlock();
398  }
399  else
400  {
401  $template->setCurrentBlock("text_col");
402  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
403  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
404  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
405  $template->setVariable("QUESTION_ID", $this->object->getId());
406  $template->parseCurrentBlock();
407  }
408  $template->touchBlock('text_outer_col');
409  }
410  break;
411  case 2:
412  // combobox output
413  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
414  {
415  $cat = $this->object->categories->getCategory($i);
416 
417  $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
418  $this->log->debug("Combobox - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
419 
420  $template->setCurrentBlock("comborow");
421  $template->setVariable("TEXT_SC", $cat->title);
422  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
423  if (is_array($working_data))
424  {
425  if (strcmp($working_data[0]["value"], "") != 0)
426  {
427  if ($working_data[0]["value"] == $cat->scale-1)
428  {
429  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
430  }
431  }
432  }
433  $template->parseCurrentBlock();
434  }
435  $template->setCurrentBlock("combooutput");
436  $template->setVariable("QUESTION_ID", $this->object->getId());
437  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
438  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
439  $template->parseCurrentBlock();
440  break;
441  }
442  if ($question_title)
443  {
444  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
445  }
446  $template->setCurrentBlock("question_data");
447  if (strcmp($error_message, "") != 0)
448  {
449  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
450  }
451  if ($show_questiontext)
452  {
453  $this->outQuestionText($template);
454  }
455  $template->parseCurrentBlock();
456  return $template->get();
457  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaterialOutput()
Creates the HTML output of the question material(s)
special template class to simplify handling of ITX/PEAR
Create new PHPExcel object
obj_idprivate
+ Here is the call graph for this function:

◆ importEditFormValues()

SurveySingleChoiceQuestionGUI::importEditFormValues ( ilPropertyFormGUI  $a_form)
protected

Definition at line 87 of file class.SurveySingleChoiceQuestionGUI.php.

References $_POST, and ilPropertyFormGUI\getInput().

88  {
89  $this->log->debug("importing edit values");
90 
91  $this->object->setOrientation($a_form->getInput("orientation"));
92 
93  $this->object->categories->flushCategories();
94  foreach ($_POST['answers']['answer'] as $key => $value)
95  {
96  if (strlen($value)) $this->object->getCategories()->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
97  }
98  if (strlen($_POST['answers']['neutral']))
99  {
100  $this->object->getCategories()->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
101  }
102  }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
$_POST["username"]
+ Here is the call graph for this function:

◆ initObject()

SurveySingleChoiceQuestionGUI::initObject ( )
protected

Definition at line 39 of file class.SurveySingleChoiceQuestionGUI.php.

40  {
41  include_once "./Modules/SurveyQuestionPool/classes/class.SurveySingleChoiceQuestion.php";
42  $this->object = new SurveySingleChoiceQuestion();
43  }

◆ setQuestionTabs()

SurveySingleChoiceQuestionGUI::setQuestionTabs ( )

Definition at line 50 of file class.SurveySingleChoiceQuestionGUI.php.

References SurveyQuestionGUI\setQuestionTabsForClass().

51  {
52  $this->setQuestionTabsForClass("surveysinglechoicequestiongui");
53  }
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: