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
00038 class SurveyOrdinalQuestion extends SurveyQuestion
00039 {
00047 var $categories;
00048
00060 function SurveyOrdinalQuestion(
00061 $title = "",
00062 $description = "",
00063 $author = "",
00064 $questiontext = "",
00065 $owner = -1,
00066 $orientation = 1
00067 )
00068
00069 {
00070 $this->SurveyQuestion($title, $description, $author, $questiontext, $owner);
00071 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
00072 $this->orientation = $orientation;
00073 $this->categories = new SurveyCategories();
00074 }
00075
00085 function &getCategoriesForPhrase($phrase_id)
00086 {
00087 global $ilDB;
00088 $categories = array();
00089 $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",
00090 $ilDB->quote($phrase_id)
00091 );
00092 $result = $ilDB->query($query);
00093 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00094 {
00095 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
00096 {
00097 $categories[$row->category_id] = $this->lng->txt($row->title);
00098 }
00099 else
00100 {
00101 $categories[$row->category_id] = $row->title;
00102 }
00103 }
00104 return $categories;
00105 }
00106
00115 function addPhrase($phrase_id)
00116 {
00117 global $ilUser;
00118 global $ilDB;
00119
00120 $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",
00121 $ilDB->quote($phrase_id),
00122 $ilDB->quote($ilUser->id)
00123 );
00124 $result = $ilDB->query($query);
00125 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00126 {
00127 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
00128 {
00129 $this->categories->addCategory($this->lng->txt($row->title));
00130 }
00131 else
00132 {
00133 $this->categories->addCategory($row->title);
00134 }
00135 }
00136 }
00137
00147 function _getQuestionDataArray($id)
00148 {
00149 global $ilDB;
00150
00151 $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",
00152 $ilDB->quote($id)
00153 );
00154 $result = $ilDB->query($query);
00155 if ($result->numRows() == 1)
00156 {
00157 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00158 }
00159 else
00160 {
00161 return array();
00162 }
00163 }
00164
00173 function loadFromDb($id)
00174 {
00175 global $ilDB;
00176 $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",
00177 $ilDB->quote($id)
00178 );
00179 $result = $ilDB->query($query);
00180 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00181 {
00182 if ($result->numRows() == 1)
00183 {
00184 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00185 $this->id = $data->question_id;
00186 $this->title = $data->title;
00187 $this->description = $data->description;
00188 $this->obj_id = $data->obj_fi;
00189 $this->orientation = $data->orientation;
00190 $this->author = $data->author;
00191 $this->owner = $data->owner_fi;
00192 include_once("./Services/RTE/classes/class.ilRTE.php");
00193 $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
00194 $this->obligatory = $data->obligatory;
00195 $this->complete = $data->complete;
00196 $this->original_id = $data->original_id;
00197 }
00198
00199 $this->loadMaterialFromDb($id);
00200
00201 $this->categories->flushCategories();
00202
00203 $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",
00204 $ilDB->quote($id)
00205 );
00206 $result = $ilDB->query($query);
00207 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00208 {
00209 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00210 {
00211 $this->categories->addCategory($data->title);
00212 }
00213 }
00214 }
00215 parent::loadFromDb($id);
00216 }
00217
00226 function isComplete()
00227 {
00228 if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
00229 {
00230 return 1;
00231 }
00232 else
00233 {
00234 return 0;
00235 }
00236 }
00237
00245 function saveToDb($original_id = "", $withanswers = true)
00246 {
00247 global $ilDB;
00248 $complete = 0;
00249 if ($this->isComplete()) {
00250 $complete = 1;
00251 }
00252 if ($original_id)
00253 {
00254 $original_id = $ilDB->quote($original_id);
00255 }
00256 else
00257 {
00258 $original_id = "NULL";
00259 }
00260
00261
00262 include_once("./Services/RTE/classes/class.ilRTE.php");
00263 ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
00264 $this->getId());
00265
00266 if ($this->id == -1)
00267 {
00268
00269 $now = getdate();
00270 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00271 $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)",
00272 $ilDB->quote($this->getQuestionTypeID()),
00273 $ilDB->quote($this->obj_id),
00274 $ilDB->quote($this->owner),
00275 $ilDB->quote($this->title),
00276 $ilDB->quote($this->description),
00277 $ilDB->quote($this->author),
00278 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00279 $ilDB->quote(sprintf("%d", $this->obligatory)),
00280 $ilDB->quote("$complete"),
00281 $ilDB->quote($created),
00282 $original_id
00283 );
00284 $result = $ilDB->query($query);
00285 if ($result == DB_OK)
00286 {
00287 $this->id = $ilDB->getLastInsertId();
00288 $query = sprintf("INSERT INTO survey_question_ordinal (question_fi, orientation) VALUES (%s, %s)",
00289 $ilDB->quote($this->id . ""),
00290 $ilDB->quote(sprintf("%d", $this->orientation))
00291 );
00292 $ilDB->query($query);
00293 }
00294 }
00295 else
00296 {
00297
00298 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00299 $ilDB->quote($this->title),
00300 $ilDB->quote($this->description),
00301 $ilDB->quote($this->author),
00302 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00303 $ilDB->quote(sprintf("%d", $this->obligatory)),
00304 $ilDB->quote("$complete"),
00305 $ilDB->quote($this->id)
00306 );
00307 $result = $ilDB->query($query);
00308 $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
00309 $ilDB->quote(sprintf("%d", $this->orientation)),
00310 $ilDB->quote($this->id . "")
00311 );
00312 $result = $ilDB->query($query);
00313 }
00314 if ($result == DB_OK)
00315 {
00316
00317 $this->saveMaterialsToDb();
00318 if ($withanswers)
00319 {
00320 $this->saveCategoriesToDb();
00321 }
00322 }
00323 parent::saveToDb($original_id);
00324 }
00325
00326 function saveCategoriesToDb()
00327 {
00328
00329
00330
00331 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00332 $this->ilias->db->quote($this->id)
00333 );
00334 $result = $this->ilias->db->query($query);
00335
00336 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00337 {
00338 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
00339 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00340 $this->ilias->db->quote($category_id . ""),
00341 $this->ilias->db->quote($this->id . ""),
00342 $this->ilias->db->quote(($i + 1) . ""),
00343 $this->ilias->db->quote($i . "")
00344 );
00345 $answer_result = $this->ilias->db->query($query);
00346 }
00347 $this->saveCompletionStatus();
00348 }
00349
00358 function toXML($a_include_header = TRUE, $obligatory_state = "")
00359 {
00360 include_once("./classes/class.ilXmlWriter.php");
00361 $a_xml_writer = new ilXmlWriter;
00362 $a_xml_writer->xmlHeader();
00363 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
00364 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00365 if (!$a_include_header)
00366 {
00367 $pos = strpos($xml, "?>");
00368 $xml = substr($xml, $pos + 2);
00369 }
00370 return $xml;
00371 }
00372
00383 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
00384 {
00385 $attrs = array(
00386 "id" => $this->getId(),
00387 "title" => $this->getTitle(),
00388 "type" => $this->getQuestiontype(),
00389 "obligatory" => $this->getObligatory()
00390 );
00391 $a_xml_writer->xmlStartTag("question", $attrs);
00392
00393 $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
00394 $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
00395 $a_xml_writer->xmlStartTag("questiontext");
00396 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
00397 $a_xml_writer->xmlEndTag("questiontext");
00398
00399 $a_xml_writer->xmlStartTag("responses");
00400
00401 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00402 {
00403 $attrs = array(
00404 "id" => $i
00405 );
00406 $a_xml_writer->xmlStartTag("response_single", $attrs);
00407 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
00408 $a_xml_writer->xmlEndTag("response_single");
00409 }
00410
00411 $a_xml_writer->xmlEndTag("responses");
00412
00413 if (count($this->material))
00414 {
00415 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
00416 {
00417 $attrs = array(
00418 "label" => $this->material["title"]
00419 );
00420 $a_xml_writer->xmlStartTag("material", $attrs);
00421 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00422 if (strcmp($matches[1], "") != 0)
00423 {
00424 $intlink = $this->material["internal_link"];
00425 }
00426 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
00427 $a_xml_writer->xmlEndTag("material");
00428 }
00429 }
00430
00431 $a_xml_writer->xmlStartTag("metadata");
00432 $a_xml_writer->xmlStartTag("metadatafield");
00433 $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
00434 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
00435 $a_xml_writer->xmlEndTag("metadatafield");
00436 $a_xml_writer->xmlEndTag("metadata");
00437
00438 $a_xml_writer->xmlEndTag("question");
00439 }
00440
00441 function syncWithOriginal()
00442 {
00443 global $ilDB;
00444 if ($this->original_id)
00445 {
00446 $complete = 0;
00447 if ($this->isComplete()) {
00448 $complete = 1;
00449 }
00450 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00451 $ilDB->quote($this->title . ""),
00452 $ilDB->quote($this->description . ""),
00453 $ilDB->quote($this->author . ""),
00454 $ilDB->quote($this->questiontext . ""),
00455 $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
00456 $ilDB->quote($complete . ""),
00457 $ilDB->quote($this->original_id . "")
00458 );
00459 $result = $ilDB->query($query);
00460 $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
00461 $ilDB->quote($this->getOrientation() . ""),
00462 $ilDB->quote($this->original_id . "")
00463 );
00464 $result = $ilDB->query($query);
00465 if ($result == DB_OK) {
00466
00467
00468
00469 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00470 $ilDB->quote($this->original_id . "")
00471 );
00472 $result = $ilDB->query($query);
00473
00474 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00475 {
00476 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
00477 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00478 $ilDB->quote($category_id . ""),
00479 $ilDB->quote($this->original_id . ""),
00480 $ilDB->quote(($i + 1) . ""),
00481 $ilDB->quote($i . "")
00482 );
00483 $answer_result = $ilDB->query($query);
00484 }
00485 }
00486 }
00487 parent::syncWithOriginal();
00488 }
00489
00499 function addStandardNumbers($lower_limit, $upper_limit)
00500 {
00501 for ($i = $lower_limit; $i <= $upper_limit; $i++)
00502 {
00503 $this->categories->addCategory($i);
00504 }
00505 }
00506
00516 function savePhrase($phrases, $title)
00517 {
00518 global $ilUser;
00519 global $ilDB;
00520
00521 $query = sprintf("INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00522 $ilDB->quote($title . ""),
00523 $ilDB->quote("1"),
00524 $ilDB->quote($ilUser->id . "")
00525 );
00526 $result = $ilDB->query($query);
00527 $phrase_id = $ilDB->getLastInsertId();
00528
00529 $counter = 1;
00530 foreach ($phrases as $category)
00531 {
00532 $query = sprintf("INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00533 $ilDB->quote($this->categories->getCategory($category) . ""),
00534 $ilDB->quote("1"),
00535 $ilDB->quote($ilUser->id . "")
00536 );
00537 $result = $ilDB->query($query);
00538 $category_id = $ilDB->getLastInsertId();
00539 $query = sprintf("INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
00540 $ilDB->quote($phrase_id . ""),
00541 $ilDB->quote($category_id . ""),
00542 $ilDB->quote($counter . "")
00543 );
00544 $result = $ilDB->query($query);
00545 $counter++;
00546 }
00547 }
00548
00557 function getQuestionType()
00558 {
00559 return "SurveyOrdinalQuestion";
00560 }
00561
00570 function getAdditionalTableName()
00571 {
00572 return "survey_question_ordinal";
00573 }
00574
00583 function &getWorkingDataFromUserInput($post_data)
00584 {
00585 $entered_value = $post_data[$this->getId() . "_value"];
00586 $data = array();
00587 if (strlen($entered_value))
00588 {
00589 array_push($data, array("value" => $entered_value));
00590 }
00591 return $data;
00592 }
00593
00606 function checkUserInput($post_data, $survey_id)
00607 {
00608 $entered_value = $post_data[$this->getId() . "_value"];
00609
00610 if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
00611
00612 if (strlen($entered_value) == 0) return $this->lng->txt("ordinal_question_not_checked");
00613
00614 return "";
00615 }
00616
00617 function saveUserInput($post_data, $active_id)
00618 {
00619 global $ilDB;
00620
00621 $entered_value = $post_data[$this->getId() . "_value"];
00622 if (strlen($entered_value) == 0) return;
00623 $entered_value = $ilDB->quote($entered_value . "");
00624 $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00625 $ilDB->quote($this->getId() . ""),
00626 $ilDB->quote($active_id . ""),
00627 $entered_value,
00628 "NULL"
00629 );
00630 $result = $ilDB->query($query);
00631 }
00632
00633 function &getCumulatedResults($survey_id, $nr_of_users)
00634 {
00635 global $ilDB;
00636
00637 $question_id = $this->getId();
00638
00639 $result_array = array();
00640 $cumulated = array();
00641
00642 $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",
00643 $ilDB->quote($question_id),
00644 $ilDB->quote($survey_id)
00645 );
00646 $result = $ilDB->query($query);
00647
00648 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00649 {
00650 $cumulated["$row->value"]++;
00651 }
00652 asort($cumulated, SORT_NUMERIC);
00653 end($cumulated);
00654 $numrows = $result->numRows();
00655 $result_array["USERS_ANSWERED"] = $result->numRows();
00656 $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
00657
00658 $prefix = "";
00659 if (strcmp(key($cumulated), "") != 0)
00660 {
00661 $prefix = (key($cumulated)+1) . " - ";
00662 }
00663 $result_array["MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
00664 $result_array["MODE_VALUE"] = key($cumulated)+1;
00665 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
00666 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
00667 {
00668 $percentage = 0;
00669 if ($numrows > 0)
00670 {
00671 $percentage = (float)((int)$cumulated[$key]/$numrows);
00672 }
00673 $result_array["variables"][$key] = array("title" => $this->categories->getCategory($key), "selected" => (int)$cumulated[$key], "percentage" => $percentage);
00674 }
00675 ksort($cumulated, SORT_NUMERIC);
00676 $median = array();
00677 $total = 0;
00678 foreach ($cumulated as $value => $key)
00679 {
00680 $total += $key;
00681 for ($i = 0; $i < $key; $i++)
00682 {
00683 array_push($median, $value+1);
00684 }
00685 }
00686 if ($total > 0)
00687 {
00688 if (($total % 2) == 0)
00689 {
00690 $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
00691 if (round($median_value) != $median_value)
00692 {
00693 $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) . ")";
00694 }
00695 }
00696 else
00697 {
00698 $median_value = $median[(($total+1)/2)-1];
00699 }
00700 }
00701 else
00702 {
00703 $median_value = "";
00704 }
00705 $result_array["ARITHMETIC_MEAN"] = "";
00706 $result_array["MEDIAN"] = $median_value;
00707 $result_array["QUESTION_TYPE"] = "SurveyOrdinalQuestion";
00708 return $result_array;
00709 }
00710
00722 function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
00723 {
00724 include_once ("./classes/class.ilExcelUtils.php");
00725 $worksheet =& $workbook->addWorksheet();
00726 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
00727 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
00728 $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
00729 $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
00730 $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
00731 $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
00732 $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
00733 $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
00734 $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
00735 $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
00736 $rowcounter = 5;
00737
00738 preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
00739 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
00740 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
00741 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
00742 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
00743 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
00744 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
00745 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
00746 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
00747 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
00748 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
00749 $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
00750 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
00751 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
00752
00753 foreach ($eval_data["variables"] as $key => $value)
00754 {
00755 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
00756 $worksheet->write($rowcounter, 2, $key+1);
00757 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
00758 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
00759 }
00760 }
00761
00771 function addUserSpecificResultsData(&$a_array, &$resultset)
00772 {
00773 if (count($resultset["answers"][$this->getId()]))
00774 {
00775 foreach ($resultset["answers"][$this->getId()] as $key => $answer)
00776 {
00777 array_push($a_array, $answer["value"]+1);
00778 }
00779 }
00780 else
00781 {
00782 array_push($a_array, $this->lng->txt("skipped"));
00783 }
00784 }
00785
00795 function &getUserAnswers($survey_id)
00796 {
00797 global $ilDB;
00798
00799 $answers = array();
00800
00801 $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",
00802 $ilDB->quote($survey_id),
00803 $ilDB->quote($this->getId())
00804 );
00805 $result = $ilDB->query($query);
00806 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00807 {
00808 $category = $this->categories->getCategory($row["value"]);
00809 $answers[$row["active_fi"]] = $row["value"] + 1 . " - " . $category;
00810 }
00811 return $answers;
00812 }
00813
00822 function importResponses($a_data)
00823 {
00824 foreach ($a_data as $id => $data)
00825 {
00826 $categorytext = "";
00827 foreach ($data["material"] as $material)
00828 {
00829 $categorytext .= $material["text"];
00830 }
00831 $this->categories->addCategory($categorytext);
00832 }
00833 }
00834
00843 function usableForPrecondition()
00844 {
00845 return TRUE;
00846 }
00847
00856 function getAvailableRelations()
00857 {
00858 return array("<", "<=", "=", "<>", ">=", ">");
00859 }
00860
00869 function getPreconditionSelectValue($default = "")
00870 {
00871 global $lng;
00872
00873 include_once "./classes/class.ilTemplate.php";
00874 $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_combobox.html", TRUE, TRUE, "Modules/Survey");
00875 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00876 {
00877 $template->setCurrentBlock("option_v");
00878 $template->setVariable("OPTION_VALUE", $i);
00879 $template->setVariable("OPTION_TEXT", ($i+1) . " - " . $this->categories->getCategory($i));
00880 if ($i == $default)
00881 {
00882 $template->setVariable("OPTION_CHECKED", " selected=\"selected\"");
00883 }
00884 $template->parseCurrentBlock();
00885 }
00886 $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("select_value"));
00887 return $template->get();
00888 }
00889
00899 function getPreconditionValueOutput($value)
00900 {
00901 return ($value + 1) . " - " . $this->categories->getCategory($value);
00902 }
00903
00914 function outChart($survey_id, $type = "")
00915 {
00916 if (count($this->cumulated) == 0)
00917 {
00918 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00919 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00920 $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
00921 }
00922
00923 foreach ($this->cumulated["variables"] as $key => $value)
00924 {
00925 foreach ($value as $key2 => $value2)
00926 {
00927 $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
00928 }
00929 }
00930 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
00931 $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"]);
00932 }
00933 }
00934 ?>