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_MCSR", 1);
00028 define("SUBTYPE_MCMR", 2);
00029
00041 class SurveyNominalQuestion extends SurveyQuestion
00042 {
00050 var $subtype;
00051
00059 var $categories;
00060
00072 function SurveyNominalQuestion(
00073 $title = "",
00074 $description = "",
00075 $author = "",
00076 $questiontext = "",
00077 $owner = -1,
00078 $subtype = SUBTYPE_MCSR,
00079 $orientation = 0
00080 )
00081
00082 {
00083 $this->SurveyQuestion($title, $description, $author, $questiontext, $owner);
00084 $this->subtype = $subtype;
00085 $this->orientation = $orientation;
00086 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
00087 $this->categories = new SurveyCategories();
00088 }
00089
00099 function setSubtype($subtype = SUBTYPE_MCSR)
00100 {
00101 $this->subtype = $subtype;
00102 }
00103
00113 function getSubtype()
00114 {
00115 return $this->subtype;
00116 }
00117
00127 function _getQuestionDataArray($id)
00128 {
00129 global $ilDB;
00130
00131 $query = sprintf("SELECT survey_question.*, survey_question_nominal.* FROM survey_question, survey_question_nominal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_nominal.question_fi",
00132 $ilDB->quote($id)
00133 );
00134 $result = $ilDB->query($query);
00135 if ($result->numRows() == 1)
00136 {
00137 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00138 }
00139 else
00140 {
00141 return array();
00142 }
00143 }
00144
00153 function loadFromDb($id)
00154 {
00155 global $ilDB;
00156 $query = sprintf("SELECT survey_question.*, survey_question_nominal.* FROM survey_question, survey_question_nominal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_nominal.question_fi",
00157 $ilDB->quote($id)
00158 );
00159 $result = $ilDB->query($query);
00160 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00161 {
00162 if ($result->numRows() == 1)
00163 {
00164 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00165 $this->id = $data->question_id;
00166 $this->title = $data->title;
00167 $this->description = $data->description;
00168 $this->obj_id = $data->obj_fi;
00169 $this->author = $data->author;
00170 $this->subtype = $data->subtype;
00171 $this->orientation = $data->orientation;
00172 $this->obligatory = $data->obligatory;
00173 $this->owner = $data->owner_fi;
00174 include_once("./Services/RTE/classes/class.ilRTE.php");
00175 $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
00176 $this->complete = $data->complete;
00177 $this->original_id = $data->original_id;
00178 }
00179
00180 $this->loadMaterialFromDb($id);
00181
00182 $this->categories->flushCategories();
00183 $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",
00184 $ilDB->quote($id)
00185 );
00186 $result = $ilDB->query($query);
00187 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00188 {
00189 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00190 {
00191 $this->categories->addCategory($data->title);
00192 }
00193 }
00194 }
00195 parent::loadFromDb($id);
00196 }
00197
00206 function isComplete()
00207 {
00208 if (strlen($this->title) && strlen($this->author) && strlen($this->questiontext) && $this->categories->getCategoryCount())
00209 {
00210 return 1;
00211 }
00212 else
00213 {
00214 return 0;
00215 }
00216 }
00217
00225 function saveToDb($original_id = "", $withanswers = true)
00226 {
00227 global $ilDB;
00228 $complete = 0;
00229 if ($this->isComplete())
00230 {
00231 $complete = 1;
00232 }
00233 if ($original_id)
00234 {
00235 $original_id = $ilDB->quote($original_id);
00236 }
00237 else
00238 {
00239 $original_id = "NULL";
00240 }
00241
00242 include_once("./Services/RTE/classes/class.ilRTE.php");
00243 ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
00244 $this->getId());
00245
00246 if ($this->id == -1)
00247 {
00248
00249 $now = getdate();
00250 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00251 $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)",
00252 $ilDB->quote($this->getQuestionTypeID()),
00253 $ilDB->quote($this->obj_id),
00254 $ilDB->quote($this->owner),
00255 $ilDB->quote($this->title),
00256 $ilDB->quote($this->description),
00257 $ilDB->quote($this->author),
00258 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00259 $ilDB->quote(sprintf("%d", $this->obligatory)),
00260 $ilDB->quote("$complete"),
00261 $ilDB->quote($created),
00262 $original_id
00263 );
00264 $result = $ilDB->query($query);
00265 if ($result == DB_OK)
00266 {
00267 $this->id = $ilDB->getLastInsertId();
00268 $query = sprintf("INSERT INTO survey_question_nominal (question_fi, subtype, orientation) VALUES (%s, %s, %s)",
00269 $ilDB->quote($this->id . ""),
00270 $ilDB->quote($this->getSubType() . ""),
00271 $ilDB->quote(sprintf("%d", $this->orientation))
00272 );
00273 $ilDB->query($query);
00274 }
00275 }
00276 else
00277 {
00278
00279 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00280 $ilDB->quote($this->title),
00281 $ilDB->quote($this->description),
00282 $ilDB->quote($this->author),
00283 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00284 $ilDB->quote(sprintf("%d", $this->obligatory)),
00285 $ilDB->quote("$complete"),
00286 $ilDB->quote($this->id)
00287 );
00288 $result = $ilDB->query($query);
00289 $query = sprintf("UPDATE survey_question_nominal SET subtype = %s, orientation = %s WHERE question_fi = %s",
00290 $ilDB->quote($this->getSubType() . ""),
00291 $ilDB->quote(sprintf("%d", $this->orientation)),
00292 $ilDB->quote($this->id . "")
00293 );
00294 $result = $ilDB->query($query);
00295 }
00296 if ($result == DB_OK)
00297 {
00298
00299 $this->saveMaterialsToDb();
00300 if ($withanswers)
00301 {
00302 $this->saveCategoriesToDb();
00303 }
00304 }
00305 parent::saveToDb($original_id);
00306 }
00307
00308 function saveCategoriesToDb()
00309 {
00310
00311
00312
00313 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00314 $this->ilias->db->quote($this->id)
00315 );
00316 $result = $this->ilias->db->query($query);
00317
00318 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00319 {
00320 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
00321 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00322 $this->ilias->db->quote($category_id . ""),
00323 $this->ilias->db->quote($this->id . ""),
00324 $this->ilias->db->quote(($i + 1) . ""),
00325 $this->ilias->db->quote($i . "")
00326 );
00327 $answer_result = $this->ilias->db->query($query);
00328 }
00329 $this->saveCompletionStatus();
00330 }
00331
00340 function toXML($a_include_header = TRUE, $obligatory_state = "")
00341 {
00342 include_once("./classes/class.ilXmlWriter.php");
00343 $a_xml_writer = new ilXmlWriter;
00344 $a_xml_writer->xmlHeader();
00345 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
00346 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00347 if (!$a_include_header)
00348 {
00349 $pos = strpos($xml, "?>");
00350 $xml = substr($xml, $pos + 2);
00351 }
00352 return $xml;
00353 }
00354
00365 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
00366 {
00367 $attrs = array(
00368 "id" => $this->getId(),
00369 "title" => $this->getTitle(),
00370 "type" => $this->getQuestiontype(),
00371 "subtype" => $this->getSubtype(),
00372 "obligatory" => $this->getObligatory()
00373 );
00374 $a_xml_writer->xmlStartTag("question", $attrs);
00375
00376 $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
00377 $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
00378 $a_xml_writer->xmlStartTag("questiontext");
00379 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
00380 $a_xml_writer->xmlEndTag("questiontext");
00381
00382 $a_xml_writer->xmlStartTag("responses");
00383
00384 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00385 {
00386 $attrs = array(
00387 "id" => $i
00388 );
00389 switch ($this->getSubtype())
00390 {
00391 case 1:
00392 $a_xml_writer->xmlStartTag("response_single", $attrs);
00393 break;
00394 case 2:
00395 $a_xml_writer->xmlStartTag("response_multiple", $attrs);
00396 break;
00397 }
00398 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
00399 switch ($this->getSubtype())
00400 {
00401 case 1:
00402 $a_xml_writer->xmlEndTag("response_single");
00403 break;
00404 case 2:
00405 $a_xml_writer->xmlEndTag("response_multiple");
00406 break;
00407 }
00408 }
00409
00410 $a_xml_writer->xmlEndTag("responses");
00411
00412 if (count($this->material))
00413 {
00414 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
00415 {
00416 $attrs = array(
00417 "label" => $this->material["title"]
00418 );
00419 $a_xml_writer->xmlStartTag("material", $attrs);
00420 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00421 if (strcmp($matches[1], "") != 0)
00422 {
00423 $intlink = $this->material["internal_link"];
00424 }
00425 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
00426 $a_xml_writer->xmlEndTag("material");
00427 }
00428 }
00429
00430 $a_xml_writer->xmlStartTag("metadata");
00431 $a_xml_writer->xmlStartTag("metadatafield");
00432 $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
00433 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
00434 $a_xml_writer->xmlEndTag("metadatafield");
00435 $a_xml_writer->xmlEndTag("metadata");
00436
00437 $a_xml_writer->xmlEndTag("question");
00438 }
00439
00440 function syncWithOriginal()
00441 {
00442 global $ilDB;
00443 if ($this->original_id)
00444 {
00445 $complete = 0;
00446 if ($this->isComplete())
00447 {
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_nominal SET subtype = %s, orientation = %s WHERE question_fi = %s",
00461 $ilDB->quote($this->getSubType() . ""),
00462 $ilDB->quote($this->getOrientation() . ""),
00463 $ilDB->quote($this->original_id . "")
00464 );
00465 $result = $ilDB->query($query);
00466 if ($result == DB_OK) {
00467
00468
00469
00470 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00471 $ilDB->quote($this->original_id . "")
00472 );
00473 $result = $ilDB->query($query);
00474
00475
00476 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00477 {
00478 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
00479 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00480 $ilDB->quote($category_id . ""),
00481 $ilDB->quote($this->original_id . ""),
00482 $ilDB->quote(($i + 1) . ""),
00483 $ilDB->quote($i . "")
00484 );
00485 $answer_result = $ilDB->query($query);
00486 }
00487 }
00488 }
00489 parent::syncWithOriginal();
00490 }
00491
00500 function getQuestionType()
00501 {
00502 return "SurveyNominalQuestion";
00503 }
00504
00513 function getAdditionalTableName()
00514 {
00515 return "survey_question_nominal";
00516 }
00517
00526 function &getWorkingDataFromUserInput($post_data)
00527 {
00528 $entered_value = $post_data[$this->getId() . "_value"];
00529 $data = array();
00530 if ($this->getSubType() == SUBTYPE_MCMR)
00531 {
00532 if (is_array($entered_value))
00533 {
00534 foreach ($entered_value as $value)
00535 {
00536 array_push($data, array("value" => $value));
00537 }
00538 }
00539 }
00540 else
00541 {
00542 array_push($data, array("value" => $entered_value));
00543 }
00544 return $data;
00545 }
00546
00559 function checkUserInput($post_data, $survey_id)
00560 {
00561
00562
00563 $entered_value = $post_data[$this->getId() . "_value"];
00564 if ($this->getSubType() == SUBTYPE_MCMR)
00565 {
00566 if (!$this->getObligatory($survey_id)) return "";
00567
00568 if (!is_array($entered_value))
00569 {
00570 return $this->lng->txt("nominal_question_mr_not_checked");
00571 }
00572 }
00573 else
00574 {
00575 if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
00576
00577 if (strlen($entered_value) == 0) return $this->lng->txt("nominal_question_not_checked");
00578 }
00579 return "";
00580 }
00581
00582 function saveUserInput($post_data, $active_id)
00583 {
00584 global $ilDB;
00585
00586 if (is_array($post_data[$this->getId() . "_value"]))
00587 {
00588 foreach ($post_data[$this->getId() . "_value"] as $value)
00589 {
00590 $entered_value = $value;
00591 if (strlen($entered_value) > 0)
00592 {
00593 $entered_value = $ilDB->quote($entered_value . "");
00594 $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00595 $ilDB->quote($this->getId() . ""),
00596 $ilDB->quote($active_id . ""),
00597 $entered_value,
00598 "NULL"
00599 );
00600 $result = $ilDB->query($query);
00601 }
00602 }
00603 }
00604 else
00605 {
00606 $entered_value = $post_data[$this->getId() . "_value"];
00607 if (strlen($entered_value) == 0) return;
00608 $entered_value = $ilDB->quote($entered_value . "");
00609 $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00610 $ilDB->quote($this->getId() . ""),
00611 $ilDB->quote($active_id . ""),
00612 $entered_value,
00613 "NULL"
00614 );
00615 $result = $ilDB->query($query);
00616 }
00617 }
00618
00619 function &getCumulatedResults($survey_id, $nr_of_users)
00620 {
00621 global $ilDB;
00622
00623 $question_id = $this->getId();
00624
00625 $result_array = array();
00626 $cumulated = array();
00627
00628 $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",
00629 $ilDB->quote($question_id),
00630 $ilDB->quote($survey_id)
00631 );
00632 $result = $ilDB->query($query);
00633 $numrows = $result->numRows();
00634
00635
00636 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00637 {
00638 $cumulated["$row->value"]++;
00639 }
00640 asort($cumulated, SORT_NUMERIC);
00641 end($cumulated);
00642
00643 if ($this->getSubType() == SUBTYPE_MCMR)
00644 {
00645 $query = sprintf("SELECT survey_answer.answer_id, concat( survey_answer.question_fi, \"_\", survey_answer.active_fi) AS groupval 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 GROUP BY groupval",
00646 $ilDB->quote($question_id),
00647 $ilDB->quote($survey_id)
00648 );
00649 $mcmr_result = $ilDB->query($query);
00650 $result_array["USERS_ANSWERED"] = $mcmr_result->numRows();
00651 $result_array["USERS_SKIPPED"] = $nr_of_users - $mcmr_result->numRows();
00652 $numrows = $mcmr_result->numRows();
00653 }
00654 else
00655 {
00656 $result_array["USERS_ANSWERED"] = $result->numRows();
00657 $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
00658 }
00659 $result_array["MEDIAN"] = "";
00660 $result_array["ARITHMETIC_MEAN"] = "";
00661 $prefix = "";
00662 if (strcmp(key($cumulated), "") != 0)
00663 {
00664 $prefix = (key($cumulated)+1) . " - ";
00665 }
00666 $result_array["MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
00667 $result_array["MODE_VALUE"] = key($cumulated)+1;
00668 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
00669 $result_array["QUESTION_TYPE"] = "SurveyNominalQuestion";
00670 $maxvalues = 0;
00671 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
00672 {
00673 $maxvalues += $cumulated[$key];
00674 }
00675 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
00676 {
00677 $percentage = 0;
00678 if ($numrows > 0)
00679 {
00680 if ($this->getSubType() == SUBTYPE_MCMR)
00681 {
00682 if ($maxvalues > 0)
00683 {
00684 $percentage = ($result_array["USERS_ANSWERED"] > 0) ? (float)((int)$cumulated[$key]/$result_array["USERS_ANSWERED"]) : 0;
00685 }
00686 }
00687 else
00688 {
00689 $percentage = ($numrows > 0) ? (float)((int)$cumulated[$key]/$numrows) : 0;
00690 }
00691 }
00692 $result_array["variables"][$key] = array("title" => $this->categories->getCategory($key), "selected" => (int)$cumulated[$key], "percentage" => $percentage);
00693 }
00694 return $result_array;
00695 }
00696
00708 function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
00709 {
00710 include_once ("./classes/class.ilExcelUtils.php");
00711 $worksheet =& $workbook->addWorksheet();
00712 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
00713 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
00714 $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
00715 $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
00716 $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
00717 $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
00718 $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
00719 $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
00720 $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
00721 $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
00722 $rowcounter = 5;
00723
00724 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
00725 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
00726 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
00727 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
00728 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
00729 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
00730 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
00731 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
00732 $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
00733 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
00734 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
00735 foreach ($eval_data["variables"] as $key => $value)
00736 {
00737 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
00738 $worksheet->write($rowcounter, 2, $key+1);
00739 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
00740 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
00741 }
00742 }
00743
00752 function addUserSpecificResultsExportTitles(&$a_array)
00753 {
00754 parent::addUserSpecificResultsExportTitles($a_array);
00755 if ($this->getSubtype() == SUBTYPE_MCMR)
00756 {
00757 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
00758 {
00759 $category = $this->categories->getCategory($index);
00760 array_push($a_array, ($index+1) . " - $category");
00761 }
00762 }
00763 }
00764
00774 function addUserSpecificResultsData(&$a_array, &$resultset)
00775 {
00776 if (count($resultset["answers"][$this->getId()]))
00777 {
00778 if ($this->getSubtype() == SUBTYPE_MCMR)
00779 {
00780 array_push($a_array, "");
00781 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
00782 {
00783 $category = $this->categories->getCategory($index);
00784 $found = 0;
00785 foreach ($resultset["answers"][$this->getId()] as $answerdata)
00786 {
00787 if (strcmp($index, $answerdata["value"]) == 0)
00788 {
00789 $found = 1;
00790 }
00791 }
00792 if ($found)
00793 {
00794 array_push($a_array, "1");
00795 }
00796 else
00797 {
00798 array_push($a_array, "0");
00799 }
00800 }
00801 }
00802 else
00803 {
00804 array_push($a_array, $resultset["answers"][$this->getId()][0]["value"]+1);
00805 }
00806 }
00807 else
00808 {
00809 array_push($a_array, $this->lng->txt("skipped"));
00810 if ($this->getSubtype() == SUBTYPE_MCMR)
00811 {
00812 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
00813 {
00814 array_push($a_array, "");
00815 }
00816 }
00817 }
00818 }
00819
00829 function &getUserAnswers($survey_id)
00830 {
00831 global $ilDB;
00832
00833 $answers = array();
00834
00835 $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",
00836 $ilDB->quote($survey_id),
00837 $ilDB->quote($this->getId())
00838 );
00839 $result = $ilDB->query($query);
00840 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00841 {
00842 $category = $this->categories->getCategory($row["value"]);
00843 if (!is_array($answers[$row["active_fi"]]))
00844 {
00845 $answers[$row["active_fi"]] = array();
00846 }
00847 array_push($answers[$row["active_fi"]], $row["value"] + 1 . " - " . $category);
00848 }
00849 return $answers;
00850 }
00851
00862 function importAdditionalMetadata($a_meta)
00863 {
00864 foreach ($a_meta as $key => $value)
00865 {
00866 switch ($value["label"])
00867 {
00868 case "orientation":
00869 $this->setOrientation($value["entry"]);
00870 break;
00871 }
00872 }
00873 }
00874
00883 function importResponses($a_data)
00884 {
00885 foreach ($a_data as $id => $data)
00886 {
00887 $categorytext = "";
00888 foreach ($data["material"] as $material)
00889 {
00890 $categorytext .= $material["text"];
00891 }
00892 $this->categories->addCategory($categorytext);
00893 }
00894 }
00895
00904 function usableForPrecondition()
00905 {
00906 return TRUE;
00907 }
00908
00917 function getAvailableRelations()
00918 {
00919 return array("=", "<>");
00920 }
00921
00930 function getPreconditionSelectValue($default = "")
00931 {
00932 global $lng;
00933
00934 include_once "./classes/class.ilTemplate.php";
00935 $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_combobox.html", TRUE, TRUE, "Modules/Survey");
00936 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00937 {
00938 $template->setCurrentBlock("option_v");
00939 $template->setVariable("OPTION_VALUE", $i);
00940 $template->setVariable("OPTION_TEXT", ($i+1) . " - " . $this->categories->getCategory($i));
00941 if ($i == $default)
00942 {
00943 $template->setVariable("OPTION_CHECKED", " selected=\"selected\"");
00944 }
00945 $template->parseCurrentBlock();
00946 }
00947 $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("select_value"));
00948 return $template->get();
00949 }
00950
00960 function getPreconditionValueOutput($value)
00961 {
00962 return ($value + 1) . " - " . $this->categories->getCategory($value);
00963 }
00964
00965
00976 function outChart($survey_id, $type = "")
00977 {
00978 if (count($this->cumulated) == 0)
00979 {
00980 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00981 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00982 $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
00983 }
00984
00985 foreach ($this->cumulated["variables"] as $key => $value)
00986 {
00987 foreach ($value as $key2 => $value2)
00988 {
00989 $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
00990 }
00991 }
00992 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
00993 $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"]);
00994 }
00995 }
00996 ?>