ILIAS  Release_4_2_x_branch Revision 61807
 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  $neutral = $row["neutral"];
120  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
121  {
122  $this->categories->addCategory($this->lng->txt($row["title"]), 0, $neutral);
123  }
124  else
125  {
126  $this->categories->addCategory($row["title"], 0, $neutral);
127  }
128  }
129  }
130 
139  {
140  global $ilDB;
141 
142  $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",
143  array('integer'),
144  array($id)
145  );
146  if ($result->numRows() == 1)
147  {
148  return $ilDB->fetchAssoc($result);
149  }
150  else
151  {
152  return array();
153  }
154  }
155 
162  function loadFromDb($id)
163  {
164  global $ilDB;
165 
166  $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",
167  array('integer'),
168  array($id)
169  );
170  if ($result->numRows() == 1)
171  {
172  $data = $ilDB->fetchAssoc($result);
173  $this->setId($data["question_id"]);
174  $this->setTitle($data["title"]);
175  $this->label = $data['label'];
176  $this->setDescription($data["description"]);
177  $this->setObjId($data["obj_fi"]);
178  $this->setAuthor($data["author"]);
179  $this->setOwner($data["owner_fi"]);
180  include_once("./Services/RTE/classes/class.ilRTE.php");
181  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
182  $this->setObligatory($data["obligatory"]);
183  $this->setComplete($data["complete"]);
184  $this->setOriginalId($data["original_id"]);
185  $this->setOrientation($data["orientation"]);
186 
187  $this->categories->flushCategories();
188  $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",
189  array('integer'),
190  array($id)
191  );
192  if ($result->numRows() > 0)
193  {
194  while ($data = $ilDB->fetchAssoc($result))
195  {
196  $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
197  }
198  }
199  }
201  }
202 
209  function isComplete()
210  {
211  if (
212  strlen($this->getTitle()) &&
213  strlen($this->getAuthor()) &&
214  strlen($this->getQuestiontext()) &&
215  $this->categories->getCategoryCount()
216  )
217  {
218  return 1;
219  }
220  else
221  {
222  return 0;
223  }
224  }
225 
231  function saveToDb($original_id = "")
232  {
233  global $ilDB;
234 
235  $affectedRows = parent::saveToDb($original_id);
236  if ($affectedRows == 1)
237  {
238  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
239  array('integer'),
240  array($this->getId())
241  );
242  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
243  array('integer', 'text'),
244  array(
245  $this->getId(),
246  $this->getOrientation()
247  )
248  );
249 
250  $this->saveMaterial();
251  $this->saveCategoriesToDb();
252  }
253  }
254 
256  {
257  global $ilDB;
258 
259  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
260  array('integer'),
261  array($this->getId())
262  );
263 
264  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
265  {
266  $cat = $this->categories->getCategory($i);
267  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
268  $next_id = $ilDB->nextId('svy_variable');
269  $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)",
270  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
271  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
272  );
273  }
274  $this->saveCompletionStatus();
275  }
276 
283  function toXML($a_include_header = TRUE, $obligatory_state = "")
284  {
285  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
286  $a_xml_writer = new ilXmlWriter;
287  $a_xml_writer->xmlHeader();
288  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
289  $xml = $a_xml_writer->xmlDumpMem(FALSE);
290  if (!$a_include_header)
291  {
292  $pos = strpos($xml, "?>");
293  $xml = substr($xml, $pos + 2);
294  }
295  return $xml;
296  }
297 
306  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
307  {
308  $attrs = array(
309  "id" => $this->getId(),
310  "title" => $this->getTitle(),
311  "type" => $this->getQuestiontype(),
312  "obligatory" => $this->getObligatory()
313  );
314  $a_xml_writer->xmlStartTag("question", $attrs);
315 
316  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
317  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
318  if (strlen($this->label))
319  {
320  $attrs = array(
321  "label" => $this->label,
322  );
323  }
324  else
325  {
326  $attrs = array();
327  }
328  $a_xml_writer->xmlStartTag("questiontext", $attrs);
329  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
330  $a_xml_writer->xmlEndTag("questiontext");
331 
332  $a_xml_writer->xmlStartTag("responses");
333 
334  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
335  {
336  $attrs = array(
337  "id" => $i
338  );
339  if (strlen($this->categories->getCategory($i)->other)) $attrs['other'] = $this->categories->getCategory($i)->other;
340  if (strlen($this->categories->getCategory($i)->neutral)) $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
341  if (strlen($this->categories->getCategory($i)->label)) $attrs['label'] = $this->categories->getCategory($i)->label;
342  if (strlen($this->categories->getCategory($i)->scale)) $attrs['scale'] = $this->categories->getCategory($i)->scale;
343  $a_xml_writer->xmlStartTag("response_single", $attrs);
344  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
345  $a_xml_writer->xmlEndTag("response_single");
346  }
347 
348  $a_xml_writer->xmlEndTag("responses");
349 
350  if (count($this->material))
351  {
352  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
353  {
354  $attrs = array(
355  "label" => $this->material["title"]
356  );
357  $a_xml_writer->xmlStartTag("material", $attrs);
358  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
359  if (strcmp($matches[1], "") != 0)
360  {
361  $intlink = $this->material["internal_link"];
362  }
363  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
364  $a_xml_writer->xmlEndTag("material");
365  }
366  }
367 
368  $a_xml_writer->xmlStartTag("metadata");
369  $a_xml_writer->xmlStartTag("metadatafield");
370  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
371  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
372  $a_xml_writer->xmlEndTag("metadatafield");
373  $a_xml_writer->xmlEndTag("metadata");
374 
375  $a_xml_writer->xmlEndTag("question");
376  }
377 
386  function importAdditionalMetadata($a_meta)
387  {
388  foreach ($a_meta as $key => $value)
389  {
390  switch ($value["label"])
391  {
392  case "orientation":
393  $this->setOrientation($value["entry"]);
394  break;
395  }
396  }
397  }
398 
406  function addStandardNumbers($lower_limit, $upper_limit)
407  {
408  for ($i = $lower_limit; $i <= $upper_limit; $i++)
409  {
410  $this->categories->addCategory($i);
411  }
412  }
413 
421  function savePhrase($title)
422  {
423  global $ilUser;
424  global $ilDB;
425 
426  $next_id = $ilDB->nextId('svy_phrase');
427  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
428  array('integer','text','text','integer','integer'),
429  array($next_id, $title, 1, $ilUser->getId(), time())
430  );
431  $phrase_id = $next_id;
432 
433  $counter = 1;
434  foreach ($_SESSION['save_phrase_data'] as $data)
435  {
436  $next_id = $ilDB->nextId('svy_category');
437  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
438  array('integer','text','text','integer','integer','text'),
439  array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
440  );
441  $category_id = $next_id;
442  $next_id = $ilDB->nextId('svy_phrase_cat');
443  $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)",
444  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
445  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
446  );
447  $counter++;
448  }
449  }
450 
457  function getQuestionType()
458  {
459  return "SurveySingleChoiceQuestion";
460  }
461 
469  {
470  return "svy_qst_sc";
471  }
472 
479  function &getWorkingDataFromUserInput($post_data)
480  {
481  $entered_value = $post_data[$this->getId() . "_value"];
482  $data = array();
483  if (strlen($entered_value))
484  {
485  array_push($data, array("value" => $entered_value, "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other']));
486  }
487  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
488  {
489  $cat = $this->categories->getCategory($i);
490  if ($cat->other)
491  {
492  if ($i != $entered_value)
493  {
494  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
495  {
496  array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
497  }
498  }
499  }
500  }
501  return $data;
502  }
503 
513  function checkUserInput($post_data, $survey_id)
514  {
515  $entered_value = $post_data[$this->getId() . "_value"];
516 
517  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
518 
519  if (strlen($entered_value) == 0) return $this->lng->txt("question_not_checked");
520 
521  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
522  {
523  $cat = $this->categories->getCategory($i);
524  if ($cat->other)
525  {
526  if ($i == $entered_value)
527  {
528  if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"]))
529  {
530  return $this->lng->txt("question_mr_no_other_answer");
531  }
532  }
533  else
534  {
535  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
536  {
537  return $this->lng->txt("question_sr_no_other_answer_checked");
538  }
539  }
540  }
541  }
542 
543  return "";
544  }
545 
551  public function saveRandomData($active_id)
552  {
553  global $ilDB;
554  // single response
555  $category = rand(0, $this->categories->getCategoryCount()-1);
556  $cat = $this->categories->getCategory($category);
557  $next_id = $ilDB->nextId('svy_answer');
558  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
559  array('integer','integer','integer','float','text','integer'),
560  array($next_id, $this->getId(), $active_id, $category, ($cat->other) ? "Random Data" : null, time())
561  );
562  }
563 
564  function saveUserInput($post_data, $active_id, $a_return = false)
565  {
566  global $ilDB;
567 
568  $entered_value = $post_data[$this->getId() . "_value"];
569 
570  if($a_return)
571  {
572  return array(array("value"=>$entered_value,
573  "textanswer"=>$post_data[$this->getId() . "_" . $entered_value . "_other"]));
574  }
575  if (strlen($entered_value) == 0) return;
576 
577  $next_id = $ilDB->nextId('svy_answer');
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  }
583 
584  function &getCumulatedResults($survey_id, $nr_of_users)
585  {
586  global $ilDB;
587 
588  $question_id = $this->getId();
589 
590  $result_array = array();
591  $cumulated = array();
592 
593  $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",
594  array('integer', 'integer'),
595  array($question_id, $survey_id)
596  );
597 
598  while ($row = $ilDB->fetchAssoc($result))
599  {
600  $cumulated[$row["value"]]++;
601 
602  // add text value to result array
603  if ($row["textanswer"])
604  {
605  $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
606  }
607  }
608  // sort textanswers by value
609  if (is_array($result_array["textanswers"]))
610  {
611  ksort($result_array["textanswers"], SORT_NUMERIC);
612  }
613  asort($cumulated, SORT_NUMERIC);
614  end($cumulated);
615  $numrows = $result->numRows();
616  $result_array["USERS_ANSWERED"] = $result->numRows();
617  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
618 
619  $prefix = "";
620  if (strcmp(key($cumulated), "") != 0)
621  {
622  $prefix = (key($cumulated)+1) . " - ";
623  }
624  $category = $this->categories->getCategoryForScale(key($cumulated)+1);
625  $result_array["MODE"] = $prefix . $category->title;
626  $result_array["MODE_VALUE"] = key($cumulated)+1;
627  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
628  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
629  {
630  $cat = $this->categories->getCategory($key);
631  $percentage = 0;
632  if ($numrows > 0)
633  {
634  $percentage = (float)((int)$cumulated[$cat->scale-1]/$numrows);
635  }
636  if ($cat->other)
637  {
638  $result_array["variables"][$key] = array("title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt('other_answer'), "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
639  }
640  else
641  {
642  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
643  }
644  }
645  ksort($cumulated, SORT_NUMERIC);
646  $median = array();
647  $total = 0;
648  foreach ($cumulated as $value => $key)
649  {
650  $total += $key;
651  for ($i = 0; $i < $key; $i++)
652  {
653  array_push($median, $value+1);
654  }
655  }
656  if ($total > 0)
657  {
658  if (($total % 2) == 0)
659  {
660  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
661  if (round($median_value) != $median_value)
662  {
663  $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 . ")";
664  }
665  }
666  else
667  {
668  $median_value = $median[(($total+1)/2)-1];
669  }
670  }
671  else
672  {
673  $median_value = "";
674  }
675  $result_array["ARITHMETIC_MEAN"] = "";
676  $result_array["MEDIAN"] = $median_value;
677  $result_array["QUESTION_TYPE"] = "SurveySingleChoiceQuestion";
678  return $result_array;
679  }
680 
690  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
691  {
692  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
693  $worksheet =& $workbook->addWorksheet();
694  $rowcounter = 0;
695  switch ($export_label)
696  {
697  case 'label_only':
698  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
699  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
700  break;
701  case 'title_only':
702  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
703  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
704  break;
705  default:
706  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
707  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
708  $rowcounter++;
709  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
710  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
711  break;
712  }
713  $rowcounter++;
714  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
715  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
716  $rowcounter++;
717  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
718  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
719  $rowcounter++;
720  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
721  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
722  $rowcounter++;
723  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
724  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
725  $rowcounter++;
726 
727  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
728  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
729  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
730  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
731  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
732  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
733  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
734  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
735  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
736  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
737  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
738  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
739  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
740  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
741 
742  foreach ($eval_data["variables"] as $key => $value)
743  {
744  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
745  $category = $this->categories->getCategory($key);
746  $worksheet->write($rowcounter, 2, $category->scale);
747  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
748  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
749  }
750 
751  // add text answers to detailed results
752  if (is_array($eval_data["textanswers"]))
753  {
754  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $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("answer")), $format_title);
757 
758  foreach ($eval_data["textanswers"] as $key => $answers)
759  {
760  $title = $eval_data["variables"][$key]["title"];
761  foreach ($answers as $answer)
762  {
763  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
764  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
765  }
766  }
767  }
768  }
769 
778  function addUserSpecificResultsExportTitles(&$a_array, $a_export_label = "")
779  {
780  // add label dependent title
781  switch($a_export_label)
782  {
783  case "label_only":
784  $title = $this->label ? $this->label : $this->title;
785  break;
786 
787  case "title_only":
789  break;
790 
791  default:
792  $title = $this->label ? $this->title.' - '.$this->label : $this->title;
793  break;
794  }
795  array_push($a_array, $title);
796 
797  // optionally add header for text answer
798  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
799  {
800  $cat = $this->categories->getCategory($i);
801  if ($cat->other)
802  {
803  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
804  break;
805  }
806  }
807  }
808 
816  function addUserSpecificResultsData(&$a_array, &$resultset)
817  {
818  // check if text answer column is needed
819  $other = false;
820  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
821  {
822  $cat = $this->categories->getCategory($i);
823  if ($cat->other)
824  {
825  $other = true;
826  break;
827  }
828  }
829 
830  if (count($resultset["answers"][$this->getId()]))
831  {
832  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
833  {
834  array_push($a_array, $answer["value"]+1);
835 
836  // add the text answer from the selected option
837  if ($other)
838  {
839  array_push($a_array, $answer["textanswer"]);
840  }
841  }
842  }
843  else
844  {
845  array_push($a_array, $this->lng->txt("skipped"));
846 
847  if ($other)
848  {
849  array_push($a_array, "");
850  }
851  }
852  }
853 
862  {
863  global $ilDB;
864 
865  $answers = array();
866 
867  $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",
868  array('integer','integer'),
869  array($survey_id, $this->getId())
870  );
871  while ($row = $ilDB->fetchAssoc($result))
872  {
873  $category = $this->categories->getCategoryForScale($row["value"]+1);
874  $title = $row["value"] + 1 . " - " . $category->title;
875  if ($category->other) $title .= ": " . $row["textanswer"];
876  $answers[$row["active_fi"]] = $title;
877  }
878  return $answers;
879  }
880 
887  function importResponses($a_data)
888  {
889  foreach ($a_data as $id => $data)
890  {
891  $categorytext = "";
892  foreach ($data["material"] as $material)
893  {
894  $categorytext .= $material["text"];
895  }
896  $this->categories->addCategory(
897  $categorytext,
898  strlen($data['other']) ? $data['other'] : 0,
899  strlen($data['neutral']) ? $data['neutral'] : 0,
900  strlen($data['label']) ? $data['label'] : null,
901  strlen($data['scale']) ? $data['scale'] : null
902  );
903  }
904  }
905 
913  {
914  return TRUE;
915  }
916 
924  {
925  return array("<", "<=", "=", "<>", ">=", ">");
926  }
927 
933  public function getPreconditionOptions()
934  {
935  global $lng;
936 
937  $options = array();
938  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
939  {
940  $category = $this->categories->getCategory($i);
941  $options[$category->scale-1] = $category->scale . " - " . $category->title;
942  }
943  return $options;
944  }
945 
952  public function getPreconditionSelectValue($default = "", $title, $variable)
953  {
954  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
955  $step3 = new ilSelectInputGUI($title, $variable);
956  $options = $this->getPreconditionOptions();
957  $step3->setOptions($options);
958  $step3->setValue($default);
959  return $step3;
960  }
961 
969  function getPreconditionValueOutput($value)
970  {
971  $category = $this->categories->getCategory($value);
972  return ($value + 1) . " - " . ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
973  }
974 
975  public function getCategories()
976  {
977  return $this->categories;
978  }
979 
980 }
981 ?>