ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
46 
59  $title = "",
60  $description = "",
61  $author = "",
62  $questiontext = "",
63  $owner = -1,
64  $orientation = 1
65  )
66  {
68  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
69  $this->orientation = $orientation;
70  $this->categories = new SurveyCategories();
71  }
72 
80  function &getCategoriesForPhrase($phrase_id)
81  {
82  global $ilDB;
83  $categories = array();
84  $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",
85  array('integer'),
86  array($phrase_id)
87  );
88  while ($row = $ilDB->fetchAssoc($result))
89  {
90  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
91  {
92  $categories[$row["category_id"]] = $this->lng->txt($row["title"]);
93  }
94  else
95  {
96  $categories[$row["category_id"]] = $row["title"];
97  }
98  }
99  return $categories;
100  }
101 
108  function addPhrase($phrase_id)
109  {
110  global $ilUser;
111  global $ilDB;
112 
113  $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",
114  array('integer', 'integer'),
115  array($phrase_id, $ilUser->getId())
116  );
117  while ($row = $ilDB->fetchAssoc($result))
118  {
119  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
120  {
121  $this->categories->addCategory($this->lng->txt($row["title"]));
122  }
123  else
124  {
125  $this->categories->addCategory($row["title"]);
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  }
200  }
201 
208  function isComplete()
209  {
210  if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
211  {
212  return 1;
213  }
214  else
215  {
216  return 0;
217  }
218  }
219 
225  function saveToDb($original_id = "")
226  {
227  global $ilDB;
228 
229  $affectedRows = parent::saveToDb($original_id);
230  if ($affectedRows == 1)
231  {
232  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
233  array('integer'),
234  array($this->getId())
235  );
236  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
237  array('integer', 'text'),
238  array(
239  $this->getId(),
240  $this->getOrientation()
241  )
242  );
243 
244  $this->saveMaterial();
245  $this->saveCategoriesToDb();
246  }
247  }
248 
250  {
251  global $ilDB;
252 
253  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
254  array('integer'),
255  array($this->getId())
256  );
257 
258  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
259  {
260  $cat = $this->categories->getCategory($i);
261  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
262  $next_id = $ilDB->nextId('svy_variable');
263  $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)",
264  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
265  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
266  );
267  }
268  $this->saveCompletionStatus();
269  }
270 
277  function toXML($a_include_header = TRUE, $obligatory_state = "")
278  {
279  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
280  $a_xml_writer = new ilXmlWriter;
281  $a_xml_writer->xmlHeader();
282  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
283  $xml = $a_xml_writer->xmlDumpMem(FALSE);
284  if (!$a_include_header)
285  {
286  $pos = strpos($xml, "?>");
287  $xml = substr($xml, $pos + 2);
288  }
289  return $xml;
290  }
291 
300  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
301  {
302  $attrs = array(
303  "id" => $this->getId(),
304  "title" => $this->getTitle(),
305  "type" => $this->getQuestiontype(),
306  "obligatory" => $this->getObligatory()
307  );
308  $a_xml_writer->xmlStartTag("question", $attrs);
309 
310  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
311  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
312  if (strlen($this->label))
313  {
314  $attrs = array(
315  "label" => $this->label,
316  );
317  }
318  else
319  {
320  $attrs = array();
321  }
322  $a_xml_writer->xmlStartTag("questiontext", $attrs);
323  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
324  $a_xml_writer->xmlEndTag("questiontext");
325 
326  $a_xml_writer->xmlStartTag("responses");
327 
328  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
329  {
330  $attrs = array(
331  "id" => $i
332  );
333  if (strlen($this->categories->getCategory($i)->other)) $attrs['other'] = $this->categories->getCategory($i)->other;
334  if (strlen($this->categories->getCategory($i)->neutral)) $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
335  if (strlen($this->categories->getCategory($i)->label)) $attrs['label'] = $this->categories->getCategory($i)->label;
336  if (strlen($this->categories->getCategory($i)->scale)) $attrs['scale'] = $this->categories->getCategory($i)->scale;
337  $a_xml_writer->xmlStartTag("response_single", $attrs);
338  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
339  $a_xml_writer->xmlEndTag("response_single");
340  }
341 
342  $a_xml_writer->xmlEndTag("responses");
343 
344  if (count($this->material))
345  {
346  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
347  {
348  $attrs = array(
349  "label" => $this->material["title"]
350  );
351  $a_xml_writer->xmlStartTag("material", $attrs);
352  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
353  if (strcmp($matches[1], "") != 0)
354  {
355  $intlink = $this->material["internal_link"];
356  }
357  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
358  $a_xml_writer->xmlEndTag("material");
359  }
360  }
361 
362  $a_xml_writer->xmlStartTag("metadata");
363  $a_xml_writer->xmlStartTag("metadatafield");
364  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
365  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
366  $a_xml_writer->xmlEndTag("metadatafield");
367  $a_xml_writer->xmlEndTag("metadata");
368 
369  $a_xml_writer->xmlEndTag("question");
370  }
371 
380  function importAdditionalMetadata($a_meta)
381  {
382  foreach ($a_meta as $key => $value)
383  {
384  switch ($value["label"])
385  {
386  case "orientation":
387  $this->setOrientation($value["entry"]);
388  break;
389  }
390  }
391  }
392 
400  function addStandardNumbers($lower_limit, $upper_limit)
401  {
402  for ($i = $lower_limit; $i <= $upper_limit; $i++)
403  {
404  $this->categories->addCategory($i);
405  }
406  }
407 
415  function savePhrase($title)
416  {
417  global $ilUser;
418  global $ilDB;
419 
420  $next_id = $ilDB->nextId('svy_phrase');
421  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
422  array('integer','text','text','integer','integer'),
423  array($next_id, $title, 1, $ilUser->getId(), time())
424  );
425  $phrase_id = $next_id;
426 
427  $counter = 1;
428  foreach ($_SESSION['save_phrase_data'] as $data)
429  {
430  $next_id = $ilDB->nextId('svy_category');
431  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
432  array('integer','text','text','integer','integer'),
433  array($next_id, $data['answer'], 1, $ilUser->getId(), time())
434  );
435  $category_id = $next_id;
436  $next_id = $ilDB->nextId('svy_phrase_cat');
437  $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)",
438  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
439  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
440  );
441  $counter++;
442  }
443  }
444 
451  function getQuestionType()
452  {
453  return "SurveySingleChoiceQuestion";
454  }
455 
463  {
464  return "svy_qst_sc";
465  }
466 
473  function &getWorkingDataFromUserInput($post_data)
474  {
475  $entered_value = $post_data[$this->getId() . "_value"];
476  $data = array();
477  if (strlen($entered_value))
478  {
479  array_push($data, array("value" => $entered_value, "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other']));
480  }
481  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
482  {
483  $cat = $this->categories->getCategory($i);
484  if ($cat->other)
485  {
486  if ($i != $entered_value)
487  {
488  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
489  {
490  array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
491  }
492  }
493  }
494  }
495  return $data;
496  }
497 
507  function checkUserInput($post_data, $survey_id)
508  {
509  $entered_value = $post_data[$this->getId() . "_value"];
510 
511  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
512 
513  if (strlen($entered_value) == 0) return $this->lng->txt("question_not_checked");
514 
515  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
516  {
517  $cat = $this->categories->getCategory($i);
518  if ($cat->other)
519  {
520  if ($i == $entered_value)
521  {
522  if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"]))
523  {
524  return $this->lng->txt("question_mr_no_other_answer");
525  }
526  }
527  else
528  {
529  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
530  {
531  return $this->lng->txt("question_sr_no_other_answer_checked");
532  }
533  }
534  }
535  }
536 
537  return "";
538  }
539 
545  public function saveRandomData($active_id)
546  {
547  global $ilDB;
548  // single response
549  $category = rand(0, $this->categories->getCategoryCount()-1);
550  $cat = $this->categories->getCategory($category);
551  $next_id = $ilDB->nextId('svy_answer');
552  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
553  array('integer','integer','integer','float','text','integer'),
554  array($next_id, $this->getId(), $active_id, $category, ($cat->other) ? "Random Data" : null, time())
555  );
556  }
557 
558  function saveUserInput($post_data, $active_id)
559  {
560  global $ilDB;
561 
562  $entered_value = $post_data[$this->getId() . "_value"];
563  if (strlen($entered_value) == 0) return;
564  $next_id = $ilDB->nextId('svy_answer');
565  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
566  array('integer','integer','integer','float','text','integer'),
567  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())
568  );
569  }
570 
571  function &getCumulatedResults($survey_id, $nr_of_users)
572  {
573  global $ilDB;
574 
575  $question_id = $this->getId();
576 
577  $result_array = array();
578  $cumulated = array();
579 
580  $result = $ilDB->queryF("SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
581  array('integer', 'integer'),
582  array($question_id, $survey_id)
583  );
584 
585  while ($row = $ilDB->fetchAssoc($result))
586  {
587  $cumulated[$row["value"]]++;
588 
589  // add text value to result array
590  if ($row["textanswer"])
591  {
592  $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
593  }
594  }
595  // sort textanswers by value
596  if (is_array($result_array["textanswers"]))
597  {
598  ksort($result_array["textanswers"], SORT_NUMERIC);
599  }
600  asort($cumulated, SORT_NUMERIC);
601  end($cumulated);
602  $numrows = $result->numRows();
603  $result_array["USERS_ANSWERED"] = $result->numRows();
604  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
605 
606  $prefix = "";
607  if (strcmp(key($cumulated), "") != 0)
608  {
609  $prefix = (key($cumulated)+1) . " - ";
610  }
611  $category = $this->categories->getCategoryForScale(key($cumulated)+1);
612  $result_array["MODE"] = $prefix . $category->title;
613  $result_array["MODE_VALUE"] = key($cumulated)+1;
614  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
615  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
616  {
617  $cat = $this->categories->getCategory($key);
618  $percentage = 0;
619  if ($numrows > 0)
620  {
621  $percentage = (float)((int)$cumulated[$cat->scale-1]/$numrows);
622  }
623  if ($cat->other)
624  {
625  $result_array["variables"][$key] = array("title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt('other_answer'), "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
626  }
627  else
628  {
629  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
630  }
631  }
632  ksort($cumulated, SORT_NUMERIC);
633  $median = array();
634  $total = 0;
635  foreach ($cumulated as $value => $key)
636  {
637  $total += $key;
638  for ($i = 0; $i < $key; $i++)
639  {
640  array_push($median, $value+1);
641  }
642  }
643  if ($total > 0)
644  {
645  if (($total % 2) == 0)
646  {
647  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
648  if (round($median_value) != $median_value)
649  {
650  $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 . ")";
651  }
652  }
653  else
654  {
655  $median_value = $median[(($total+1)/2)-1];
656  }
657  }
658  else
659  {
660  $median_value = "";
661  }
662  $result_array["ARITHMETIC_MEAN"] = "";
663  $result_array["MEDIAN"] = $median_value;
664  $result_array["QUESTION_TYPE"] = "SurveySingleChoiceQuestion";
665  return $result_array;
666  }
667 
675  function setExportDetailsXLS(&$adapter, &$eval_data, $export_label)
676  {
677  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
678  $adapter->addWorksheet($this->getTitle());
679  $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
680  $rowcounter = 0;
681  switch ($export_label)
682  {
683  case 'label_only':
684  $adapter->setCellValue(0, 0, $this->lng->txt("label"), CELL_FORMAT_BOLD);
685  $adapter->setCellValue(0, 1, $this->label);
686  break;
687  case 'title_only':
688  $adapter->setCellValue(0, 0, $this->lng->txt("title"), CELL_FORMAT_BOLD);
689  $adapter->setCellValue(0, 1, $this->getTitle());
690  break;
691  default:
692  $adapter->setCellValue(0, 0, $this->lng->txt("title"), CELL_FORMAT_BOLD);
693  $adapter->setCellValue(0, 1, $this->getTitle());
694  $rowcounter++;
695  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("label"), CELL_FORMAT_BOLD);
696  $adapter->setCellValue($rowcounter, 1, $this->label);
697  break;
698  }
699  $rowcounter++;
700  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("question"), CELL_FORMAT_BOLD);
701  $adapter->setCellValue($rowcounter, 1, $this->getQuestiontext());
702  $rowcounter++;
703  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("question_type"), CELL_FORMAT_BOLD);
704  $adapter->setCellValue($rowcounter, 1, $this->lng->txt($this->getQuestionType()));
705  $rowcounter++;
706  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("users_answered"), CELL_FORMAT_BOLD);
707  $adapter->setCellValue($rowcounter, 1, $eval_data["TOTAL"]["USERS_ANSWERED"]);
708  $rowcounter++;
709  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("users_skipped"), CELL_FORMAT_BOLD);
710  $adapter->setCellValue($rowcounter, 1, $eval_data["TOTAL"]["USERS_SKIPPED"]);
711  $rowcounter++;
712 
713  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
714  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("mode"), CELL_FORMAT_BOLD);
715  $adapter->setCellValue($rowcounter++, 1, $matches[1]);
716  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("mode_text"), CELL_FORMAT_BOLD);
717  $adapter->setCellValue($rowcounter++, 1, $matches[2]);
718  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("mode_nr_of_selections"), CELL_FORMAT_BOLD);
719  $adapter->setCellValue($rowcounter++, 1, $eval_data["MODE_NR_OF_SELECTIONS"]);
720  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("median"), CELL_FORMAT_BOLD);
721  $adapter->setCellValue($rowcounter++, 1, str_replace("<br />", " ", $eval_data["MEDIAN"]));
722  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("categories"), CELL_FORMAT_BOLD);
723  $adapter->setCellValue($rowcounter, 1, $this->lng->txt("title"), CELL_FORMAT_TITLE);
724  $adapter->setCellValue($rowcounter, 2, $this->lng->txt("value"), CELL_FORMAT_TITLE);
725  $adapter->setCellValue($rowcounter, 3, $this->lng->txt("category_nr_selected"), CELL_FORMAT_TITLE);
726  $adapter->setCellValue($rowcounter++, 4, $this->lng->txt("percentage_of_selections"), CELL_FORMAT_TITLE);
727 
728  foreach ($eval_data["variables"] as $key => $value)
729  {
730  $adapter->setCellValue($rowcounter, 1, $value["title"]);
731  $category = $this->categories->getCategory($key);
732  $adapter->setCellValue($rowcounter, 2, $category->scale);
733  $adapter->setCellValue($rowcounter, 3, $value["selected"]);
734  $adapter->setCellValue($rowcounter++, 4, $value["percentage"], CELL_FORMAT_PERCENT);
735  }
736 
737  // add text answers to detailed results
738  if (is_array($eval_data["textanswers"]))
739  {
740  $adapter->setCellValue($rowcounter, 0, $this->lng->txt("freetext_answers"), CELL_FORMAT_BOLD);
741  $adapter->setCellValue($rowcounter, 1, $this->lng->txt("title"), CELL_FORMAT_TITLE);
742  $adapter->setCellValue($rowcounter++, 2, $this->lng->txt("answer"), CELL_FORMAT_TITLE);
743 
744  foreach ($eval_data["textanswers"] as $key => $answers)
745  {
746  $title = $eval_data["variables"][$key]["title"];
747  foreach ($answers as $answer)
748  {
749  $adapter->setCellValue($rowcounter, 1, $title);
750  $adapter->setCellValue($rowcounter++, 2, $answer);
751  }
752  }
753  }
754  }
755 
764  function addUserSpecificResultsExportTitles(&$a_array, $a_export_label = "")
765  {
766  // add label dependent title
767  switch($a_export_label)
768  {
769  case "label_only":
770  $title = $this->label ? $this->label : $this->title;
771  break;
772 
773  case "title_only":
775  break;
776 
777  default:
778  $title = $this->label ? $this->title.' - '.$this->label : $this->title;
779  break;
780  }
781  array_push($a_array, $title);
782 
783  // optionally add header for text answer
784  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
785  {
786  $cat = $this->categories->getCategory($i);
787  if ($cat->other)
788  {
789  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
790  break;
791  }
792  }
793  }
794 
802  function addUserSpecificResultsData(&$a_array, &$resultset)
803  {
804  // check if text answer column is needed
805  $other = false;
806  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
807  {
808  $cat = $this->categories->getCategory($i);
809  if ($cat->other)
810  {
811  $other = true;
812  break;
813  }
814  }
815 
816  // add the text answer from the selected option
817  if (count($resultset["answers"][$this->getId()]))
818  {
819  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
820  {
821  array_push($a_array, $answer["value"]+1);
822  if ($other)
823  {
824  array_push($a_array, $answer["textanswer"]);
825  }
826  }
827  }
828  else
829  {
830  array_push($a_array, $this->lng->txt("skipped"));
831  if ($other)
832  {
833  array_push($a_array, "");
834  }
835  }
836  }
837 
846  {
847  global $ilDB;
848 
849  $answers = array();
850 
851  $result = $ilDB->queryF("SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_finished.survey_fi = %s AND svy_answer.question_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
852  array('integer','integer'),
853  array($survey_id, $this->getId())
854  );
855  while ($row = $ilDB->fetchAssoc($result))
856  {
857  $category = $this->categories->getCategoryForScale($row["value"]+1);
858  $title = $row["value"] + 1 . " - " . $category->title;
859  if ($category->other) $title .= ": " . $row["textanswer"];
860  $answers[$row["active_fi"]] = $title;
861  }
862  return $answers;
863  }
864 
871  function importResponses($a_data)
872  {
873  foreach ($a_data as $id => $data)
874  {
875  $categorytext = "";
876  foreach ($data["material"] as $material)
877  {
878  $categorytext .= $material["text"];
879  }
880  $this->categories->addCategory(
881  $categorytext,
882  strlen($data['other']) ? $data['other'] : 0,
883  strlen($data['neutral']) ? $data['neutral'] : 0,
884  strlen($data['label']) ? $data['label'] : null,
885  strlen($data['scale']) ? $data['scale'] : null
886  );
887  }
888  }
889 
897  {
898  return TRUE;
899  }
900 
908  {
909  return array("<", "<=", "=", "<>", ">=", ">");
910  }
911 
917  public function getPreconditionOptions()
918  {
919  global $lng;
920 
921  $options = array();
922  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
923  {
924  $category = $this->categories->getCategory($i);
925  $options[$i] = ($i+1) . " - " . $category->title;
926  }
927  return $options;
928  }
929 
936  public function getPreconditionSelectValue($default = "", $title, $variable)
937  {
938  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
939  $step3 = new ilSelectInputGUI($title, $variable);
940  $options = $this->getPreconditionOptions();
941  $step3->setOptions($options);
942  $step3->setValue($default);
943  return $step3;
944  }
945 
953  function getPreconditionValueOutput($value)
954  {
955  $category = $this->categories->getCategory($value);
956  return ($value + 1) . " - " . ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
957  }
958 
967  function outChart($survey_id, $type = "")
968  {
969  if (count($this->cumulated) == 0)
970  {
971  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
973  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
974  }
975 
976  foreach ($this->cumulated["variables"] as $key => $value)
977  {
978  foreach ($value as $key2 => $value2)
979  {
980  $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
981  }
982  }
983  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
984  $b1 = new SurveyChart("bars",400,250,utf8_decode($this->getTitle()),utf8_decode($this->lng->txt("answers")),utf8_decode($this->lng->txt("users_answered")),$this->cumulated["variables"]);
985  }
986 
987  public function getCategories()
988  {
989  return $this->categories;
990  }
991 
992 }
993 ?>