ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMultipleChoiceQuestion.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 
57  $title = "",
58  $description = "",
59  $author = "",
60  $questiontext = "",
61  $owner = -1,
62  $orientation = 0
63  )
64  {
66  $this->orientation = $orientation;
67  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
68  $this->categories = new SurveyCategories();
69  }
70 
79  {
80  global $ilDB;
81 
82  $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",
83  array('integer'),
84  array($id)
85  );
86  if ($result->numRows() == 1)
87  {
88  return $ilDB->fetchAssoc($result);
89  }
90  else
91  {
92  return array();
93  }
94  }
95 
102  function loadFromDb($id)
103  {
104  global $ilDB;
105 
106  $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",
107  array('integer'),
108  array($id)
109  );
110  if ($result->numRows() == 1)
111  {
112  $data = $ilDB->fetchAssoc($result);
113  $this->setId($data["question_id"]);
114  $this->setTitle($data["title"]);
115  $this->label = $data['label'];
116  $this->setDescription($data["description"]);
117  $this->setObjId($data["obj_fi"]);
118  $this->setAuthor($data["author"]);
119  $this->setOwner($data["owner_fi"]);
120  include_once("./Services/RTE/classes/class.ilRTE.php");
121  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
122  $this->setObligatory($data["obligatory"]);
123  $this->setComplete($data["complete"]);
124  $this->setOriginalId($data["original_id"]);
125  $this->setOrientation($data["orientation"]);
126  $this->use_min_answers = ($data['use_min_answers']) ? true : false;
127  $this->nr_min_answers = $data['nr_min_answers'];
128  $this->nr_max_answers = $data['nr_max_answers'];
129 
130  $this->categories->flushCategories();
131  $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",
132  array('integer'),
133  array($id)
134  );
135  if ($result->numRows() > 0)
136  {
137  while ($data = $ilDB->fetchAssoc($result))
138  {
139  $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
140  }
141  }
142  }
144  }
145 
152  function isComplete()
153  {
154  if (
155  strlen($this->getTitle()) &&
156  strlen($this->getAuthor()) &&
157  strlen($this->getQuestiontext()) &&
158  $this->categories->getCategoryCount()
159  )
160  {
161  return 1;
162  }
163  else
164  {
165  return 0;
166  }
167  }
168 
174  function saveToDb($original_id = "")
175  {
176  global $ilDB;
177 
178  $affectedRows = parent::saveToDb($original_id);
179  if ($affectedRows == 1)
180  {
181  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
182  array('integer'),
183  array($this->getId())
184  );
185  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
186  array('integer', 'text', 'integer', 'integer', 'integer'),
187  array(
188  $this->getId(),
189  $this->getOrientation(),
190  ($this->use_min_answers) ? 1 : 0,
191  ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
192  ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
193  )
194  );
195 
196  // saving material uris in the database
197  $this->saveMaterial();
198  $this->saveCategoriesToDb();
199  }
200  }
201 
203  {
204  global $ilDB;
205 
206  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
207  array('integer'),
208  array($this->getId())
209  );
210 
211  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
212  {
213  $cat = $this->categories->getCategory($i);
214  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
215  $next_id = $ilDB->nextId('svy_variable');
216  $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)",
217  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
218  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
219  );
220  }
221  $this->saveCompletionStatus();
222  }
223 
230  function toXML($a_include_header = TRUE, $obligatory_state = "")
231  {
232  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
233  $a_xml_writer = new ilXmlWriter;
234  $a_xml_writer->xmlHeader();
235  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
236  $xml = $a_xml_writer->xmlDumpMem(FALSE);
237  if (!$a_include_header)
238  {
239  $pos = strpos($xml, "?>");
240  $xml = substr($xml, $pos + 2);
241  }
242  return $xml;
243  }
244 
253  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
254  {
255  $attrs = array(
256  "id" => $this->getId(),
257  "title" => $this->getTitle(),
258  "type" => $this->getQuestiontype(),
259  "obligatory" => $this->getObligatory()
260  );
261  $a_xml_writer->xmlStartTag("question", $attrs);
262 
263  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
264  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
265  if (strlen($this->label))
266  {
267  $attrs = array(
268  "label" => $this->label,
269  );
270  }
271  else
272  {
273  $attrs = array();
274  }
275  $a_xml_writer->xmlStartTag("questiontext", $attrs);
276  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
277  $a_xml_writer->xmlEndTag("questiontext");
278 
279  $a_xml_writer->xmlStartTag("responses");
280 
281  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
282  {
283  $attrs = array(
284  "id" => $i
285  );
286  if (strlen($this->categories->getCategory($i)->other)) $attrs['other'] = $this->categories->getCategory($i)->other;
287  if (strlen($this->categories->getCategory($i)->neutral)) $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
288  if (strlen($this->categories->getCategory($i)->label)) $attrs['label'] = $this->categories->getCategory($i)->label;
289  if (strlen($this->categories->getCategory($i)->scale)) $attrs['scale'] = $this->categories->getCategory($i)->scale;
290  $a_xml_writer->xmlStartTag("response_multiple", $attrs);
291  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
292  $a_xml_writer->xmlEndTag("response_multiple");
293  }
294 
295  $a_xml_writer->xmlEndTag("responses");
296 
297  if (count($this->material))
298  {
299  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
300  {
301  $attrs = array(
302  "label" => $this->material["title"]
303  );
304  $a_xml_writer->xmlStartTag("material", $attrs);
305  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
306  if (strcmp($matches[1], "") != 0)
307  {
308  $intlink = $this->material["internal_link"];
309  }
310  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
311  $a_xml_writer->xmlEndTag("material");
312  }
313  }
314 
315  $a_xml_writer->xmlStartTag("metadata");
316  $a_xml_writer->xmlStartTag("metadatafield");
317  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
318  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
319  $a_xml_writer->xmlEndTag("metadatafield");
320  $a_xml_writer->xmlStartTag("metadatafield");
321  $a_xml_writer->xmlElement("fieldlabel", NULL, "use_min_answers");
322  $a_xml_writer->xmlElement("fieldentry", NULL, $this->use_min_answers);
323  $a_xml_writer->xmlEndTag("metadatafield");
324  $a_xml_writer->xmlStartTag("metadatafield");
325  $a_xml_writer->xmlElement("fieldlabel", NULL, "nr_min_answers");
326  $a_xml_writer->xmlElement("fieldentry", NULL, $this->nr_min_answers);
327  $a_xml_writer->xmlEndTag("metadatafield");
328  $a_xml_writer->xmlStartTag("metadatafield");
329  $a_xml_writer->xmlElement("fieldlabel", NULL, "nr_max_answers");
330  $a_xml_writer->xmlElement("fieldentry", NULL, $this->nr_max_answers);
331  $a_xml_writer->xmlEndTag("metadatafield");
332  $a_xml_writer->xmlEndTag("metadata");
333 
334  $a_xml_writer->xmlEndTag("question");
335  }
336 
343  function getQuestionType()
344  {
345  return "SurveyMultipleChoiceQuestion";
346  }
347 
355  {
356  return "svy_qst_mc";
357  }
358 
365  function &getWorkingDataFromUserInput($post_data)
366  {
367  $entered_value = $post_data[$this->getId() . "_value"];
368  $data = array();
369  if (is_array($entered_value))
370  {
371  foreach ($entered_value as $idx => $value)
372  {
373  array_push($data, array("value" => $value, "textanswer" => $post_data[$this->getId() . '_' . $value . '_other']));
374  }
375  }
376  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
377  {
378  $cat = $this->categories->getCategory($i);
379  if ($cat->other)
380  {
381  if (!in_array($i, $entered_value))
382  {
383  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
384  {
385  array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
386  }
387  }
388  }
389  }
390  return $data;
391  }
392 
402  function checkUserInput($post_data, $survey_id)
403  {
404  $entered_value = $post_data[$this->getId() . "_value"];
405  if (!$this->getObligatory($survey_id) && count($entered_value) == 0) return "";
406 
407  if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) != $this->nr_max_answers)
408  {
409  return sprintf($this->lng->txt("err_no_exact_answers"), $this->nr_min_answers);
410  }
411  if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers)
412  {
413  return sprintf($this->lng->txt("err_no_min_answers"), $this->nr_min_answers);
414  }
415  if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers)
416  {
417  return sprintf($this->lng->txt("err_no_max_answers"), $this->nr_max_answers);
418  }
419  if (!is_array($entered_value))
420  {
421  return $this->lng->txt("question_mr_not_checked");
422  }
423  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
424  {
425  $cat = $this->categories->getCategory($i);
426  if ($cat->other)
427  {
428  if (in_array($i, $entered_value))
429  {
430  if (array_key_exists($this->getId() . "_" . $i . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $i . "_other"]))
431  {
432  return $this->lng->txt("question_mr_no_other_answer");
433  }
434  }
435  else
436  {
437  if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
438  {
439  return $this->lng->txt("question_mr_no_other_answer_checked");
440  }
441  }
442  }
443  }
444  return "";
445  }
446 
452  public function saveRandomData($active_id)
453  {
454  global $ilDB;
455  // multiple responses
456  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
457  {
458  if (rand(0,1))
459  {
460  $cat = $this->categories->getCategory($i);
461  $next_id = $ilDB->nextId('svy_answer');
462  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
463  array('integer','integer','integer','float','text','integer'),
464  array($next_id, $this->getId(), $active_id, $i, ($cat->other) ? "Random Data" : null, time())
465  );
466  }
467  }
468  }
469 
470  function saveUserInput($post_data, $active_id, $a_return = false)
471  {
472  global $ilDB;
473 
474  if($a_return)
475  {
476  $return_data = array();
477  }
478  if (is_array($post_data[$this->getId() . "_value"]))
479  {
480  foreach ($post_data[$this->getId() . "_value"] as $entered_value)
481  {
482  if (strlen($entered_value) > 0)
483  {
484  if(!$a_return)
485  {
486  $next_id = $ilDB->nextId('svy_answer');
487  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
488  array('integer','integer','integer','float','text','integer'),
489  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())
490  );
491  }
492  else
493  {
494  $return_data[] = array("value"=>$entered_value,
495  "textanswer"=>$post_data[$this->getId() . "_" . $entered_value . "_other"]);
496  }
497  }
498  }
499  }
500  if($a_return)
501  {
502  return $return_data;
503  }
504  }
505 
506  function &getCumulatedResults($survey_id, $nr_of_users)
507  {
508  global $ilDB;
509 
510  $question_id = $this->getId();
511 
512  $result_array = array();
513  $cumulated = array();
514 
515  $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",
516  array('integer', 'integer'),
517  array($question_id, $survey_id)
518  );
519  $numrows = $result->numRows();
520 
521  // count the answers for every answer value
522  $textanswers = array();
523  while ($row = $ilDB->fetchAssoc($result))
524  {
525  $cumulated[$row["value"]]++;
526 
527  // add text value to result array
528  if ($row["textanswer"])
529  {
530  $textanswers[$row["value"]][] = $row["textanswer"];
531  }
532  }
533  // sort textanswers by value
534  if (is_array($textanswers))
535  {
536  ksort($textanswers, SORT_NUMERIC);
537  }
538  asort($cumulated, SORT_NUMERIC);
539  end($cumulated);
540 
541  $mcmr_result = $ilDB->queryF("SELECT svy_answer.answer_id, svy_answer.question_fi, svy_answer.active_fi 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",
542  array('integer', 'integer'),
543  array($question_id, $survey_id)
544  );
545  $found = array();
546  while ($row = $ilDB->fetchAssoc($mcmr_result))
547  {
548  $found[$row["question_fi"] . "_" . $row["active_fi"]] = 1;
549  }
550  $result_array["USERS_ANSWERED"] = count($found);
551  $result_array["USERS_SKIPPED"] = $nr_of_users - count($found);
552  $numrows = count($found);
553 
554  $result_array["MEDIAN"] = "";
555  $result_array["ARITHMETIC_MEAN"] = "";
556  $prefix = "";
557  if (strcmp(key($cumulated), "") != 0)
558  {
559  $prefix = (key($cumulated)+1) . " - ";
560  }
561  $category = $this->categories->getCategoryForScale(key($cumulated)+1);
562  $result_array["MODE"] = $prefix . $category->title;
563  $result_array["MODE_VALUE"] = key($cumulated)+1;
564  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
565  $result_array["QUESTION_TYPE"] = "SurveyMultipleChoiceQuestion";
566  $maxvalues = 0;
567  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
568  {
569  $cat = $this->categories->getCategory($key);
570  $maxvalues += $cumulated[$cat->scale-1];
571  }
572  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
573  {
574  $cat = $this->categories->getCategory($key);
575  $percentage = 0;
576  if ($numrows > 0)
577  {
578  if ($maxvalues > 0)
579  {
580  $percentage = ($maxvalues > 0) ? (float)((int)$cumulated[$cat->scale-1]/$maxvalues) : 0;
581  }
582  }
583  if(isset($textanswers[$cat->scale-1]))
584  {
585  // #12138
586  $result_array["textanswers"][$key] = $textanswers[$cat->scale-1];
587  }
588  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
589  }
590  return $result_array;
591  }
592 
602  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
603  {
604  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
605  $worksheet =& $workbook->addWorksheet();
606  $rowcounter = 0;
607  switch ($export_label)
608  {
609  case 'label_only':
610  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
611  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
612  break;
613  case 'title_only':
614  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
615  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
616  break;
617  default:
618  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
619  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
620  $rowcounter++;
621  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
622  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
623  break;
624  }
625  $rowcounter++;
626  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
627  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
628  $rowcounter++;
629  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
630  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
631  $rowcounter++;
632  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
633  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
634  $rowcounter++;
635  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
636  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
637  $rowcounter++;
638 
639  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
640  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
641  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
642  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
643  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
644  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
645  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
646  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
647  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
648  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
649  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
650  foreach ($eval_data["variables"] as $key => $value)
651  {
652  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
653  $category = $this->categories->getCategory($key);
654  $worksheet->write($rowcounter, 2, $category->scale);
655  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
656  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
657  }
658 
659  // add text answers to detailed results
660  if (is_array($eval_data["textanswers"]))
661  {
662  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
663  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
664  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
665 
666  foreach ($eval_data["textanswers"] as $key => $answers)
667  {
668  $title = $eval_data["variables"][$key]["title"];
669  foreach ($answers as $answer)
670  {
671  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
672  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
673  }
674  }
675  }
676  }
677 
684  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
685  {
686  parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
687 
688  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
689  {
690  $category = $this->categories->getCategory($index);
691  $title = $category->title;
692 
693  if(!$a_use_label || $a_substitute)
694  {
695  array_push($a_array, $title);
696  }
697  else
698  {
699  array_push($a_array, "");
700  }
701 
702  // optionally add headers for text answers
703  if ($category->other)
704  {
705  if(!$a_use_label || $a_substitute)
706  {
707  array_push($a_array, $title . " - ". $this->lng->txt("other"));
708  }
709  else
710  {
711  array_push($a_array, "");
712  }
713  }
714  }
715  }
716 
724  function addUserSpecificResultsData(&$a_array, &$resultset)
725  {
726  if (count($resultset["answers"][$this->getId()]))
727  {
728  array_push($a_array, "");
729  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
730  {
731  $category = $this->categories->getCategory($index);
732  $incoming_value = $category->scale ? $category->scale-1 : $index;
733 
734  $found = 0;
735  $textanswer = "";
736  foreach ($resultset["answers"][$this->getId()] as $answerdata)
737  {
738  if (strcmp($incoming_value, $answerdata["value"]) == 0)
739  {
740  $found = $answerdata["value"]+1;
741  $textanswer = $answerdata["textanswer"];
742  }
743  }
744  if ($found)
745  {
746  array_push($a_array, $found);
747  }
748  else
749  {
750  array_push($a_array, "0");
751  }
752  if ($category->other)
753  {
754  array_push($a_array, $textanswer);
755  }
756  }
757  }
758  else
759  {
760  array_push($a_array, $this->lng->txt("skipped"));
761  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
762  {
763  array_push($a_array, "");
764 
765  // add empty text answers for skipped question
766  $category = $this->categories->getCategory($index);
767  if ($category->other)
768  {
769  array_push($a_array, "");
770  }
771  }
772  }
773  }
774 
783  {
784  global $ilDB;
785 
786  $answers = array();
787 
788  $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",
789  array('integer', 'integer'),
790  array($survey_id, $this->getId())
791  );
792  while ($row = $ilDB->fetchAssoc($result))
793  {
794  $category = $this->categories->getCategoryForScale($row["value"]+1);
795  if (!is_array($answers[$row["active_fi"]]))
796  {
797  $answers[$row["active_fi"]] = array();
798  }
799  $title = $row["value"] + 1 . " - " . $category->title;
800  if ($category->other) $title .= ": " . $row["textanswer"];
801  $catindex = $this->categories->getIndex($category);
802  if ($catindex !== null)
803  {
804  $answers[$row["active_fi"]][$catindex] = $title;
805  }
806  else
807  {
808  array_push($answers[$row["active_fi"]], $title);
809  }
810  ksort($answers[$row["active_fi"]], SORT_NUMERIC);
811  }
812  return $answers;
813  }
814 
823  function importAdditionalMetadata($a_meta)
824  {
825  foreach ($a_meta as $key => $value)
826  {
827  switch ($value["label"])
828  {
829  case "orientation":
830  $this->setOrientation($value["entry"]);
831  break;
832  case "use_min_answers":
833  $this->use_min_answers = $value["entry"];
834  break;
835  case "nr_min_answers":
836  $this->nr_min_answers = $value["entry"];
837  break;
838  case "nr_max_answers":
839  $this->nr_max_answers = $value["entry"];
840  break;
841  }
842  }
843  }
844 
851  function importResponses($a_data)
852  {
853  foreach ($a_data as $id => $data)
854  {
855  $categorytext = "";
856  foreach ($data["material"] as $material)
857  {
858  $categorytext .= $material["text"];
859  }
860  $this->categories->addCategory(
861  $categorytext,
862  strlen($data['other']) ? $data['other'] : 0,
863  strlen($data['neutral']) ? $data['neutral'] : 0,
864  strlen($data['label']) ? $data['label'] : null,
865  strlen($data['scale']) ? $data['scale'] : null
866  );
867  }
868  }
869 
877  {
878  return TRUE;
879  }
880 
888  {
889  return array("=", "<>");
890  }
891 
897  public function getPreconditionOptions()
898  {
899  global $lng;
900 
901  $options = array();
902  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
903  {
904  $category = $this->categories->getCategory($i);
905  $options[$category->scale-1] = $category->scale . " - " . $category->title;
906  }
907  return $options;
908  }
909 
916  public function getPreconditionSelectValue($default = "", $title, $variable)
917  {
918  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
919  $step3 = new ilSelectInputGUI($title, $variable);
920  $options = $this->getPreconditionOptions();
921  $step3->setOptions($options);
922  $step3->setValue($default);
923  return $step3;
924  }
925 
933  function getPreconditionValueOutput($value)
934  {
935  $category = $this->categories->getCategory($value);
936  return ($value + 1) . " - " . ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
937  }
938 
939  public function getCategories()
940  {
941  return $this->categories;
942  }
943 
944 }
945 ?>