ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMetricQuestion.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 
27 define("SUBTYPE_NON_RATIO", 3);
28 define("SUBTYPE_RATIO_NON_ABSOLUTE", 4);
29 define("SUBTYPE_RATIO_ABSOLUTE", 5);
30 
43 {
51  var $subtype;
52 
60  var $minimum;
61 
69  var $maximum;
70 
83  $title = "",
84  $description = "",
85  $author = "",
86  $questiontext = "",
87  $owner = -1,
89  )
90 
91  {
93  $this->subtype = $subtype;
94  $this->minimum = "";
95  $this->maximum = "";
96  }
97 
108  {
109  $this->subtype = $subtype;
110  }
111 
121  function setMinimum($minimum = 0)
122  {
123  $this->minimum = $minimum;
124  }
125 
135  function setMaximum($maximum = "")
136  {
137  $this->maximum = $maximum;
138  }
139 
149  function getSubtype()
150  {
151  return $this->subtype;
152  }
153 
163  function getMinimum()
164  {
165  if ((strlen($this->minimum) == 0) && ($this->getSubtype() > 3))
166  {
167  $this->minimum = 0;
168  }
169  return $this->minimum;
170  }
171 
181  function getMaximum()
182  {
183  return $this->maximum;
184  }
185 
196  {
197  global $ilDB;
198 
199  $query = sprintf("SELECT survey_question.*, survey_question_metric.* FROM survey_question, survey_question_metric WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_metric.question_fi",
200  $ilDB->quote($id)
201  );
202  $result = $ilDB->query($query);
203  if ($result->numRows() == 1)
204  {
205  return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
206  }
207  else
208  {
209  return array();
210  }
211  }
212 
221  function loadFromDb($id)
222  {
223  global $ilDB;
224  $query = sprintf("SELECT survey_question.*, survey_question_metric.* FROM survey_question, survey_question_metric WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_metric.question_fi",
225  $ilDB->quote($id)
226  );
227  $result = $ilDB->query($query);
228  if ($result->numRows() == 1)
229  {
230  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
231  $this->id = $data->question_id;
232  $this->title = $data->title;
233  $this->description = $data->description;
234  $this->obj_id = $data->obj_fi;
235  $this->obligatory = $data->obligatory;
236  $this->author = $data->author;
237  $this->subtype = $data->subtype;
238  $this->original_id = $data->original_id;
239  $this->owner = $data->owner_fi;
240  include_once("./Services/RTE/classes/class.ilRTE.php");
241  $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
242  $this->complete = $data->complete;
243  // loads materials uris from database
244  $this->loadMaterialFromDb($id);
245 
246  $query = sprintf("SELECT survey_variable.* FROM survey_variable WHERE survey_variable.question_fi = %s",
247  $ilDB->quote($id)
248  );
249  $result = $ilDB->query($query);
250  if ($result->numRows() > 0)
251  {
252  if ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
253  {
254  $this->minimum = $data->value1;
255  if (($data->value2 < 0) or (strcmp($data->value2, "") == 0))
256  {
257  $this->maximum = "";
258  }
259  else
260  {
261  $this->maximum = $data->value2;
262  }
263  }
264  }
265  }
267  }
268 
277  function isComplete()
278  {
279  if ($this->title and $this->author and $this->questiontext)
280  {
281  return 1;
282  }
283  else
284  {
285  return 0;
286  }
287  }
288 
296  function saveToDb($original_id = "")
297  {
298  global $ilDB;
299  $complete = 0;
300  if ($this->isComplete())
301  {
302  $complete = 1;
303  }
304  if ($original_id)
305  {
306  $original_id = $ilDB->quote($original_id);
307  }
308  else
309  {
310  $original_id = "NULL";
311  }
312  // cleanup RTE images which are not inserted into the question text
313  include_once("./Services/RTE/classes/class.ilRTE.php");
314  ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
315  $this->getId());
316 
317  if ($this->id == -1)
318  {
319  // Write new dataset
320  $now = getdate();
321  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
322  $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)",
323  $ilDB->quote($this->getQuestionTypeID()),
324  $ilDB->quote($this->obj_id),
325  $ilDB->quote($this->owner),
326  $ilDB->quote($this->title),
327  $ilDB->quote($this->description),
328  $ilDB->quote($this->author),
329  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
330  $ilDB->quote(sprintf("%d", $this->obligatory)),
331  $ilDB->quote("$complete"),
332  $ilDB->quote($created),
333  $original_id
334  );
335  $result = $ilDB->query($query);
336  if (PEAR::isError($result))
337  {
338  global $ilias;
339  $ilias->raiseError($result->getMessage());
340  }
341  else
342  {
343  $this->id = $ilDB->getLastInsertId();
344  $query = sprintf("INSERT INTO survey_question_metric (question_fi, subtype) VALUES (%s, %s)",
345  $ilDB->quote($this->id . ""),
346  $ilDB->quote($this->getSubType() . "")
347  );
348  $ilDB->query($query);
349  }
350  }
351  else
352  {
353  // update existing dataset
354  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
355  $ilDB->quote($this->title),
356  $ilDB->quote($this->description),
357  $ilDB->quote($this->author),
358  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
359  $ilDB->quote(sprintf("%d", $this->obligatory)),
360  $ilDB->quote("$complete"),
361  $ilDB->quote($this->id)
362  );
363  $result = $ilDB->query($query);
364  $query = sprintf("UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
365  $ilDB->quote($this->getSubType() . ""),
366  $ilDB->quote($this->id . "")
367  );
368  $result = $ilDB->query($query);
369  }
370  if (PEAR::isError($result))
371  {
372  global $ilias;
373  $ilias->raiseError($result->getMessage());
374  }
375  else
376  {
377  // saving material uris in the database
378  $this->saveMaterialsToDb();
379  // save categories
380  // delete existing category relations
381  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
382  $ilDB->quote($this->id)
383  );
384  $result = $ilDB->query($query);
385  // create new category relations
386  if (strcmp($this->minimum, "") == 0)
387  {
388  $min = "NULL";
389  }
390  else
391  {
392  $min = $ilDB->quote($this->minimum);
393  }
394  if (preg_match("/[\D]/", $this->maximum) or (strcmp($this->maximum, "&infin;") == 0))
395  {
396  $max = -1;
397  }
398  else
399  {
400  if (strcmp($this->maximum, "") == 0)
401  {
402  $max = "NULL";
403  }
404  else
405  {
406  $max = $ilDB->quote($this->maximum);
407  }
408  }
409  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
410  $ilDB->quote(0),
411  $ilDB->quote($this->id),
412  $min,
413  $max,
414  $ilDB->quote(0)
415  );
416  $answer_result = $ilDB->query($query);
417  }
418  parent::saveToDb($original_id);
419  }
420 
429  function toXML($a_include_header = TRUE, $obligatory_state = "")
430  {
431  include_once("./classes/class.ilXmlWriter.php");
432  $a_xml_writer = new ilXmlWriter;
433  $a_xml_writer->xmlHeader();
434  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
435  $xml = $a_xml_writer->xmlDumpMem(FALSE);
436  if (!$a_include_header)
437  {
438  $pos = strpos($xml, "?>");
439  $xml = substr($xml, $pos + 2);
440  }
441  return $xml;
442  }
443 
454  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
455  {
456  $attrs = array(
457  "id" => $this->getId(),
458  "title" => $this->getTitle(),
459  "type" => $this->getQuestiontype(),
460  "subtype" => $this->getSubtype(),
461  "obligatory" => $this->getObligatory()
462  );
463  $a_xml_writer->xmlStartTag("question", $attrs);
464 
465  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
466  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
467  $a_xml_writer->xmlStartTag("questiontext");
468  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
469  $a_xml_writer->xmlEndTag("questiontext");
470 
471  $a_xml_writer->xmlStartTag("responses");
472  switch ($this->getSubtype())
473  {
474  case 3:
475  $attrs = array(
476  "id" => "0",
477  "format" => "double"
478  );
479  if (strlen($this->getMinimum()))
480  {
481  $attrs["min"] = $this->getMinimum();
482  }
483  if (strlen($this->getMaximum()))
484  {
485  $attrs["max"] = $this->getMaximum();
486  }
487  break;
488  case 4:
489  $attrs = array(
490  "id" => "0",
491  "format" => "double"
492  );
493  if (strlen($this->getMinimum()))
494  {
495  $attrs["min"] = $this->getMinimum();
496  }
497  if (strlen($this->getMaximum()))
498  {
499  $attrs["max"] = $this->getMaximum();
500  }
501  break;
502  case 5:
503  $attrs = array(
504  "id" => "0",
505  "format" => "integer"
506  );
507  if (strlen($this->getMinimum()))
508  {
509  $attrs["min"] = $this->getMinimum();
510  }
511  if (strlen($this->getMaximum()))
512  {
513  $attrs["max"] = $this->getMaximum();
514  }
515  break;
516  }
517  $a_xml_writer->xmlStartTag("response_num", $attrs);
518  $a_xml_writer->xmlEndTag("response_num");
519 
520  $a_xml_writer->xmlEndTag("responses");
521 
522  if (count($this->material))
523  {
524  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
525  {
526  $attrs = array(
527  "label" => $this->material["title"]
528  );
529  $a_xml_writer->xmlStartTag("material", $attrs);
530  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
531  if (strcmp($matches[1], "") != 0)
532  {
533  $intlink = $this->material["internal_link"];
534  }
535  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
536  $a_xml_writer->xmlEndTag("material");
537  }
538  }
539 
540  $a_xml_writer->xmlEndTag("question");
541  }
542 
543  function syncWithOriginal()
544  {
545  global $ilDB;
546  if ($this->original_id)
547  {
548  $complete = 0;
549  if ($this->isComplete())
550  {
551  $complete = 1;
552  }
553  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
554  $ilDB->quote($this->title . ""),
555  $ilDB->quote($this->description . ""),
556  $ilDB->quote($this->author . ""),
557  $ilDB->quote($this->questiontext . ""),
558  $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
559  $ilDB->quote($complete . ""),
560  $ilDB->quote($this->original_id . "")
561  );
562  $result = $ilDB->query($query);
563  $query = sprintf("UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
564  $ilDB->quote($this->getSubType() . ""),
565  $ilDB->quote($this->original_id . "")
566  );
567  $result = $ilDB->query($query);
568  if (PEAR::isError($result))
569  {
570  global $ilias;
571  $ilias->raiseError($result->getMessage());
572  }
573  else
574  {
575  // save categories
576 
577  // delete existing category relations
578  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
579  $ilDB->quote($this->original_id)
580  );
581  $result = $ilDB->query($query);
582  // create new category relations
583  if (strcmp($this->minimum, "") == 0)
584  {
585  $min = "NULL";
586  }
587  else
588  {
589  $min = $ilDB->quote($this->minimum . "");
590  }
591  if (preg_match("/[\D]/", $this->maximum) or (strcmp($this->maximum, "&infin;") == 0))
592  {
593  $max = -1;
594  }
595  else
596  {
597  if (strcmp($this->maximum, "") == 0)
598  {
599  $max = "NULL";
600  }
601  else
602  {
603  $max = $ilDB->quote($this->maximum . "");
604  }
605  }
606  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
607  $ilDB->quote("0"),
608  $ilDB->quote($this->original_id . ""),
609  $min,
610  $max,
611  $ilDB->quote("0")
612  );
613  $answer_result = $ilDB->query($query);
614  }
615  }
617  }
618 
627  function getQuestionTypeID()
628  {
629  global $ilDB;
630  $query = sprintf("SELECT questiontype_id FROM survey_questiontype WHERE type_tag = %s",
631  $ilDB->quote($this->getQuestionType())
632  );
633  $result = $ilDB->query($query);
634  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
635  return $row["questiontype_id"];
636  }
637 
646  function getQuestionType()
647  {
648  return "SurveyMetricQuestion";
649  }
650 
660  {
661  return "survey_question_metric";
662  }
663 
672  function &getWorkingDataFromUserInput($post_data)
673  {
674  $entered_value = $post_data[$this->getId() . "_metric_question"];
675  $data = array();
676  if (strlen($entered_value))
677  {
678  array_push($data, array("value" => $entered_value));
679  }
680  return $data;
681  }
682 
695  function checkUserInput($post_data, $survey_id)
696  {
697  $entered_value = $post_data[$this->getId() . "_metric_question"];
698  // replace german notation with international notation
699  $entered_value = str_replace(",", ".", $entered_value);
700 
701  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
702 
703  if (strlen($entered_value) == 0) return $this->lng->txt("survey_question_obligatory");
704 
705  if (strlen($this->getMinimum()))
706  {
707  if ($entered_value < $this->getMinimum())
708  {
709  return $this->lng->txt("metric_question_out_of_bounds");
710  }
711  }
712 
713  if (strlen($this->getMaximum()))
714  {
715  if (($this->getMaximum() == 1) && ($this->getMaximum() < $this->getMinimum()))
716  {
717  // old &infty; values as maximum
718  }
719  else
720  {
721  if ($entered_value > $this->getMaximum())
722  {
723  return $this->lng->txt("metric_question_out_of_bounds");
724  }
725  }
726  }
727 
728  if (!is_numeric($entered_value))
729  {
730  return $this->lng->txt("metric_question_not_a_value");
731  }
732 
733  if (($this->getSubType() == SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
734  {
735  return $this->lng->txt("metric_question_floating_point");
736  }
737  return "";
738  }
739 
745  public function saveRandomData($active_id)
746  {
747  global $ilDB;
748  // single response
749  $number = rand($this->getMinimum(), (strlen($this->getMaximum())) ? $this->getMaximum() : 100);
750  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
751  $ilDB->quote($this->getId()),
752  $ilDB->quote($active_id),
753  $ilDB->quote($number)
754  );
755  $result = $ilDB->query($query);
756  }
757 
758  function saveUserInput($post_data, $active_id)
759  {
760  global $ilDB;
761 
762  $entered_value = $post_data[$this->getId() . "_metric_question"];
763  if (strlen($entered_value) == 0) return;
764  // replace german notation with international notation
765  $entered_value = str_replace(",", ".", $entered_value);
766 
767  if (strlen($entered_value) == 0)
768  {
769  $entered_value = "NULL";
770  }
771  else
772  {
773  $entered_value = $ilDB->quote($entered_value . "");
774  }
775  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
776  $ilDB->quote($this->getId() . ""),
777  $ilDB->quote($active_id . ""),
778  $entered_value,
779  "NULL"
780  );
781  $result = $ilDB->query($query);
782  }
783 
784  function &getCumulatedResults($survey_id, $nr_of_users)
785  {
786  global $ilDB;
787 
788  $question_id = $this->getId();
789 
790  $result_array = array();
791  $cumulated = array();
792 
793  $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",
794  $ilDB->quote($question_id),
795  $ilDB->quote($survey_id)
796  );
797  $result = $ilDB->query($query);
798 
799  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
800  {
801  $cumulated["$row->value"]++;
802  }
803  asort($cumulated, SORT_NUMERIC);
804  end($cumulated);
805  $numrows = $result->numRows();
806  $result_array["USERS_ANSWERED"] = $result->numRows();
807  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
808  $result_array["MODE"] = key($cumulated);
809  $result_array["MODE_VALUE"] = key($cumulated);
810  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
811  ksort($cumulated, SORT_NUMERIC);
812  $counter = 0;
813  foreach ($cumulated as $value => $nr_of_users)
814  {
815  $percentage = 0;
816  if ($numrows > 0)
817  {
818  $percentage = (float)($nr_of_users/$numrows);
819  }
820  $result_array["values"][$counter++] = array("value" => $value, "selected" => (int)$nr_of_users, "percentage" => $percentage);
821  }
822  $median = array();
823  $total = 0;
824  $x_i = 0;
825  $p_i = 1;
826  $x_i_inv = 0;
827  $sum_part_zero = false;
828  foreach ($cumulated as $value => $key)
829  {
830  $total += $key;
831  for ($i = 0; $i < $key; $i++)
832  {
833  array_push($median, $value);
834  $x_i += $value;
835  $p_i *= $value;
836  if ($value != 0)
837  {
838  $sum_part_zero = true;
839  $x_i_inv += 1/$value;
840  }
841  }
842  }
843  if ($total > 0)
844  {
845  if (($total % 2) == 0)
846  {
847  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
848  }
849  else
850  {
851  $median_value = $median[(($total+1)/2)-1];
852  }
853  }
854  else
855  {
856  $median_value = "";
857  }
858  if ($total > 0)
859  {
860  if (($x_i/$total) == (int)($x_i/$total))
861  {
862  $result_array["ARITHMETIC_MEAN"] = $x_i/$total;
863  }
864  else
865  {
866  $result_array["ARITHMETIC_MEAN"] = sprintf("%.2f", $x_i/$total);
867  }
868  }
869  else
870  {
871  $result_array["ARITHMETIC_MEAN"] = "";
872  }
873  $result_array["MEDIAN"] = $median_value;
874  $result_array["QUESTION_TYPE"] = "SurveyMetricQuestion";
875  return $result_array;
876  }
877 
889  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
890  {
891  include_once ("./classes/class.ilExcelUtils.php");
892  $worksheet =& $workbook->addWorksheet();
893  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
894  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
895  $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
896  $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
897  $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
898  $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
899  $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
900  $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
901  $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
902  $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
903  $rowcounter = 5;
904 
905  $worksheet->write($rowcounter, 0, $this->lng->txt("subtype"), $format_bold);
906  switch ($this->getSubtype())
907  {
908  case SUBTYPE_NON_RATIO:
909  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("non_ratio")), $format_bold);
910  break;
912  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("ratio_non_absolute")), $format_bold);
913  break;
915  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("ratio_absolute")), $format_bold);
916  break;
917  }
918  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
919  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
920  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
921  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
922  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
923  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
924  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
925  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MEDIAN"]));
926  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean")), $format_bold);
927  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["ARITHMETIC_MEAN"]));
928  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("values")), $format_bold);
929  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
930  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
931  $worksheet->write($rowcounter++, 3, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
932  $values = "";
933  if (is_array($eval_data["values"]))
934  {
935  foreach ($eval_data["values"] as $key => $value)
936  {
937  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["value"]));
938  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($value["selected"]));
939  $worksheet->write($rowcounter++, 3, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
940  }
941  }
942  }
943 
953  function addUserSpecificResultsData(&$a_array, &$resultset)
954  {
955  if (count($resultset["answers"][$this->getId()]))
956  {
957  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
958  {
959  array_push($a_array, $answer["value"]);
960  }
961  }
962  else
963  {
964  array_push($a_array, $this->lng->txt("skipped"));
965  }
966  }
967 
978  {
979  global $ilDB;
980 
981  $answers = array();
982 
983  $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",
984  $ilDB->quote($survey_id),
985  $ilDB->quote($this->getId())
986  );
987  $result = $ilDB->query($query);
988  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
989  {
990  $answers[$row["active_fi"]] = $row["value"];
991  }
992  return $answers;
993  }
994 
1003  function importResponses($a_data)
1004  {
1005  foreach ($a_data as $id => $data)
1006  {
1007  $this->setMinimum($data["min"]);
1008  $this->setMaximum($data["max"]);
1009  }
1010  }
1011 
1021  {
1022  return TRUE;
1023  }
1024 
1034  {
1035  return array("<", "<=", "=", "<>", ">=", ">");
1036  }
1037 
1046  function outPreconditionSelectValue(&$template)
1047  {
1048  $template->setCurrentBlock("textfield");
1049  $template->setVariable("TEXTFIELD_VALUE", "");
1050  $template->parseCurrentBlock();
1051  }
1052 
1061  function getPreconditionSelectValue($default = "")
1062  {
1063  global $lng;
1064 
1065  include_once "./classes/class.ilTemplate.php";
1066  $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_textfield.html", TRUE, TRUE, "Modules/Survey");
1067  if (strlen($default))
1068  {
1069  $template->setCurrentBlock("textfield");
1070  $template->setVariable("TEXTFIELD_VALUE", " value=\"" . ilUtil::prepareFormOutput($default) . "\"");
1071  $template->parseCurrentBlock();
1072  }
1073  else
1074  {
1075  $template->touchBlock("textfield");
1076  }
1077  $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("enter_value"));
1078  return $template->get();
1079  }
1080 
1091  function outChart($survey_id, $type = "")
1092  {
1093  if (count($this->cumulated) == 0)
1094  {
1095  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1097  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
1098  }
1099 
1100  foreach ($this->cumulated["values"] as $key => $value)
1101  {
1102  foreach ($value as $key2 => $value2)
1103  {
1104  $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
1105  }
1106  }
1107  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
1108  $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["values"]);
1109  }
1110 
1119  function getMinMaxText()
1120  {
1121  $min = $this->getMinimum();
1122  $max = $this->getMaximum();
1123  if (strlen($min) && strlen($max))
1124  {
1125  return "(" . $min . " " . strtolower($this->lng->txt("to")) . " " . $max . ")";
1126  }
1127  else if (strlen($min))
1128  {
1129  return "(&gt;= " . $min . ")";
1130  }
1131  else if (strlen($max))
1132  {
1133  return "(&lt;= " . $max . ")";
1134  }
1135  else
1136  {
1137  return "";
1138  }
1139  }
1140 }
1141 ?>