ILIAS  Release_4_2_x_branch Revision 61807
 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  while ($row = $ilDB->fetchAssoc($result))
523  {
524  $cumulated[$row["value"]]++;
525 
526  // add text value to result array
527  if ($row["textanswer"])
528  {
529  $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
530  }
531  }
532  // sort textanswers by value
533  if (is_array($result_array["textanswers"]))
534  {
535  ksort($result_array["textanswers"], SORT_NUMERIC);
536  }
537  asort($cumulated, SORT_NUMERIC);
538  end($cumulated);
539 
540  $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",
541  array('integer', 'integer'),
542  array($question_id, $survey_id)
543  );
544  $found = array();
545  while ($row = $ilDB->fetchAssoc($mcmr_result))
546  {
547  $found[$row["question_fi"] . "_" . $row["active_fi"]] = 1;
548  }
549  $result_array["USERS_ANSWERED"] = count($found);
550  $result_array["USERS_SKIPPED"] = $nr_of_users - count($found);
551  $numrows = count($found);
552 
553  $result_array["MEDIAN"] = "";
554  $result_array["ARITHMETIC_MEAN"] = "";
555  $prefix = "";
556  if (strcmp(key($cumulated), "") != 0)
557  {
558  $prefix = (key($cumulated)+1) . " - ";
559  }
560  $category = $this->categories->getCategoryForScale(key($cumulated)+1);
561  $result_array["MODE"] = $prefix . $category->title;
562  $result_array["MODE_VALUE"] = key($cumulated)+1;
563  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
564  $result_array["QUESTION_TYPE"] = "SurveyMultipleChoiceQuestion";
565  $maxvalues = 0;
566  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
567  {
568  $cat = $this->categories->getCategory($key);
569  $maxvalues += $cumulated[$cat->scale-1];
570  }
571  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
572  {
573  $cat = $this->categories->getCategory($key);
574  $percentage = 0;
575  if ($numrows > 0)
576  {
577  if ($maxvalues > 0)
578  {
579  $percentage = ($maxvalues > 0) ? (float)((int)$cumulated[$cat->scale-1]/$maxvalues) : 0;
580  }
581  }
582  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
583  }
584  return $result_array;
585  }
586 
596  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
597  {
598  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
599  $worksheet =& $workbook->addWorksheet();
600  $rowcounter = 0;
601  switch ($export_label)
602  {
603  case 'label_only':
604  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
605  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
606  break;
607  case 'title_only':
608  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
609  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
610  break;
611  default:
612  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
613  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
614  $rowcounter++;
615  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
616  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
617  break;
618  }
619  $rowcounter++;
620  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
621  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
622  $rowcounter++;
623  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
624  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
625  $rowcounter++;
626  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
627  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
628  $rowcounter++;
629  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
630  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
631  $rowcounter++;
632 
633  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
634  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
635  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
636  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
637  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
638  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
639  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
640  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
641  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
642  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
643  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
644  foreach ($eval_data["variables"] as $key => $value)
645  {
646  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
647  $category = $this->categories->getCategory($key);
648  $worksheet->write($rowcounter, 2, $category->scale);
649  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
650  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
651  }
652 
653  // add text answers to detailed results
654  if (is_array($eval_data["textanswers"]))
655  {
656  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
657  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
658  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
659 
660  foreach ($eval_data["textanswers"] as $key => $answers)
661  {
662  $title = $eval_data["variables"][$key]["title"];
663  foreach ($answers as $answer)
664  {
665  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
666  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
667  }
668  }
669  }
670  }
671 
678  function addUserSpecificResultsExportTitles(&$a_array, $a_export_label = "")
679  {
680  parent::addUserSpecificResultsExportTitles($a_array, $a_export_label);
681 
682  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
683  {
684  $category = $this->categories->getCategory($index);
685  $title = $category->title;
686  array_push($a_array, $title);
687 
688  // optionally add headers for text answers
689  if ($category->other)
690  {
691  array_push($a_array, $title . " - ". $this->lng->txt("other"));
692  }
693  }
694  }
695 
703  function addUserSpecificResultsData(&$a_array, &$resultset)
704  {
705  if (count($resultset["answers"][$this->getId()]))
706  {
707  array_push($a_array, "");
708  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
709  {
710  $category = $this->categories->getCategory($index);
711  $incoming_value = $category->scale ? $category->scale-1 : $index;
712 
713  $found = 0;
714  $textanswer = "";
715  foreach ($resultset["answers"][$this->getId()] as $answerdata)
716  {
717  if (strcmp($incoming_value, $answerdata["value"]) == 0)
718  {
719  $found = $answerdata["value"]+1;
720  $textanswer = $answerdata["textanswer"];
721  }
722  }
723  if ($found)
724  {
725  array_push($a_array, $found);
726  }
727  else
728  {
729  array_push($a_array, "0");
730  }
731  if ($category->other)
732  {
733  array_push($a_array, $textanswer);
734  }
735  }
736  }
737  else
738  {
739  array_push($a_array, $this->lng->txt("skipped"));
740  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
741  {
742  array_push($a_array, "");
743 
744  // add empty text answers for skipped question
745  $category = $this->categories->getCategory($index);
746  if ($category->other)
747  {
748  array_push($a_array, "");
749  }
750  }
751  }
752  }
753 
762  {
763  global $ilDB;
764 
765  $answers = array();
766 
767  $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",
768  array('integer', 'integer'),
769  array($survey_id, $this->getId())
770  );
771  while ($row = $ilDB->fetchAssoc($result))
772  {
773  $category = $this->categories->getCategoryForScale($row["value"]+1);
774  if (!is_array($answers[$row["active_fi"]]))
775  {
776  $answers[$row["active_fi"]] = array();
777  }
778  $title = $row["value"] + 1 . " - " . $category->title;
779  if ($category->other) $title .= ": " . $row["textanswer"];
780  $catindex = $this->categories->getIndex($category);
781  if ($catindex !== null)
782  {
783  $answers[$row["active_fi"]][$catindex] = $title;
784  }
785  else
786  {
787  array_push($answers[$row["active_fi"]], $title);
788  }
789  ksort($answers[$row["active_fi"]], SORT_NUMERIC);
790  }
791  return $answers;
792  }
793 
802  function importAdditionalMetadata($a_meta)
803  {
804  foreach ($a_meta as $key => $value)
805  {
806  switch ($value["label"])
807  {
808  case "orientation":
809  $this->setOrientation($value["entry"]);
810  break;
811  case "use_min_answers":
812  $this->use_min_answers = $value["entry"];
813  break;
814  case "nr_min_answers":
815  $this->nr_min_answers = $value["entry"];
816  break;
817  case "nr_max_answers":
818  $this->nr_max_answers = $value["entry"];
819  break;
820  }
821  }
822  }
823 
830  function importResponses($a_data)
831  {
832  foreach ($a_data as $id => $data)
833  {
834  $categorytext = "";
835  foreach ($data["material"] as $material)
836  {
837  $categorytext .= $material["text"];
838  }
839  $this->categories->addCategory(
840  $categorytext,
841  strlen($data['other']) ? $data['other'] : 0,
842  strlen($data['neutral']) ? $data['neutral'] : 0,
843  strlen($data['label']) ? $data['label'] : null,
844  strlen($data['scale']) ? $data['scale'] : null
845  );
846  }
847  }
848 
856  {
857  return TRUE;
858  }
859 
867  {
868  return array("=", "<>");
869  }
870 
876  public function getPreconditionOptions()
877  {
878  global $lng;
879 
880  $options = array();
881  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
882  {
883  $category = $this->categories->getCategory($i);
884  $options[$category->scale-1] = $category->scale . " - " . $category->title;
885  }
886  return $options;
887  }
888 
895  public function getPreconditionSelectValue($default = "", $title, $variable)
896  {
897  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
898  $step3 = new ilSelectInputGUI($title, $variable);
899  $options = $this->getPreconditionOptions();
900  $step3->setOptions($options);
901  $step3->setValue($default);
902  return $step3;
903  }
904 
912  function getPreconditionValueOutput($value)
913  {
914  $category = $this->categories->getCategory($value);
915  return ($value + 1) . " - " . ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
916  }
917 
918  public function getCategories()
919  {
920  return $this->categories;
921  }
922 
923 }
924 ?>