ILIAS  Release_4_1_x_branch Revision 61804
 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 
677  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
678  {
679  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
680  $worksheet =& $workbook->addWorksheet();
681  $rowcounter = 0;
682  switch ($export_label)
683  {
684  case 'label_only':
685  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
686  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
687  break;
688  case 'title_only':
689  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
690  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
691  break;
692  default:
693  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
694  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
695  $rowcounter++;
696  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
697  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
698  break;
699  }
700  $rowcounter++;
701  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
702  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
703  $rowcounter++;
704  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
705  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
706  $rowcounter++;
707  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
708  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
709  $rowcounter++;
710  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
711  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
712  $rowcounter++;
713 
714  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
715  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
716  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
717  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
718  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
719  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
720  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
721  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
722  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
723  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
724  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
725  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
726  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
727  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
728 
729  foreach ($eval_data["variables"] as $key => $value)
730  {
731  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
732  $category = $this->categories->getCategory($key);
733  $worksheet->write($rowcounter, 2, $category->scale);
734  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
735  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
736  }
737 
738  // add text answers to detailed results
739  if (is_array($eval_data["textanswers"]))
740  {
741  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
742  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
743  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
744 
745  foreach ($eval_data["textanswers"] as $key => $answers)
746  {
747  $title = $eval_data["variables"][$key]["title"];
748  foreach ($answers as $answer)
749  {
750  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
751  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
752  }
753  }
754  }
755  }
756 
765  function addUserSpecificResultsExportTitles(&$a_array, $a_export_label = "")
766  {
767  // add label dependent title
768  switch($a_export_label)
769  {
770  case "label_only":
771  $title = $this->label ? $this->label : $this->title;
772  break;
773 
774  case "title_only":
776  break;
777 
778  default:
779  $title = $this->label ? $this->title.' - '.$this->label : $this->title;
780  break;
781  }
782  array_push($a_array, $title);
783 
784  // optionally add header for text answer
785  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
786  {
787  $cat = $this->categories->getCategory($i);
788  if ($cat->other)
789  {
790  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
791  break;
792  }
793  }
794  }
795 
803  function addUserSpecificResultsData(&$a_array, &$resultset)
804  {
805  // check if text answer column is needed
806  $other = false;
807  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
808  {
809  $cat = $this->categories->getCategory($i);
810  if ($cat->other)
811  {
812  $other = true;
813  break;
814  }
815  }
816 
817  // add the text answer from the selected option
818  if (count($resultset["answers"][$this->getId()]))
819  {
820  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
821  {
822  array_push($a_array, $answer["value"]+1);
823  if ($other)
824  {
825  array_push($a_array, $answer["textanswer"]);
826  }
827  }
828  }
829  else
830  {
831  array_push($a_array, $this->lng->txt("skipped"));
832  if ($other)
833  {
834  array_push($a_array, "");
835  }
836  }
837  }
838 
847  {
848  global $ilDB;
849 
850  $answers = array();
851 
852  $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",
853  array('integer','integer'),
854  array($survey_id, $this->getId())
855  );
856  while ($row = $ilDB->fetchAssoc($result))
857  {
858  $category = $this->categories->getCategoryForScale($row["value"]+1);
859  $title = $row["value"] + 1 . " - " . $category->title;
860  if ($category->other) $title .= ": " . $row["textanswer"];
861  $answers[$row["active_fi"]] = $title;
862  }
863  return $answers;
864  }
865 
872  function importResponses($a_data)
873  {
874  foreach ($a_data as $id => $data)
875  {
876  $categorytext = "";
877  foreach ($data["material"] as $material)
878  {
879  $categorytext .= $material["text"];
880  }
881  $this->categories->addCategory(
882  $categorytext,
883  strlen($data['other']) ? $data['other'] : 0,
884  strlen($data['neutral']) ? $data['neutral'] : 0,
885  strlen($data['label']) ? $data['label'] : null,
886  strlen($data['scale']) ? $data['scale'] : null
887  );
888  }
889  }
890 
898  {
899  return TRUE;
900  }
901 
909  {
910  return array("<", "<=", "=", "<>", ">=", ">");
911  }
912 
918  public function getPreconditionOptions()
919  {
920  global $lng;
921 
922  $options = array();
923  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
924  {
925  $category = $this->categories->getCategory($i);
926  $options[$i] = ($i+1) . " - " . $category->title;
927  }
928  return $options;
929  }
930 
937  public function getPreconditionSelectValue($default = "", $title, $variable)
938  {
939  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
940  $step3 = new ilSelectInputGUI($title, $variable);
941  $options = $this->getPreconditionOptions();
942  $step3->setOptions($options);
943  $step3->setValue($default);
944  return $step3;
945  }
946 
954  function getPreconditionValueOutput($value)
955  {
956  $category = $this->categories->getCategory($value);
957  return ($value + 1) . " - " . ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
958  }
959 
968  function outChart($survey_id, $type = "")
969  {
970  if (count($this->cumulated) == 0)
971  {
972  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
974  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
975  }
976 
977  foreach ($this->cumulated["variables"] as $key => $value)
978  {
979  foreach ($value as $key2 => $value2)
980  {
981  $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
982  }
983  }
984  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
985  $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"]);
986  }
987 
988  public function getCategories()
989  {
990  return $this->categories;
991  }
992 
993 }
994 ?>