00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00025 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00026
00027 define("SUBTYPE_NON_RATIO", 3);
00028 define("SUBTYPE_RATIO_NON_ABSOLUTE", 4);
00029 define("SUBTYPE_RATIO_ABSOLUTE", 5);
00030
00042 class SurveyMetricQuestion extends SurveyQuestion
00043 {
00051 var $subtype;
00052
00060 var $minimum;
00061
00069 var $maximum;
00070
00082 function SurveyMetricQuestion(
00083 $title = "",
00084 $description = "",
00085 $author = "",
00086 $questiontext = "",
00087 $owner = -1,
00088 $subtype = SUBTYPE_NON_RATIO
00089 )
00090
00091 {
00092 $this->SurveyQuestion($title, $description, $author, $questiontext, $owner);
00093 $this->subtype = $subtype;
00094 $this->minimum = "";
00095 $this->maximum = "";
00096 }
00097
00107 function setSubtype($subtype = SUBTYPE_NON_RATIO)
00108 {
00109 $this->subtype = $subtype;
00110 }
00111
00121 function setMinimum($minimum = 0)
00122 {
00123 $this->minimum = $minimum;
00124 }
00125
00135 function setMaximum($maximum = "")
00136 {
00137 $this->maximum = $maximum;
00138 }
00139
00149 function getSubtype()
00150 {
00151 return $this->subtype;
00152 }
00153
00163 function getMinimum()
00164 {
00165 if ((strlen($this->minimum) == 0) && ($this->getSubtype() > 3))
00166 {
00167 $this->minimum = 0;
00168 }
00169 return $this->minimum;
00170 }
00171
00181 function getMaximum()
00182 {
00183 return $this->maximum;
00184 }
00185
00195 function _getQuestionDataArray($id)
00196 {
00197 global $ilDB;
00198
00199 $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",
00200 $ilDB->quote($id)
00201 );
00202 $result = $ilDB->query($query);
00203 if ($result->numRows() == 1)
00204 {
00205 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00206 }
00207 else
00208 {
00209 return array();
00210 }
00211 }
00212
00221 function loadFromDb($id)
00222 {
00223 global $ilDB;
00224 $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",
00225 $ilDB->quote($id)
00226 );
00227 $result = $ilDB->query($query);
00228 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00229 {
00230 if ($result->numRows() == 1)
00231 {
00232 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00233 $this->id = $data->question_id;
00234 $this->title = $data->title;
00235 $this->description = $data->description;
00236 $this->obj_id = $data->obj_fi;
00237 $this->obligatory = $data->obligatory;
00238 $this->author = $data->author;
00239 $this->subtype = $data->subtype;
00240 $this->original_id = $data->original_id;
00241 $this->owner = $data->owner_fi;
00242 include_once("./Services/RTE/classes/class.ilRTE.php");
00243 $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
00244 $this->complete = $data->complete;
00245 }
00246
00247 $this->loadMaterialFromDb($id);
00248
00249 $query = sprintf("SELECT survey_variable.* FROM survey_variable WHERE survey_variable.question_fi = %s",
00250 $ilDB->quote($id)
00251 );
00252 $result = $ilDB->query($query);
00253 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00254 {
00255 if ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00256 {
00257 $this->minimum = $data->value1;
00258 if (($data->value2 < 0) or (strcmp($data->value2, "") == 0))
00259 {
00260 $this->maximum = "";
00261 }
00262 else
00263 {
00264 $this->maximum = $data->value2;
00265 }
00266 }
00267 }
00268 }
00269 parent::loadFromDb($id);
00270 }
00271
00280 function isComplete()
00281 {
00282 if ($this->title and $this->author and $this->questiontext)
00283 {
00284 return 1;
00285 }
00286 else
00287 {
00288 return 0;
00289 }
00290 }
00291
00299 function saveToDb($original_id = "")
00300 {
00301 global $ilDB;
00302 $complete = 0;
00303 if ($this->isComplete())
00304 {
00305 $complete = 1;
00306 }
00307 if ($original_id)
00308 {
00309 $original_id = $ilDB->quote($original_id);
00310 }
00311 else
00312 {
00313 $original_id = "NULL";
00314 }
00315
00316 include_once("./Services/RTE/classes/class.ilRTE.php");
00317 ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
00318 $this->getId());
00319
00320 if ($this->id == -1)
00321 {
00322
00323 $now = getdate();
00324 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00325 $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)",
00326 $ilDB->quote($this->getQuestionTypeID()),
00327 $ilDB->quote($this->obj_id),
00328 $ilDB->quote($this->owner),
00329 $ilDB->quote($this->title),
00330 $ilDB->quote($this->description),
00331 $ilDB->quote($this->author),
00332 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00333 $ilDB->quote(sprintf("%d", $this->obligatory)),
00334 $ilDB->quote("$complete"),
00335 $ilDB->quote($created),
00336 $original_id
00337 );
00338 $result = $ilDB->query($query);
00339 if ($result == DB_OK)
00340 {
00341 $this->id = $ilDB->getLastInsertId();
00342 $query = sprintf("INSERT INTO survey_question_metric (question_fi, subtype) VALUES (%s, %s)",
00343 $ilDB->quote($this->id . ""),
00344 $ilDB->quote($this->getSubType() . "")
00345 );
00346 $ilDB->query($query);
00347 }
00348 }
00349 else
00350 {
00351
00352 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00353 $ilDB->quote($this->title),
00354 $ilDB->quote($this->description),
00355 $ilDB->quote($this->author),
00356 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00357 $ilDB->quote(sprintf("%d", $this->obligatory)),
00358 $ilDB->quote("$complete"),
00359 $ilDB->quote($this->id)
00360 );
00361 $result = $ilDB->query($query);
00362 $query = sprintf("UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
00363 $ilDB->quote($this->getSubType() . ""),
00364 $ilDB->quote($this->id . "")
00365 );
00366 $result = $ilDB->query($query);
00367 }
00368 if ($result == DB_OK)
00369 {
00370
00371 $this->saveMaterialsToDb();
00372
00373
00374
00375
00376 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00377 $ilDB->quote($this->id)
00378 );
00379 $result = $ilDB->query($query);
00380
00381 if (strcmp($this->minimum, "") == 0)
00382 {
00383 $min = "NULL";
00384 }
00385 else
00386 {
00387 $min = $ilDB->quote($this->minimum);
00388 }
00389 if (preg_match("/[\D]/", $this->maximum) or (strcmp($this->maximum, "∞") == 0))
00390 {
00391 $max = -1;
00392 }
00393 else
00394 {
00395 if (strcmp($this->maximum, "") == 0)
00396 {
00397 $max = "NULL";
00398 }
00399 else
00400 {
00401 $max = $ilDB->quote($this->maximum);
00402 }
00403 }
00404 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00405 $ilDB->quote(0),
00406 $ilDB->quote($this->id),
00407 $min,
00408 $max,
00409 $ilDB->quote(0)
00410 );
00411 $answer_result = $ilDB->query($query);
00412 }
00413 parent::saveToDb($original_id);
00414 }
00415
00424 function toXML($a_include_header = TRUE, $obligatory_state = "")
00425 {
00426 include_once("./classes/class.ilXmlWriter.php");
00427 $a_xml_writer = new ilXmlWriter;
00428 $a_xml_writer->xmlHeader();
00429 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
00430 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00431 if (!$a_include_header)
00432 {
00433 $pos = strpos($xml, "?>");
00434 $xml = substr($xml, $pos + 2);
00435 }
00436 return $xml;
00437 }
00438
00449 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
00450 {
00451 $attrs = array(
00452 "id" => $this->getId(),
00453 "title" => $this->getTitle(),
00454 "type" => $this->getQuestiontype(),
00455 "subtype" => $this->getSubtype(),
00456 "obligatory" => $this->getObligatory()
00457 );
00458 $a_xml_writer->xmlStartTag("question", $attrs);
00459
00460 $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
00461 $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
00462 $a_xml_writer->xmlStartTag("questiontext");
00463 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
00464 $a_xml_writer->xmlEndTag("questiontext");
00465
00466 $a_xml_writer->xmlStartTag("responses");
00467 switch ($this->getSubtype())
00468 {
00469 case 3:
00470 $attrs = array(
00471 "id" => "0",
00472 "format" => "double"
00473 );
00474 if (strlen($this->getMinimum()))
00475 {
00476 $attrs["min"] = $this->getMinimum();
00477 }
00478 if (strlen($this->getMaximum()))
00479 {
00480 $attrs["max"] = $this->getMaximum();
00481 }
00482 break;
00483 case 4:
00484 $attrs = array(
00485 "id" => "0",
00486 "format" => "double"
00487 );
00488 if (strlen($this->getMinimum()))
00489 {
00490 $attrs["min"] = $this->getMinimum();
00491 }
00492 if (strlen($this->getMaximum()))
00493 {
00494 $attrs["max"] = $this->getMaximum();
00495 }
00496 break;
00497 case 5:
00498 $attrs = array(
00499 "id" => "0",
00500 "format" => "integer"
00501 );
00502 if (strlen($this->getMinimum()))
00503 {
00504 $attrs["min"] = $this->getMinimum();
00505 }
00506 if (strlen($this->getMaximum()))
00507 {
00508 $attrs["max"] = $this->getMaximum();
00509 }
00510 break;
00511 }
00512 $a_xml_writer->xmlStartTag("response_num", $attrs);
00513 $a_xml_writer->xmlEndTag("response_num");
00514
00515 $a_xml_writer->xmlEndTag("responses");
00516
00517 if (count($this->material))
00518 {
00519 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
00520 {
00521 $attrs = array(
00522 "label" => $this->material["title"]
00523 );
00524 $a_xml_writer->xmlStartTag("material", $attrs);
00525 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00526 if (strcmp($matches[1], "") != 0)
00527 {
00528 $intlink = $this->material["internal_link"];
00529 }
00530 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
00531 $a_xml_writer->xmlEndTag("material");
00532 }
00533 }
00534
00535 $a_xml_writer->xmlEndTag("question");
00536 }
00537
00538 function syncWithOriginal()
00539 {
00540 global $ilDB;
00541 if ($this->original_id)
00542 {
00543 $complete = 0;
00544 if ($this->isComplete())
00545 {
00546 $complete = 1;
00547 }
00548 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00549 $ilDB->quote($this->title . ""),
00550 $ilDB->quote($this->description . ""),
00551 $ilDB->quote($this->author . ""),
00552 $ilDB->quote($this->questiontext . ""),
00553 $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
00554 $ilDB->quote($complete . ""),
00555 $ilDB->quote($this->original_id . "")
00556 );
00557 $result = $ilDB->query($query);
00558 $query = sprintf("UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
00559 $ilDB->quote($this->getSubType() . ""),
00560 $ilDB->quote($this->original_id . "")
00561 );
00562 $result = $ilDB->query($query);
00563 if ($result == DB_OK)
00564 {
00565
00566
00567
00568 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00569 $ilDB->quote($this->original_id)
00570 );
00571 $result = $ilDB->query($query);
00572
00573 if (strcmp($this->minimum, "") == 0)
00574 {
00575 $min = "NULL";
00576 }
00577 else
00578 {
00579 $min = $ilDB->quote($this->minimum . "");
00580 }
00581 if (preg_match("/[\D]/", $this->maximum) or (strcmp($this->maximum, "∞") == 0))
00582 {
00583 $max = -1;
00584 }
00585 else
00586 {
00587 if (strcmp($this->maximum, "") == 0)
00588 {
00589 $max = "NULL";
00590 }
00591 else
00592 {
00593 $max = $ilDB->quote($this->maximum . "");
00594 }
00595 }
00596 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00597 $ilDB->quote("0"),
00598 $ilDB->quote($this->original_id . ""),
00599 $min,
00600 $max,
00601 $ilDB->quote("0")
00602 );
00603 $answer_result = $ilDB->query($query);
00604 }
00605 }
00606 parent::syncWithOriginal();
00607 }
00608
00617 function getQuestionTypeID()
00618 {
00619 global $ilDB;
00620 $query = sprintf("SELECT questiontype_id FROM survey_questiontype WHERE type_tag = %s",
00621 $ilDB->quote($this->getQuestionType())
00622 );
00623 $result = $ilDB->query($query);
00624 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00625 return $row["questiontype_id"];
00626 }
00627
00636 function getQuestionType()
00637 {
00638 return "SurveyMetricQuestion";
00639 }
00640
00649 function getAdditionalTableName()
00650 {
00651 return "survey_question_metric";
00652 }
00653
00662 function &getWorkingDataFromUserInput($post_data)
00663 {
00664 $entered_value = $post_data[$this->getId() . "_metric_question"];
00665 $data = array();
00666 if (strlen($entered_value))
00667 {
00668 array_push($data, array("value" => $entered_value));
00669 }
00670 return $data;
00671 }
00672
00685 function checkUserInput($post_data, $survey_id)
00686 {
00687 $entered_value = $post_data[$this->getId() . "_metric_question"];
00688
00689 $entered_value = str_replace(",", ".", $entered_value);
00690
00691 if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
00692
00693 if (strlen($entered_value) == 0) return $this->lng->txt("survey_question_obligatory");
00694
00695 if (strlen($this->getMinimum()))
00696 {
00697 if ($entered_value < $this->getMinimum())
00698 {
00699 return $this->lng->txt("metric_question_out_of_bounds");
00700 }
00701 }
00702
00703 if (strlen($this->getMaximum()))
00704 {
00705 if (($this->getMaximum() == 1) && ($this->getMaximum() < $this->getMinimum()))
00706 {
00707
00708 }
00709 else
00710 {
00711 if ($entered_value > $this->getMaximum())
00712 {
00713 return $this->lng->txt("metric_question_out_of_bounds");
00714 }
00715 }
00716 }
00717
00718 if (!is_numeric($entered_value))
00719 {
00720 return $this->lng->txt("metric_question_not_a_value");
00721 }
00722
00723 if (($this->getSubType() == SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
00724 {
00725 return $this->lng->txt("metric_question_floating_point");
00726 }
00727 return "";
00728 }
00729
00730 function saveUserInput($post_data, $active_id)
00731 {
00732 global $ilDB;
00733
00734 $entered_value = $post_data[$this->getId() . "_metric_question"];
00735 if (strlen($entered_value) == 0) return;
00736
00737 $entered_value = str_replace(",", ".", $entered_value);
00738
00739 if (strlen($entered_value) == 0)
00740 {
00741 $entered_value = "NULL";
00742 }
00743 else
00744 {
00745 $entered_value = $ilDB->quote($entered_value . "");
00746 }
00747 $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00748 $ilDB->quote($this->getId() . ""),
00749 $ilDB->quote($active_id . ""),
00750 $entered_value,
00751 "NULL"
00752 );
00753 $result = $ilDB->query($query);
00754 }
00755
00756 function &getCumulatedResults($survey_id, $nr_of_users)
00757 {
00758 global $ilDB;
00759
00760 $question_id = $this->getId();
00761
00762 $result_array = array();
00763 $cumulated = array();
00764
00765 $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",
00766 $ilDB->quote($question_id),
00767 $ilDB->quote($survey_id)
00768 );
00769 $result = $ilDB->query($query);
00770
00771 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00772 {
00773 $cumulated["$row->value"]++;
00774 }
00775 asort($cumulated, SORT_NUMERIC);
00776 end($cumulated);
00777 $numrows = $result->numRows();
00778 $result_array["USERS_ANSWERED"] = $result->numRows();
00779 $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
00780 $result_array["MODE"] = key($cumulated);
00781 $result_array["MODE_VALUE"] = key($cumulated);
00782 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
00783 ksort($cumulated, SORT_NUMERIC);
00784 $counter = 0;
00785 foreach ($cumulated as $value => $nr_of_users)
00786 {
00787 $percentage = 0;
00788 if ($numrows > 0)
00789 {
00790 $percentage = (float)($nr_of_users/$numrows);
00791 }
00792 $result_array["values"][$counter++] = array("value" => $value, "selected" => (int)$nr_of_users, "percentage" => $percentage);
00793 }
00794 $median = array();
00795 $total = 0;
00796 $x_i = 0;
00797 $p_i = 1;
00798 $x_i_inv = 0;
00799 $sum_part_zero = false;
00800 foreach ($cumulated as $value => $key)
00801 {
00802 $total += $key;
00803 for ($i = 0; $i < $key; $i++)
00804 {
00805 array_push($median, $value);
00806 $x_i += $value;
00807 $p_i *= $value;
00808 if ($value != 0)
00809 {
00810 $sum_part_zero = true;
00811 $x_i_inv += 1/$value;
00812 }
00813 }
00814 }
00815 if ($total > 0)
00816 {
00817 if (($total % 2) == 0)
00818 {
00819 $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
00820 }
00821 else
00822 {
00823 $median_value = $median[(($total+1)/2)-1];
00824 }
00825 }
00826 else
00827 {
00828 $median_value = "";
00829 }
00830 if ($total > 0)
00831 {
00832 if (($x_i/$total) == (int)($x_i/$total))
00833 {
00834 $result_array["ARITHMETIC_MEAN"] = $x_i/$total;
00835 }
00836 else
00837 {
00838 $result_array["ARITHMETIC_MEAN"] = sprintf("%.2f", $x_i/$total);
00839 }
00840 }
00841 else
00842 {
00843 $result_array["ARITHMETIC_MEAN"] = "";
00844 }
00845 $result_array["MEDIAN"] = $median_value;
00846 $result_array["QUESTION_TYPE"] = "SurveyMetricQuestion";
00847 return $result_array;
00848 }
00849
00861 function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
00862 {
00863 include_once ("./classes/class.ilExcelUtils.php");
00864 $worksheet =& $workbook->addWorksheet();
00865 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
00866 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
00867 $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
00868 $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
00869 $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
00870 $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
00871 $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
00872 $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
00873 $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
00874 $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
00875 $rowcounter = 5;
00876
00877 $worksheet->write($rowcounter, 0, $this->lng->txt("subtype"), $format_bold);
00878 switch ($this->getSubtype())
00879 {
00880 case SUBTYPE_NON_RATIO:
00881 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("non_ratio")), $format_bold);
00882 break;
00883 case SUBTYPE_RATIO_NON_ABSOLUTE:
00884 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("ratio_non_absolute")), $format_bold);
00885 break;
00886 case SUBTYPE_RATIO_ABSOLUTE:
00887 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($this->lng->txt("ratio_absolute")), $format_bold);
00888 break;
00889 }
00890 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
00891 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
00892 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
00893 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
00894 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
00895 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
00896 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
00897 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MEDIAN"]));
00898 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean")), $format_bold);
00899 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["ARITHMETIC_MEAN"]));
00900 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("values")), $format_bold);
00901 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
00902 $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
00903 $worksheet->write($rowcounter++, 3, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
00904 $values = "";
00905 if (is_array($eval_data["values"]))
00906 {
00907 foreach ($eval_data["values"] as $key => $value)
00908 {
00909 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["value"]));
00910 $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($value["selected"]));
00911 $worksheet->write($rowcounter++, 3, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
00912 }
00913 }
00914 }
00915
00925 function addUserSpecificResultsData(&$a_array, &$resultset)
00926 {
00927 if (count($resultset["answers"][$this->getId()]))
00928 {
00929 foreach ($resultset["answers"][$this->getId()] as $key => $answer)
00930 {
00931 array_push($a_array, $answer["value"]);
00932 }
00933 }
00934 else
00935 {
00936 array_push($a_array, $this->lng->txt("skipped"));
00937 }
00938 }
00939
00949 function &getUserAnswers($survey_id)
00950 {
00951 global $ilDB;
00952
00953 $answers = array();
00954
00955 $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",
00956 $ilDB->quote($survey_id),
00957 $ilDB->quote($this->getId())
00958 );
00959 $result = $ilDB->query($query);
00960 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00961 {
00962 $answers[$row["active_fi"]] = $row["value"];
00963 }
00964 return $answers;
00965 }
00966
00975 function importResponses($a_data)
00976 {
00977 foreach ($a_data as $id => $data)
00978 {
00979 $this->setMinimum($data["min"]);
00980 $this->setMaximum($data["max"]);
00981 }
00982 }
00983
00992 function usableForPrecondition()
00993 {
00994 return TRUE;
00995 }
00996
01005 function getAvailableRelations()
01006 {
01007 return array("<", "<=", "=", "<>", ">=", ">");
01008 }
01009
01018 function outPreconditionSelectValue(&$template)
01019 {
01020 $template->setCurrentBlock("textfield");
01021 $template->setVariable("TEXTFIELD_VALUE", "");
01022 $template->parseCurrentBlock();
01023 }
01024
01033 function getPreconditionSelectValue($default = "")
01034 {
01035 global $lng;
01036
01037 include_once "./classes/class.ilTemplate.php";
01038 $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_textfield.html", TRUE, TRUE, "Modules/Survey");
01039 if (strlen($default))
01040 {
01041 $template->setCurrentBlock("textfield");
01042 $template->setVariable("TEXTFIELD_VALUE", " value=\"" . ilUtil::prepareFormOutput($default) . "\"");
01043 $template->parseCurrentBlock();
01044 }
01045 else
01046 {
01047 $template->touchBlock("textfield");
01048 }
01049 $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("enter_value"));
01050 return $template->get();
01051 }
01052
01063 function outChart($survey_id, $type = "")
01064 {
01065 if (count($this->cumulated) == 0)
01066 {
01067 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
01068 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
01069 $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
01070 }
01071
01072 foreach ($this->cumulated["values"] as $key => $value)
01073 {
01074 foreach ($value as $key2 => $value2)
01075 {
01076 $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
01077 }
01078 }
01079 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
01080 $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"]);
01081 }
01082
01091 function getMinMaxText()
01092 {
01093 $min = $this->getMinimum();
01094 $max = $this->getMaximum();
01095 if (strlen($min) && strlen($max))
01096 {
01097 return "(" . $min . " " . strtolower($this->lng->txt("to")) . " " . $max . ")";
01098 }
01099 else if (strlen($min))
01100 {
01101 return "(>= " . $min . ")";
01102 }
01103 else if (strlen($max))
01104 {
01105 return "(<= " . $max . ")";
01106 }
01107 else
01108 {
01109 return "";
01110 }
01111 }
01112 }
01113 ?>