ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyOrdinalQuestion.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 {
48 
61  $title = "",
62  $description = "",
63  $author = "",
64  $questiontext = "",
65  $owner = -1,
66  $orientation = 1
67  )
68 
69  {
71  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
72  $this->orientation = $orientation;
73  $this->categories = new SurveyCategories();
74  }
75 
85  function &getCategoriesForPhrase($phrase_id)
86  {
87  global $ilDB;
88  $categories = array();
89  $query = sprintf("SELECT survey_category.* FROM survey_category, survey_phrase_category WHERE survey_phrase_category.category_fi = survey_category.category_id AND survey_phrase_category.phrase_fi = %s ORDER BY survey_phrase_category.sequence",
90  $ilDB->quote($phrase_id)
91  );
92  $result = $ilDB->query($query);
93  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
94  {
95  if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
96  {
97  $categories[$row->category_id] = $this->lng->txt($row->title);
98  }
99  else
100  {
101  $categories[$row->category_id] = $row->title;
102  }
103  }
104  return $categories;
105  }
106 
115  function addPhrase($phrase_id)
116  {
117  global $ilUser;
118  global $ilDB;
119 
120  $query = sprintf("SELECT survey_category.* FROM survey_category, survey_phrase_category WHERE survey_phrase_category.category_fi = survey_category.category_id AND survey_phrase_category.phrase_fi = %s AND (survey_category.owner_fi = 0 OR survey_category.owner_fi = %s) ORDER BY survey_phrase_category.sequence",
121  $ilDB->quote($phrase_id),
122  $ilDB->quote($ilUser->id)
123  );
124  $result = $ilDB->query($query);
125  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
126  {
127  if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
128  {
129  $this->categories->addCategory($this->lng->txt($row->title));
130  }
131  else
132  {
133  $this->categories->addCategory($row->title);
134  }
135  }
136  }
137 
148  {
149  global $ilDB;
150 
151  $query = sprintf("SELECT survey_question.*, survey_question_ordinal.* FROM survey_question, survey_question_ordinal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_ordinal.question_fi",
152  $ilDB->quote($id)
153  );
154  $result = $ilDB->query($query);
155  if ($result->numRows() == 1)
156  {
157  return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
158  }
159  else
160  {
161  return array();
162  }
163  }
164 
173  function loadFromDb($id)
174  {
175  global $ilDB;
176  $query = sprintf("SELECT survey_question.*, survey_question_ordinal.* FROM survey_question, survey_question_ordinal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_ordinal.question_fi",
177  $ilDB->quote($id)
178  );
179  $result = $ilDB->query($query);
180  if ($result->numRows() == 1)
181  {
182  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
183  $this->id = $data->question_id;
184  $this->title = $data->title;
185  $this->description = $data->description;
186  $this->obj_id = $data->obj_fi;
187  $this->orientation = $data->orientation;
188  $this->author = $data->author;
189  $this->owner = $data->owner_fi;
190  include_once("./Services/RTE/classes/class.ilRTE.php");
191  $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
192  $this->obligatory = $data->obligatory;
193  $this->complete = $data->complete;
194  $this->original_id = $data->original_id;
195  // loads materials uris from database
196  $this->loadMaterialFromDb($id);
197 
198  $this->categories->flushCategories();
199  $query = sprintf("SELECT survey_variable.*, survey_category.title FROM survey_variable, survey_category WHERE survey_variable.question_fi = %s AND survey_variable.category_fi = survey_category.category_id ORDER BY sequence ASC",
200  $ilDB->quote($id)
201  );
202  $result = $ilDB->query($query);
203  if ($result->numRows() > 0)
204  {
205  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
206  {
207  $this->categories->addCategory($data->title);
208  }
209  }
210  }
212  }
213 
222  function isComplete()
223  {
224  if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
225  {
226  return 1;
227  }
228  else
229  {
230  return 0;
231  }
232  }
233 
241  function saveToDb($original_id = "", $withanswers = true)
242  {
243  global $ilDB;
244  $complete = 0;
245  if ($this->isComplete()) {
246  $complete = 1;
247  }
248  if ($original_id)
249  {
250  $original_id = $ilDB->quote($original_id);
251  }
252  else
253  {
254  $original_id = "NULL";
255  }
256 
257  // cleanup RTE images which are not inserted into the question text
258  include_once("./Services/RTE/classes/class.ilRTE.php");
259  ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
260  $this->getId());
261 
262  if ($this->id == -1)
263  {
264  // Write new dataset
265  $now = getdate();
266  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
267  $query = sprintf("INSERT INTO survey_question (question_id, questiontype_fi, obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
268  $ilDB->quote($this->getQuestionTypeID()),
269  $ilDB->quote($this->obj_id),
270  $ilDB->quote($this->owner),
271  $ilDB->quote($this->title),
272  $ilDB->quote($this->description),
273  $ilDB->quote($this->author),
274  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
275  $ilDB->quote(sprintf("%d", $this->obligatory)),
276  $ilDB->quote("$complete"),
277  $ilDB->quote($created),
278  $original_id
279  );
280  $result = $ilDB->query($query);
281  if (PEAR::isError($result))
282  {
283  global $ilias;
284  $ilias->raiseError($result->getMessage());
285  }
286  else
287  {
288  $this->id = $ilDB->getLastInsertId();
289  $query = sprintf("INSERT INTO survey_question_ordinal (question_fi, orientation) VALUES (%s, %s)",
290  $ilDB->quote($this->id . ""),
291  $ilDB->quote(sprintf("%d", $this->orientation))
292  );
293  $ilDB->query($query);
294  }
295  }
296  else
297  {
298  // update existing dataset
299  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
300  $ilDB->quote($this->title),
301  $ilDB->quote($this->description),
302  $ilDB->quote($this->author),
303  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
304  $ilDB->quote(sprintf("%d", $this->obligatory)),
305  $ilDB->quote("$complete"),
306  $ilDB->quote($this->id)
307  );
308  $result = $ilDB->query($query);
309  $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
310  $ilDB->quote(sprintf("%d", $this->orientation)),
311  $ilDB->quote($this->id . "")
312  );
313  $result = $ilDB->query($query);
314  }
315  if (PEAR::isError($result))
316  {
317  global $ilias;
318  $ilias->raiseError($result->getMessage());
319  }
320  else
321  {
322  // saving material uris in the database
323  $this->saveMaterialsToDb();
324  if ($withanswers)
325  {
326  $this->saveCategoriesToDb();
327  }
328  }
329  parent::saveToDb($original_id);
330  }
331 
333  {
334  // save categories
335 
336  // delete existing category relations
337  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
338  $this->ilias->db->quote($this->id)
339  );
340  $result = $this->ilias->db->query($query);
341  // create new category relations
342  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
343  {
344  $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
345  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
346  $this->ilias->db->quote($category_id . ""),
347  $this->ilias->db->quote($this->id . ""),
348  $this->ilias->db->quote(($i + 1) . ""),
349  $this->ilias->db->quote($i . "")
350  );
351  $answer_result = $this->ilias->db->query($query);
352  }
353  $this->saveCompletionStatus();
354  }
355 
364  function toXML($a_include_header = TRUE, $obligatory_state = "")
365  {
366  include_once("./classes/class.ilXmlWriter.php");
367  $a_xml_writer = new ilXmlWriter;
368  $a_xml_writer->xmlHeader();
369  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
370  $xml = $a_xml_writer->xmlDumpMem(FALSE);
371  if (!$a_include_header)
372  {
373  $pos = strpos($xml, "?>");
374  $xml = substr($xml, $pos + 2);
375  }
376  return $xml;
377  }
378 
389  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
390  {
391  $attrs = array(
392  "id" => $this->getId(),
393  "title" => $this->getTitle(),
394  "type" => $this->getQuestiontype(),
395  "obligatory" => $this->getObligatory()
396  );
397  $a_xml_writer->xmlStartTag("question", $attrs);
398 
399  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
400  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
401  $a_xml_writer->xmlStartTag("questiontext");
402  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
403  $a_xml_writer->xmlEndTag("questiontext");
404 
405  $a_xml_writer->xmlStartTag("responses");
406 
407  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
408  {
409  $attrs = array(
410  "id" => $i
411  );
412  $a_xml_writer->xmlStartTag("response_single", $attrs);
413  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
414  $a_xml_writer->xmlEndTag("response_single");
415  }
416 
417  $a_xml_writer->xmlEndTag("responses");
418 
419  if (count($this->material))
420  {
421  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
422  {
423  $attrs = array(
424  "label" => $this->material["title"]
425  );
426  $a_xml_writer->xmlStartTag("material", $attrs);
427  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
428  if (strcmp($matches[1], "") != 0)
429  {
430  $intlink = $this->material["internal_link"];
431  }
432  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
433  $a_xml_writer->xmlEndTag("material");
434  }
435  }
436 
437  $a_xml_writer->xmlStartTag("metadata");
438  $a_xml_writer->xmlStartTag("metadatafield");
439  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
440  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
441  $a_xml_writer->xmlEndTag("metadatafield");
442  $a_xml_writer->xmlEndTag("metadata");
443 
444  $a_xml_writer->xmlEndTag("question");
445  }
446 
447  function syncWithOriginal()
448  {
449  global $ilDB;
450  if ($this->original_id)
451  {
452  $complete = 0;
453  if ($this->isComplete()) {
454  $complete = 1;
455  }
456  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
457  $ilDB->quote($this->title . ""),
458  $ilDB->quote($this->description . ""),
459  $ilDB->quote($this->author . ""),
460  $ilDB->quote($this->questiontext . ""),
461  $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
462  $ilDB->quote($complete . ""),
463  $ilDB->quote($this->original_id . "")
464  );
465  $result = $ilDB->query($query);
466  $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
467  $ilDB->quote($this->getOrientation() . ""),
468  $ilDB->quote($this->original_id . "")
469  );
470  $result = $ilDB->query($query);
471  if (PEAR::isError($result))
472  {
473  global $ilias;
474  $ilias->raiseError($result->getMessage());
475  }
476  else
477  {
478  // save categories
479 
480  // delete existing category relations
481  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
482  $ilDB->quote($this->original_id . "")
483  );
484  $result = $ilDB->query($query);
485  // create new category relations
486  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
487  {
488  $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
489  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
490  $ilDB->quote($category_id . ""),
491  $ilDB->quote($this->original_id . ""),
492  $ilDB->quote(($i + 1) . ""),
493  $ilDB->quote($i . "")
494  );
495  $answer_result = $ilDB->query($query);
496  }
497  }
498  }
500  }
501 
511  function addStandardNumbers($lower_limit, $upper_limit)
512  {
513  for ($i = $lower_limit; $i <= $upper_limit; $i++)
514  {
515  $this->categories->addCategory($i);
516  }
517  }
518 
528  function savePhrase($phrases, $title)
529  {
530  global $ilUser;
531  global $ilDB;
532 
533  $query = sprintf("INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
534  $ilDB->quote($title . ""),
535  $ilDB->quote("1"),
536  $ilDB->quote($ilUser->id . "")
537  );
538  $result = $ilDB->query($query);
539  $phrase_id = $ilDB->getLastInsertId();
540 
541  $counter = 1;
542  foreach ($phrases as $category)
543  {
544  $query = sprintf("INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
545  $ilDB->quote($this->categories->getCategory($category) . ""),
546  $ilDB->quote("1"),
547  $ilDB->quote($ilUser->id . "")
548  );
549  $result = $ilDB->query($query);
550  $category_id = $ilDB->getLastInsertId();
551  $query = sprintf("INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
552  $ilDB->quote($phrase_id . ""),
553  $ilDB->quote($category_id . ""),
554  $ilDB->quote($counter . "")
555  );
556  $result = $ilDB->query($query);
557  $counter++;
558  }
559  }
560 
569  function getQuestionType()
570  {
571  return "SurveyOrdinalQuestion";
572  }
573 
583  {
584  return "survey_question_ordinal";
585  }
586 
595  function &getWorkingDataFromUserInput($post_data)
596  {
597  $entered_value = $post_data[$this->getId() . "_value"];
598  $data = array();
599  if (strlen($entered_value))
600  {
601  array_push($data, array("value" => $entered_value));
602  }
603  return $data;
604  }
605 
618  function checkUserInput($post_data, $survey_id)
619  {
620  $entered_value = $post_data[$this->getId() . "_value"];
621 
622  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
623 
624  if (strlen($entered_value) == 0) return $this->lng->txt("ordinal_question_not_checked");
625 
626  return "";
627  }
628 
634  public function saveRandomData($active_id)
635  {
636  global $ilDB;
637  // single response
638  $category = rand(0, $this->categories->getCategoryCount()-1);
639  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
640  $ilDB->quote($this->getId()),
641  $ilDB->quote($active_id),
642  $ilDB->quote($category)
643  );
644  $result = $ilDB->query($query);
645  }
646 
647  function saveUserInput($post_data, $active_id)
648  {
649  global $ilDB;
650 
651  $entered_value = $post_data[$this->getId() . "_value"];
652  if (strlen($entered_value) == 0) return;
653  $entered_value = $ilDB->quote($entered_value . "");
654  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
655  $ilDB->quote($this->getId() . ""),
656  $ilDB->quote($active_id . ""),
657  $entered_value,
658  "NULL"
659  );
660  $result = $ilDB->query($query);
661  }
662 
663  function &getCumulatedResults($survey_id, $nr_of_users)
664  {
665  global $ilDB;
666 
667  $question_id = $this->getId();
668 
669  $result_array = array();
670  $cumulated = array();
671 
672  $query = sprintf("SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
673  $ilDB->quote($question_id),
674  $ilDB->quote($survey_id)
675  );
676  $result = $ilDB->query($query);
677 
678  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
679  {
680  $cumulated["$row->value"]++;
681  }
682  asort($cumulated, SORT_NUMERIC);
683  end($cumulated);
684  $numrows = $result->numRows();
685  $result_array["USERS_ANSWERED"] = $result->numRows();
686  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
687 
688  $prefix = "";
689  if (strcmp(key($cumulated), "") != 0)
690  {
691  $prefix = (key($cumulated)+1) . " - ";
692  }
693  $result_array["MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
694  $result_array["MODE_VALUE"] = key($cumulated)+1;
695  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
696  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
697  {
698  $percentage = 0;
699  if ($numrows > 0)
700  {
701  $percentage = (float)((int)$cumulated[$key]/$numrows);
702  }
703  $result_array["variables"][$key] = array("title" => $this->categories->getCategory($key), "selected" => (int)$cumulated[$key], "percentage" => $percentage);
704  }
705  ksort($cumulated, SORT_NUMERIC);
706  $median = array();
707  $total = 0;
708  foreach ($cumulated as $value => $key)
709  {
710  $total += $key;
711  for ($i = 0; $i < $key; $i++)
712  {
713  array_push($median, $value+1);
714  }
715  }
716  if ($total > 0)
717  {
718  if (($total % 2) == 0)
719  {
720  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
721  if (round($median_value) != $median_value)
722  {
723  $median_value = $median_value . "<br />" . "(" . $this->lng->txt("median_between") . " " . (floor($median_value)) . "-" . $this->categories->getCategory((int)floor($median_value)-1) . " " . $this->lng->txt("and") . " " . (ceil($median_value)) . "-" . $this->categories->getCategory((int)ceil($median_value)-1) . ")";
724  }
725  }
726  else
727  {
728  $median_value = $median[(($total+1)/2)-1];
729  }
730  }
731  else
732  {
733  $median_value = "";
734  }
735  $result_array["ARITHMETIC_MEAN"] = "";
736  $result_array["MEDIAN"] = $median_value;
737  $result_array["QUESTION_TYPE"] = "SurveyOrdinalQuestion";
738  return $result_array;
739  }
740 
752  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
753  {
754  include_once ("./classes/class.ilExcelUtils.php");
755  $worksheet =& $workbook->addWorksheet();
756  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
757  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
758  $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
759  $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
760  $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
761  $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
762  $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
763  $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
764  $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
765  $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
766  $rowcounter = 5;
767 
768  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
769  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
770  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
771  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
772  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
773  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
774  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
775  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
776  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
777  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
778  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
779  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
780  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
781  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
782 
783  foreach ($eval_data["variables"] as $key => $value)
784  {
785  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
786  $worksheet->write($rowcounter, 2, $key+1);
787  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
788  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
789  }
790  }
791 
801  function addUserSpecificResultsData(&$a_array, &$resultset)
802  {
803  if (count($resultset["answers"][$this->getId()]))
804  {
805  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
806  {
807  array_push($a_array, $answer["value"]+1);
808  }
809  }
810  else
811  {
812  array_push($a_array, $this->lng->txt("skipped"));
813  }
814  }
815 
826  {
827  global $ilDB;
828 
829  $answers = array();
830 
831  $query = sprintf("SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_finished.survey_fi = %s AND survey_answer.question_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
832  $ilDB->quote($survey_id),
833  $ilDB->quote($this->getId())
834  );
835  $result = $ilDB->query($query);
836  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
837  {
838  $category = $this->categories->getCategory($row["value"]);
839  $answers[$row["active_fi"]] = $row["value"] + 1 . " - " . $category;
840  }
841  return $answers;
842  }
843 
852  function importResponses($a_data)
853  {
854  foreach ($a_data as $id => $data)
855  {
856  $categorytext = "";
857  foreach ($data["material"] as $material)
858  {
859  $categorytext .= $material["text"];
860  }
861  $this->categories->addCategory($categorytext);
862  }
863  }
864 
874  {
875  return TRUE;
876  }
877 
887  {
888  return array("<", "<=", "=", "<>", ">=", ">");
889  }
890 
899  function getPreconditionSelectValue($default = "")
900  {
901  global $lng;
902 
903  include_once "./classes/class.ilTemplate.php";
904  $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_combobox.html", TRUE, TRUE, "Modules/Survey");
905  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
906  {
907  $template->setCurrentBlock("option_v");
908  $template->setVariable("OPTION_VALUE", $i);
909  $template->setVariable("OPTION_TEXT", ($i+1) . " - " . $this->categories->getCategory($i));
910  if ($i == $default)
911  {
912  $template->setVariable("OPTION_CHECKED", " selected=\"selected\"");
913  }
914  $template->parseCurrentBlock();
915  }
916  $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("select_value"));
917  return $template->get();
918  }
919 
929  function getPreconditionValueOutput($value)
930  {
931  return ($value + 1) . " - " . $this->categories->getCategory($value);
932  }
933 
944  function outChart($survey_id, $type = "")
945  {
946  if (count($this->cumulated) == 0)
947  {
948  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
950  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
951  }
952 
953  foreach ($this->cumulated["variables"] as $key => $value)
954  {
955  foreach ($value as $key2 => $value2)
956  {
957  $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
958  }
959  }
960  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
961  $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"]);
962  }
963 }
964 ?>