ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.SurveySingleChoiceQuestion.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 
38 {
45 
58  $title = "",
59  $description = "",
60  $author = "",
61  $questiontext = "",
62  $owner = -1,
63  $orientation = 1
64  )
65  {
67  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
68  $this->orientation = $orientation;
69  $this->categories = new SurveyCategories();
70  }
71 
79  function &getCategoriesForPhrase($phrase_id)
80  {
81  global $ilDB;
82  $categories = array();
83  $result = $ilDB->queryF("SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
84  array('integer'),
85  array($phrase_id)
86  );
87  while ($row = $ilDB->fetchAssoc($result))
88  {
89  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
90  {
91  $categories[$row["category_id"]] = $this->lng->txt($row["title"]);
92  }
93  else
94  {
95  $categories[$row["category_id"]] = $row["title"];
96  }
97  }
98  return $categories;
99  }
100 
107  function addPhrase($phrase_id)
108  {
109  global $ilUser;
110  global $ilDB;
111 
112  $result = $ilDB->queryF("SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = 0 OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
113  array('integer', 'integer'),
114  array($phrase_id, $ilUser->getId())
115  );
116  while ($row = $ilDB->fetchAssoc($result))
117  {
118  $neutral = $row["neutral"];
119  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
120  {
121  $this->categories->addCategory($this->lng->txt($row["title"]), 0, $neutral);
122  }
123  else
124  {
125  $this->categories->addCategory($row["title"], 0, $neutral);
126  }
127  }
128  }
129 
138  {
139  global $ilDB;
140 
141  $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question, " . $this->getAdditionalTableName() . " WHERE svy_question.question_id = %s AND svy_question.question_id = " . $this->getAdditionalTableName() . ".question_fi",
142  array('integer'),
143  array($id)
144  );
145  if ($result->numRows() == 1)
146  {
147  return $ilDB->fetchAssoc($result);
148  }
149  else
150  {
151  return array();
152  }
153  }
154 
161  function loadFromDb($id)
162  {
163  global $ilDB;
164 
165  $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = svy_question.question_id WHERE svy_question.question_id = %s",
166  array('integer'),
167  array($id)
168  );
169  if ($result->numRows() == 1)
170  {
171  $data = $ilDB->fetchAssoc($result);
172  $this->setId($data["question_id"]);
173  $this->setTitle($data["title"]);
174  $this->label = $data['label'];
175  $this->setDescription($data["description"]);
176  $this->setObjId($data["obj_fi"]);
177  $this->setAuthor($data["author"]);
178  $this->setOwner($data["owner_fi"]);
179  include_once("./Services/RTE/classes/class.ilRTE.php");
180  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
181  $this->setObligatory($data["obligatory"]);
182  $this->setComplete($data["complete"]);
183  $this->setOriginalId($data["original_id"]);
184  $this->setOrientation($data["orientation"]);
185 
186  $this->categories->flushCategories();
187  $result = $ilDB->queryF("SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
188  array('integer'),
189  array($id)
190  );
191  if ($result->numRows() > 0)
192  {
193  while ($data = $ilDB->fetchAssoc($result))
194  {
195  $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
196  }
197  }
198  }
199  parent::loadFromDb($id);
200  }
201 
208  function isComplete()
209  {
210  if (
211  strlen($this->getTitle()) &&
212  strlen($this->getAuthor()) &&
213  strlen($this->getQuestiontext()) &&
214  $this->categories->getCategoryCount()
215  )
216  {
217  return 1;
218  }
219  else
220  {
221  return 0;
222  }
223  }
224 
230  function saveToDb($original_id = "")
231  {
232  global $ilDB;
233 
234  $affectedRows = parent::saveToDb($original_id);
235  if ($affectedRows == 1)
236  {
237  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
238  array('integer'),
239  array($this->getId())
240  );
241  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
242  array('integer', 'text'),
243  array(
244  $this->getId(),
245  $this->getOrientation()
246  )
247  );
248 
249  $this->saveMaterial();
250  $this->saveCategoriesToDb();
251  }
252  }
253 
255  {
256  global $ilDB;
257 
258  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
259  array('integer'),
260  array($this->getId())
261  );
262 
263  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
264  {
265  $cat = $this->categories->getCategory($i);
266  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
267  $next_id = $ilDB->nextId('svy_variable');
268  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
269  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
270  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
271  );
272  }
273  $this->saveCompletionStatus();
274  }
275 
282  function toXML($a_include_header = TRUE, $obligatory_state = "")
283  {
284  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
285  $a_xml_writer = new ilXmlWriter;
286  $a_xml_writer->xmlHeader();
287  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
288  $xml = $a_xml_writer->xmlDumpMem(FALSE);
289  if (!$a_include_header)
290  {
291  $pos = strpos($xml, "?>");
292  $xml = substr($xml, $pos + 2);
293  }
294  return $xml;
295  }
296 
305  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
306  {
307  $attrs = array(
308  "id" => $this->getId(),
309  "title" => $this->getTitle(),
310  "type" => $this->getQuestiontype(),
311  "obligatory" => $this->getObligatory()
312  );
313  $a_xml_writer->xmlStartTag("question", $attrs);
314 
315  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
316  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
317  if (strlen($this->label))
318  {
319  $attrs = array(
320  "label" => $this->label,
321  );
322  }
323  else
324  {
325  $attrs = array();
326  }
327  $a_xml_writer->xmlStartTag("questiontext", $attrs);
328  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
329  $a_xml_writer->xmlEndTag("questiontext");
330 
331  $a_xml_writer->xmlStartTag("responses");
332 
333  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
334  {
335  $attrs = array(
336  "id" => $i
337  );
338  if (strlen($this->categories->getCategory($i)->other)) $attrs['other'] = $this->categories->getCategory($i)->other;
339  if (strlen($this->categories->getCategory($i)->neutral)) $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
340  if (strlen($this->categories->getCategory($i)->label)) $attrs['label'] = $this->categories->getCategory($i)->label;
341  if (strlen($this->categories->getCategory($i)->scale)) $attrs['scale'] = $this->categories->getCategory($i)->scale;
342  $a_xml_writer->xmlStartTag("response_single", $attrs);
343  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
344  $a_xml_writer->xmlEndTag("response_single");
345  }
346 
347  $a_xml_writer->xmlEndTag("responses");
348 
349  if (count($this->material))
350  {
351  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
352  {
353  $attrs = array(
354  "label" => $this->material["title"]
355  );
356  $a_xml_writer->xmlStartTag("material", $attrs);
357  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
358  if (strcmp($matches[1], "") != 0)
359  {
360  $intlink = $this->material["internal_link"];
361  }
362  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
363  $a_xml_writer->xmlEndTag("material");
364  }
365  }
366 
367  $a_xml_writer->xmlStartTag("metadata");
368  $a_xml_writer->xmlStartTag("metadatafield");
369  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
370  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
371  $a_xml_writer->xmlEndTag("metadatafield");
372  $a_xml_writer->xmlEndTag("metadata");
373 
374  $a_xml_writer->xmlEndTag("question");
375  }
376 
385  function importAdditionalMetadata($a_meta)
386  {
387  foreach ($a_meta as $key => $value)
388  {
389  switch ($value["label"])
390  {
391  case "orientation":
392  $this->setOrientation($value["entry"]);
393  break;
394  }
395  }
396  }
397 
405  function addStandardNumbers($lower_limit, $upper_limit)
406  {
407  for ($i = $lower_limit; $i <= $upper_limit; $i++)
408  {
409  $this->categories->addCategory($i);
410  }
411  }
412 
420  function savePhrase($title)
421  {
422  global $ilUser;
423  global $ilDB;
424 
425  $next_id = $ilDB->nextId('svy_phrase');
426  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
427  array('integer','text','text','integer','integer'),
428  array($next_id, $title, 1, $ilUser->getId(), time())
429  );
430  $phrase_id = $next_id;
431 
432  $counter = 1;
433  foreach ($_SESSION['save_phrase_data'] as $data)
434  {
435  $next_id = $ilDB->nextId('svy_category');
436  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
437  array('integer','text','text','integer','integer','text'),
438  array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
439  );
440  $category_id = $next_id;
441  $next_id = $ilDB->nextId('svy_phrase_cat');
442  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
443  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
444  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
445  );
446  $counter++;
447  }
448  }
449 
456  function getQuestionType()
457  {
458  return "SurveySingleChoiceQuestion";
459  }
460 
468  {
469  return "svy_qst_sc";
470  }
471 
478  function &getWorkingDataFromUserInput($post_data)
479  {
480  $entered_value = $post_data[$this->getId() . "_value"];
481  $data = array();
482  if (strlen($entered_value))
483  {
484  array_push($data, array("value" => $entered_value, "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other']));
485  }
486  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
487  {
488  $cat = $this->categories->getCategory($i);
489  if ($cat->other)
490  {
491  if ($i != $entered_value)
492  {
493  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
494  {
495  array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
496  }
497  }
498  }
499  }
500  return $data;
501  }
502 
512  function checkUserInput($post_data, $survey_id)
513  {
514  $entered_value = $post_data[$this->getId() . "_value"];
515 
516  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
517 
518  if (strlen($entered_value) == 0) return $this->lng->txt("question_not_checked");
519 
520  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
521  {
522  $cat = $this->categories->getCategory($i);
523  if ($cat->other)
524  {
525  if ($i == $entered_value)
526  {
527  if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"]))
528  {
529  return $this->lng->txt("question_mr_no_other_answer");
530  }
531  }
532  else
533  {
534  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
535  {
536  return $this->lng->txt("question_sr_no_other_answer_checked");
537  }
538  }
539  }
540  }
541 
542  return "";
543  }
544 
550  public function saveRandomData($active_id)
551  {
552  global $ilDB;
553  // single response
554  $category = rand(0, $this->categories->getCategoryCount()-1);
555  $cat = $this->categories->getCategory($category);
556  $next_id = $ilDB->nextId('svy_answer');
557  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
558  array('integer','integer','integer','float','text','integer'),
559  array($next_id, $this->getId(), $active_id, $category, ($cat->other) ? "Random Data" : null, time())
560  );
561  }
562 
563  function saveUserInput($post_data, $active_id, $a_return = false)
564  {
565  global $ilDB;
566 
567  $entered_value = $post_data[$this->getId() . "_value"];
568 
569  if($a_return)
570  {
571  return array(array("value"=>$entered_value,
572  "textanswer"=>$post_data[$this->getId() . "_" . $entered_value . "_other"]));
573  }
574  if (strlen($entered_value) == 0) return;
575 
576  $next_id = $ilDB->nextId('svy_answer');
577 
578  /*$affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
579  array('integer','integer','integer','float','text','integer'),
580  array($next_id, $this->getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $post_data[$this->getId() . "_" . $entered_value . "_other"] : null, time())
581  );*/
582  #20216
583  $fields = array();
584  $fields['answer_id'] = array("integer", $next_id);
585  $fields['question_fi'] = array("integer", $this->getId());
586  $fields['active_fi'] = array("integer", $active_id);
587  $fields['value'] = array("float", (strlen($entered_value)) ? $entered_value : NULL);
588  $fields['textanswer'] = array("clob", ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $post_data[$this->getId() . "_" . $entered_value . "_other"] : null);
589  $fields['tstamp'] = array("integer", time());
590 
591  $affectedRows = $ilDB->insert("svy_answer", $fields);
592  }
593 
594  function &getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
595  {
596  global $ilDB;
597 
598  $question_id = $this->getId();
599 
600  $result_array = array();
601  $cumulated = array();
602 
603  $sql = "SELECT svy_answer.* FROM svy_answer".
604  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
605  " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, "integer").
606  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
607  if($finished_ids)
608  {
609  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
610  }
611 
612  $result = $ilDB->query($sql);
613  while ($row = $ilDB->fetchAssoc($result))
614  {
615  $cumulated[$row["value"]]++;
616 
617  // add text value to result array
618  if ($row["textanswer"])
619  {
620  $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
621  }
622  }
623  // sort textanswers by value
624  if (is_array($result_array["textanswers"]))
625  {
626  ksort($result_array["textanswers"], SORT_NUMERIC);
627  }
628  asort($cumulated, SORT_NUMERIC);
629  end($cumulated);
630  $numrows = $result->numRows();
631  $result_array["USERS_ANSWERED"] = $result->numRows();
632  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
633 
634  if(sizeof($cumulated))
635  {
636  $prefix = "";
637  if (strcmp(key($cumulated), "") != 0)
638  {
639  $prefix = (key($cumulated)+1) . " - ";
640  }
641  $category = $this->categories->getCategoryForScale(key($cumulated)+1);
642  $result_array["MODE"] = $prefix . $category->title;
643  $result_array["MODE_VALUE"] = key($cumulated)+1;
644  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
645  }
646  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
647  {
648  $cat = $this->categories->getCategory($key);
649  $percentage = 0;
650  if ($numrows > 0)
651  {
652  $percentage = (float)((int)$cumulated[$cat->scale-1]/$numrows);
653  }
654  if ($cat->other)
655  {
656  $result_array["variables"][$key] = array("title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt('other_answer'), "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
657  }
658  else
659  {
660  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
661  }
662  }
663  ksort($cumulated, SORT_NUMERIC);
664  $median = array();
665  $total = 0;
666  foreach ($cumulated as $value => $key)
667  {
668  $total += $key;
669  for ($i = 0; $i < $key; $i++)
670  {
671  array_push($median, $value+1);
672  }
673  }
674  if ($total > 0)
675  {
676  if (($total % 2) == 0)
677  {
678  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
679  if (round($median_value) != $median_value)
680  {
681  $median_value = $median_value . "<br />" . "(" . $this->lng->txt("median_between") . " " . (floor($median_value)) . "-" . $this->categories->getCategory((int)floor($median_value)-1)->title . " " . $this->lng->txt("and") . " " . (ceil($median_value)) . "-" . $this->categories->getCategory((int)ceil($median_value)-1)->title . ")";
682  }
683  }
684  else
685  {
686  $median_value = $median[(($total+1)/2)-1];
687  }
688  }
689  else
690  {
691  $median_value = "";
692  }
693  $result_array["ARITHMETIC_MEAN"] = "";
694  $result_array["MEDIAN"] = $median_value;
695  $result_array["QUESTION_TYPE"] = "SurveySingleChoiceQuestion";
696  return $result_array;
697  }
698 
708  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
709  {
710  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
711  $worksheet =& $workbook->addWorksheet();
712  $rowcounter = 0;
713  switch ($export_label)
714  {
715  case 'label_only':
716  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
717  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
718  break;
719  case 'title_only':
720  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
721  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
722  break;
723  default:
724  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
725  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
726  $rowcounter++;
727  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
728  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
729  break;
730  }
731  $rowcounter++;
732  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
733  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
734  $rowcounter++;
735  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
736  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
737  $rowcounter++;
738  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
739  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
740  $rowcounter++;
741  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
742  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
743  $rowcounter++;
744 
745  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
746  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
747  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
748  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
749  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
750  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
751  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
752  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
753  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
754  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
755  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
756  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
757  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
758  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("svy_fraction_of_selections")), $format_title);
759 
760  foreach ($eval_data["variables"] as $key => $value)
761  {
762  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
763  $category = $this->categories->getCategory($key);
764  $worksheet->write($rowcounter, 2, $category->scale);
765  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
766  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
767  }
768 
769  // add text answers to detailed results
770  if (is_array($eval_data["textanswers"]))
771  {
772  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
773  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
774  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
775 
776  foreach ($eval_data["textanswers"] as $key => $answers)
777  {
778  $title = $eval_data["variables"][$key]["title"];
779  foreach ($answers as $answer)
780  {
781  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
782  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
783  }
784  }
785  }
786  }
787 
796  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
797  {
798  $title = parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
799 
800  // optionally add header for text answer
801  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
802  {
803  $cat = $this->categories->getCategory($i);
804  if ($cat->other)
805  {
806  if(!$a_use_label || $a_substitute)
807  {
808  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
809  }
810  else
811  {
812  array_push($a_array, "");
813  }
814  break;
815  }
816  }
817  }
818 
826  function addUserSpecificResultsData(&$a_array, &$resultset)
827  {
828  // check if text answer column is needed
829  $other = false;
830  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
831  {
832  $cat = $this->categories->getCategory($i);
833  if ($cat->other)
834  {
835  $other = true;
836  break;
837  }
838  }
839 
840  if (count($resultset["answers"][$this->getId()]))
841  {
842  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
843  {
844  array_push($a_array, $answer["value"]+1);
845 
846  // add the text answer from the selected option
847  if ($other)
848  {
849  array_push($a_array, $answer["textanswer"]);
850  }
851  }
852  }
853  else
854  {
855  array_push($a_array, $this->getSkippedValue());
856 
857  if ($other)
858  {
859  array_push($a_array, "");
860  }
861  }
862  }
863 
871  function &getUserAnswers($survey_id, $finished_ids)
872  {
873  global $ilDB;
874 
875  $answers = array();
876 
877  $sql = "SELECT svy_answer.* FROM svy_answer".
878  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
879  " WHERE svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
880  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
881  if($finished_ids)
882  {
883  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
884  }
885 
886  $result = $ilDB->query($sql);
887  while ($row = $ilDB->fetchAssoc($result))
888  {
889  $category = $this->categories->getCategoryForScale($row["value"]+1);
890  $title = $row["value"] + 1 . " - " . $category->title;
891  if ($category->other) $title .= ": " . $row["textanswer"];
892  $answers[$row["active_fi"]] = $title;
893  }
894  return $answers;
895  }
896 
903  function importResponses($a_data)
904  {
905  foreach ($a_data as $id => $data)
906  {
907  $categorytext = "";
908  foreach ($data["material"] as $material)
909  {
910  $categorytext .= $material["text"];
911  }
912  $this->categories->addCategory(
913  $categorytext,
914  strlen($data['other']) ? $data['other'] : 0,
915  strlen($data['neutral']) ? $data['neutral'] : 0,
916  strlen($data['label']) ? $data['label'] : null,
917  strlen($data['scale']) ? $data['scale'] : null
918  );
919  }
920  }
921 
929  {
930  return TRUE;
931  }
932 
940  {
941  return array("<", "<=", "=", "<>", ">=", ">");
942  }
943 
949  public function getPreconditionOptions()
950  {
951  global $lng;
952 
953  $options = array();
954  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
955  {
956  $category = $this->categories->getCategory($i);
957  $options[$category->scale-1] = $category->scale . " - " . $category->title;
958  }
959  return $options;
960  }
961 
968  public function getPreconditionSelectValue($default = "", $title, $variable)
969  {
970  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
971  $step3 = new ilSelectInputGUI($title, $variable);
972  $options = $this->getPreconditionOptions();
973  $step3->setOptions($options);
974  $step3->setValue($default);
975  return $step3;
976  }
977 
985  function getPreconditionValueOutput($value)
986  {
987  // #18136
988  $category = $this->categories->getCategoryForScale($value+1);
989 
990  // #17895 - see getPreconditionOptions()
991  return $category->scale .
992  " - " .
993  ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
994  }
995 
996  public function getCategories()
997  {
998  return $this->categories;
999  }
1000 
1001 }
1002 ?>
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
saveUserInput($post_data, $active_id, $a_return=false)
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
getTitle()
Gets the title string of the SurveyQuestion object.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
usableForPrecondition()
Returns if the question is usable for preconditions.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
$result
getObligatory($survey_id="")
Gets the obligatory state of the question.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
setOrientation($orientation=0)
Sets the orientation of the question output.
_convert_text($a_text, $a_target="has been removed")
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setId($id=-1)
Sets the id of the SurveyQuestion object.
isComplete()
Returns true if the question is complete for use.
savePhrase($title)
Saves a set of categories to a default phrase.
XML writer class.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
addStandardNumbers($lower_limit, $upper_limit)
Adds standard numbers as categories.
importResponses($a_data)
Import response data from the question import file.
saveToDb($original_id="")
Saves a SurveySingleChoiceQuestion object to a database.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
setOriginalId($original_id)
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
Class SurveyCategories.
getPreconditionOptions()
Returns the options for preconditions.
_getQuestionDataArray($id)
Returns the question data fields from the database.
$data
addUserSpecificResultsExportTitles(&$a_array, $a_use_label=false, $a_substitute=true)
overwritten addUserSpecificResultsExportTitles
if(!is_array($argv)) $options
getId()
Gets the id of the SurveyQuestion object.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
Basic class for all survey question types.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
saveMaterial()
save material to db
xmlHeader()
Writes xml header public.
& getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
loadFromDb($id)
Loads a SurveySingleChoiceQuestion object from the database.
global $ilUser
Definition: imgupload.php:15
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
global $ilDB
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
addPhrase($phrase_id)
Adds a phrase to the question.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
getQuestionType()
Returns the question type of the question.
getDescription()
Gets the description string of the SurveyQuestion object.
SurveySingleChoiceQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=1)
SurveySingleChoiceQuestion constructor.
setObjId($obj_id=0)
Set the reference id of the container object.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
getAvailableRelations()
Returns the available relations for the question.
setTitle($title="")
Sets the title string of the SurveyQuestion object.