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 "./survey/classes/class.SurveyQuestion.php";
00025 include_once "./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 "./survey/classes/class.SurveyCategories.php";
00072 $this->orientation = $orientation;
00073 $this->categories = new SurveyCategories();
00074 }
00075
00085 function &getAvailablePhrases($useronly = 0)
00086 {
00087 global $ilUser;
00088 global $ilDB;
00089
00090 $phrases = array();
00091 $query = sprintf("SELECT * FROM survey_phrase WHERE defaultvalue = '1' OR owner_fi = %s ORDER BY title",
00092 $ilDB->quote($ilUser->id)
00093 );
00094 $result = $ilDB->query($query);
00095 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00096 {
00097 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
00098 {
00099 if (!$useronly)
00100 {
00101 $phrases[$row->phrase_id] = array(
00102 "title" => $this->lng->txt($row->title),
00103 "owner" => $row->owner_fi
00104 );
00105 }
00106 }
00107 else
00108 {
00109 if ($ilUser->getId() == $row->owner_fi)
00110 {
00111 $phrases[$row->phrase_id] = array(
00112 "title" => $row->title,
00113 "owner" => $row->owner_fi
00114 );
00115 }
00116 }
00117 }
00118 return $phrases;
00119 }
00120
00130 function &getCategoriesForPhrase($phrase_id)
00131 {
00132 global $ilDB;
00133 $categories = array();
00134 $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",
00135 $ilDB->quote($phrase_id)
00136 );
00137 $result = $ilDB->query($query);
00138 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00139 {
00140 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
00141 {
00142 $categories[$row->category_id] = $this->lng->txt($row->title);
00143 }
00144 else
00145 {
00146 $categories[$row->category_id] = $row->title;
00147 }
00148 }
00149 return $categories;
00150 }
00151
00160 function addPhrase($phrase_id)
00161 {
00162 global $ilUser;
00163 global $ilDB;
00164
00165 $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",
00166 $ilDB->quote($phrase_id),
00167 $ilDB->quote($ilUser->id)
00168 );
00169 $result = $ilDB->query($query);
00170 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00171 {
00172 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
00173 {
00174 $this->categories->addCategory($this->lng->txt($row->title));
00175 }
00176 else
00177 {
00178 $this->categories->addCategory($row->title);
00179 }
00180 }
00181 }
00182
00192 function _getQuestionDataArray($id)
00193 {
00194 global $ilDB;
00195
00196 $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",
00197 $ilDB->quote($id)
00198 );
00199 $result = $ilDB->query($query);
00200 if ($result->numRows() == 1)
00201 {
00202 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00203 }
00204 else
00205 {
00206 return array();
00207 }
00208 }
00209
00218 function loadFromDb($id)
00219 {
00220 global $ilDB;
00221 $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",
00222 $ilDB->quote($id)
00223 );
00224 $result = $ilDB->query($query);
00225 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00226 {
00227 if ($result->numRows() == 1)
00228 {
00229 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00230 $this->id = $data->question_id;
00231 $this->title = $data->title;
00232 $this->description = $data->description;
00233 $this->obj_id = $data->obj_fi;
00234 $this->orientation = $data->orientation;
00235 $this->author = $data->author;
00236 $this->owner = $data->owner_fi;
00237 include_once("./Services/RTE/classes/class.ilRTE.php");
00238 $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
00239 $this->obligatory = $data->obligatory;
00240 $this->complete = $data->complete;
00241 $this->original_id = $data->original_id;
00242 }
00243
00244 $this->loadMaterialFromDb($id);
00245
00246 $this->categories->flushCategories();
00247
00248 $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",
00249 $ilDB->quote($id)
00250 );
00251 $result = $ilDB->query($query);
00252 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00253 {
00254 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00255 {
00256 $this->categories->addCategory($data->title);
00257 }
00258 }
00259 }
00260 parent::loadFromDb($id);
00261 }
00262
00271 function isComplete()
00272 {
00273 if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
00274 {
00275 return 1;
00276 }
00277 else
00278 {
00279 return 0;
00280 }
00281 }
00282
00290 function saveToDb($original_id = "", $withanswers = true)
00291 {
00292 global $ilDB;
00293 $complete = 0;
00294 if ($this->isComplete()) {
00295 $complete = 1;
00296 }
00297 if ($original_id)
00298 {
00299 $original_id = $ilDB->quote($original_id);
00300 }
00301 else
00302 {
00303 $original_id = "NULL";
00304 }
00305
00306
00307 include_once("./Services/RTE/classes/class.ilRTE.php");
00308 ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
00309 $this->getId());
00310
00311 if ($this->id == -1)
00312 {
00313
00314 $now = getdate();
00315 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00316 $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)",
00317 $ilDB->quote($this->getQuestionType()),
00318 $ilDB->quote($this->obj_id),
00319 $ilDB->quote($this->owner),
00320 $ilDB->quote($this->title),
00321 $ilDB->quote($this->description),
00322 $ilDB->quote($this->author),
00323 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00324 $ilDB->quote(sprintf("%d", $this->obligatory)),
00325 $ilDB->quote("$complete"),
00326 $ilDB->quote($created),
00327 $original_id
00328 );
00329 $result = $ilDB->query($query);
00330 if ($result == DB_OK)
00331 {
00332 $this->id = $ilDB->getLastInsertId();
00333 $query = sprintf("INSERT INTO survey_question_ordinal (question_fi, orientation) VALUES (%s, %s)",
00334 $ilDB->quote($this->id . ""),
00335 $ilDB->quote(sprintf("%d", $this->orientation))
00336 );
00337 $ilDB->query($query);
00338 }
00339 }
00340 else
00341 {
00342
00343 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00344 $ilDB->quote($this->title),
00345 $ilDB->quote($this->description),
00346 $ilDB->quote($this->author),
00347 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
00348 $ilDB->quote(sprintf("%d", $this->obligatory)),
00349 $ilDB->quote("$complete"),
00350 $ilDB->quote($this->id)
00351 );
00352 $result = $ilDB->query($query);
00353 $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
00354 $ilDB->quote(sprintf("%d", $this->orientation)),
00355 $ilDB->quote($this->id . "")
00356 );
00357 $result = $ilDB->query($query);
00358 }
00359 if ($result == DB_OK)
00360 {
00361
00362 $this->saveMaterialsToDb();
00363 if ($withanswers)
00364 {
00365 $this->saveCategoriesToDb();
00366 }
00367 }
00368 parent::saveToDb($original_id);
00369 }
00370
00380 function from_xml($xml_text)
00381 {
00382 $result = false;
00383 if (!empty($this->domxml))
00384 {
00385 $this->domxml->free();
00386 }
00387 $xml_text = preg_replace("/>\s*?</", "><", $xml_text);
00388 $this->domxml = domxml_open_mem($xml_text);
00389 if (!empty($this->domxml))
00390 {
00391 $root = $this->domxml->document_element();
00392 $item = $root->first_child();
00393 $this->setTitle($item->get_attribute("title"));
00394 $this->gaps = array();
00395 $itemnodes = $item->child_nodes();
00396 foreach ($itemnodes as $index => $node)
00397 {
00398 switch ($node->node_name())
00399 {
00400 case "qticomment":
00401 $comment = $node->get_content();
00402 if (strpos($comment, "ILIAS Version=") !== false)
00403 {
00404 }
00405 elseif (strpos($comment, "Questiontype=") !== false)
00406 {
00407 }
00408 elseif (strpos($comment, "Author=") !== false)
00409 {
00410 $comment = str_replace("Author=", "", $comment);
00411 $this->setAuthor($comment);
00412 }
00413 else
00414 {
00415 $this->setDescription($comment);
00416 }
00417 break;
00418 case "itemmetadata":
00419 $qtimetadata = $node->first_child();
00420 $metadata_fields = $qtimetadata->child_nodes();
00421 foreach ($metadata_fields as $index => $metadata_field)
00422 {
00423 $fieldlabel = $metadata_field->first_child();
00424 $fieldentry = $fieldlabel->next_sibling();
00425 switch ($fieldlabel->get_content())
00426 {
00427 case "obligatory":
00428 $this->setObligatory($fieldentry->get_content());
00429 break;
00430 case "orientation":
00431 $this->setOrientation($fieldentry->get_content());
00432 break;
00433 }
00434 }
00435 break;
00436 case "presentation":
00437 $flow = $node->first_child();
00438 $flownodes = $flow->child_nodes();
00439 foreach ($flownodes as $idx => $flownode)
00440 {
00441 if (strcmp($flownode->node_name(), "material") == 0)
00442 {
00443 $mattext = $flownode->first_child();
00444 $this->setQuestiontext($mattext->get_content());
00445 }
00446 elseif (strcmp($flownode->node_name(), "response_lid") == 0)
00447 {
00448 $ident = $flownode->get_attribute("ident");
00449 $shuffle = "";
00450
00451 $response_lid_nodes = $flownode->child_nodes();
00452 foreach ($response_lid_nodes as $resp_lid_id => $resp_lid_node)
00453 {
00454 switch ($resp_lid_node->node_name())
00455 {
00456 case "render_choice":
00457 $render_choice = $resp_lid_node;
00458 $labels = $render_choice->child_nodes();
00459 foreach ($labels as $lidx => $response_label)
00460 {
00461 $material = $response_label->first_child();
00462 $mattext = $material->first_child();
00463 $shuf = 0;
00464 $this->categories->addCategoryAtPosition($mattext->get_content(), $response_label->get_attribute("ident"));
00465 }
00466 break;
00467 case "material":
00468 $matlabel = $resp_lid_node->get_attribute("label");
00469 $mattype = $resp_lid_node->first_child();
00470 if (strcmp($mattype->node_name(), "mattext") == 0)
00471 {
00472 $material = $mattype->get_content();
00473 if ($material)
00474 {
00475 if ($this->getId() < 1)
00476 {
00477 $this->saveToDb();
00478 }
00479 $this->setMaterial($material, true, $matlabel);
00480 }
00481 }
00482 break;
00483 }
00484 }
00485 }
00486 }
00487 break;
00488 }
00489 }
00490 $result = true;
00491 }
00492 return $result;
00493 }
00494
00504 function to_xml($a_include_header = true, $obligatory_state = "")
00505 {
00506 include_once("./classes/class.ilXmlWriter.php");
00507 $a_xml_writer = new ilXmlWriter;
00508
00509 $a_xml_writer->xmlHeader();
00510 $a_xml_writer->xmlStartTag("questestinterop");
00511 $attrs = array(
00512 "ident" => $this->getId(),
00513 "title" => $this->getTitle()
00514 );
00515 $a_xml_writer->xmlStartTag("item", $attrs);
00516
00517 $a_xml_writer->xmlElement("qticomment", NULL, $this->getDescription());
00518 $a_xml_writer->xmlElement("qticomment", NULL, "ILIAS Version=".$this->ilias->getSetting("ilias_version"));
00519 $a_xml_writer->xmlElement("qticomment", NULL, "Questiontype=".ORDINAL_QUESTION_IDENTIFIER);
00520 $a_xml_writer->xmlElement("qticomment", NULL, "Author=".$this->getAuthor());
00521
00522 $a_xml_writer->xmlStartTag("itemmetadata");
00523 $a_xml_writer->xmlStartTag("qtimetadata");
00524 $a_xml_writer->xmlStartTag("qtimetadatafield");
00525 $a_xml_writer->xmlElement("fieldlabel", NULL, "obligatory");
00526 if (strcmp($obligatory_state, "") != 0)
00527 {
00528 $this->setObligatory($obligatory_state);
00529 }
00530 $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getObligatory()));
00531 $a_xml_writer->xmlEndTag("qtimetadatafield");
00532 $a_xml_writer->xmlStartTag("qtimetadatafield");
00533 $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
00534 $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getOrientation()));
00535 $a_xml_writer->xmlEndTag("qtimetadatafield");
00536 $a_xml_writer->xmlEndTag("qtimetadata");
00537 $a_xml_writer->xmlEndTag("itemmetadata");
00538
00539
00540 $attrs = array(
00541 "label" => $this->getTitle()
00542 );
00543 $a_xml_writer->xmlStartTag("presentation", $attrs);
00544
00545 $a_xml_writer->xmlStartTag("flow");
00546
00547 $this->addQTIMaterial($a_xml_writer, $this->getQuestiontext());
00548
00549 $attrs = array(
00550 "ident" => "MCSR",
00551 "rcardinality" => "Single"
00552 );
00553 $a_xml_writer->xmlStartTag("response_lid", $attrs);
00554
00555 if (count($this->material))
00556 {
00557 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
00558 {
00559 $attrs = array(
00560 "label" => $this->material["title"]
00561 );
00562 $a_xml_writer->xmlStartTag("material", $attrs);
00563 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00564 if (strcmp($matches[1], "") != 0)
00565 {
00566 $intlink = $this->material["internal_link"];
00567 }
00568 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
00569 $a_xml_writer->xmlEndTag("material");
00570 }
00571 }
00572
00573 $attrs = array(
00574 "shuffle" => "no"
00575 );
00576 $a_xml_writer->xmlStartTag("render_choice", $attrs);
00577
00578
00579 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
00580 {
00581 $category = $this->categories->getCategory($index);
00582 $attrs = array(
00583 "ident" => "$index"
00584 );
00585 $a_xml_writer->xmlStartTag("response_label", $attrs);
00586 $a_xml_writer->xmlStartTag("material");
00587 $a_xml_writer->xmlElement("mattext", NULL, $category);
00588 $a_xml_writer->xmlEndTag("material");
00589 $a_xml_writer->xmlEndTag("response_label");
00590 }
00591 $a_xml_writer->xmlEndTag("render_choice");
00592 $a_xml_writer->xmlEndTag("response_lid");
00593 $a_xml_writer->xmlEndTag("flow");
00594 $a_xml_writer->xmlEndTag("presentation");
00595 $a_xml_writer->xmlEndTag("item");
00596 $a_xml_writer->xmlEndTag("questestinterop");
00597
00598 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00599 if (!$a_include_header)
00600 {
00601 $pos = strpos($xml, "?>");
00602 $xml = substr($xml, $pos + 2);
00603 }
00604 return $xml;
00605 }
00606
00607 function syncWithOriginal()
00608 {
00609 global $ilDB;
00610 if ($this->original_id)
00611 {
00612 $complete = 0;
00613 if ($this->isComplete()) {
00614 $complete = 1;
00615 }
00616 $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
00617 $ilDB->quote($this->title . ""),
00618 $ilDB->quote($this->description . ""),
00619 $ilDB->quote($this->author . ""),
00620 $ilDB->quote($this->questiontext . ""),
00621 $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
00622 $ilDB->quote($complete . ""),
00623 $ilDB->quote($this->original_id . "")
00624 );
00625 $result = $ilDB->query($query);
00626 $query = sprintf("UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
00627 $ilDB->quote($this->getOrientation() . ""),
00628 $ilDB->quote($this->original_id . "")
00629 );
00630 $result = $ilDB->query($query);
00631 if ($result == DB_OK) {
00632
00633
00634
00635 $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
00636 $ilDB->quote($this->original_id . "")
00637 );
00638 $result = $ilDB->query($query);
00639
00640 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
00641 {
00642 $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
00643 $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
00644 $ilDB->quote($category_id . ""),
00645 $ilDB->quote($this->original_id . ""),
00646 $ilDB->quote(($i + 1) . ""),
00647 $ilDB->quote($i . "")
00648 );
00649 $answer_result = $ilDB->query($query);
00650 }
00651 }
00652 }
00653 parent::syncWithOriginal();
00654 }
00655
00665 function addStandardNumbers($lower_limit, $upper_limit)
00666 {
00667 for ($i = $lower_limit; $i <= $upper_limit; $i++)
00668 {
00669 $this->categories->addCategory($i);
00670 }
00671 }
00672
00682 function savePhrase($phrases, $title)
00683 {
00684 global $ilUser;
00685 global $ilDB;
00686
00687 $query = sprintf("INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00688 $ilDB->quote($title . ""),
00689 $ilDB->quote("1"),
00690 $ilDB->quote($ilUser->id . "")
00691 );
00692 $result = $ilDB->query($query);
00693 $phrase_id = $ilDB->getLastInsertId();
00694
00695 $counter = 1;
00696 foreach ($phrases as $category)
00697 {
00698 $query = sprintf("INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00699 $ilDB->quote($this->categories->getCategory($category) . ""),
00700 $ilDB->quote("1"),
00701 $ilDB->quote($ilUser->id . "")
00702 );
00703 $result = $ilDB->query($query);
00704 $category_id = $ilDB->getLastInsertId();
00705 $query = sprintf("INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
00706 $ilDB->quote($phrase_id . ""),
00707 $ilDB->quote($category_id . ""),
00708 $ilDB->quote($counter . "")
00709 );
00710 $result = $ilDB->query($query);
00711 $counter++;
00712 }
00713 }
00714
00723 function getQuestionType()
00724 {
00725 return 2;
00726 }
00727
00736 function getAdditionalTableName()
00737 {
00738 return "survey_question_ordinal";
00739 }
00740
00741 function checkUserInput($post_data)
00742 {
00743 $entered_value = $post_data[$this->getId() . "_value"];
00744
00745 if ((!$this->getObligatory()) && (strlen($entered_value) == 0)) return "";
00746
00747 if (strlen($entered_value) == 0) return $this->lng->txt("ordinal_question_not_checked");
00748
00749 return "";
00750 }
00751
00752 function saveUserInput($post_data, $survey_id, $user_id, $anonymous_id)
00753 {
00754 global $ilDB;
00755
00756 $entered_value = $post_data[$this->getId() . "_value"];
00757 if (strlen($entered_value) == 0) return;
00758 $entered_value = $ilDB->quote($entered_value . "");
00759 $query = sprintf("INSERT INTO survey_answer (answer_id, survey_fi, question_fi, user_fi, anonymous_id, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, NULL)",
00760 $ilDB->quote($survey_id . ""),
00761 $ilDB->quote($this->getId() . ""),
00762 $ilDB->quote($user_id . ""),
00763 $ilDB->quote($anonymous_id . ""),
00764 $entered_value,
00765 "NULL"
00766 );
00767 $result = $ilDB->query($query);
00768 }
00769
00770 function &getCumulatedResults($survey_id, $nr_of_users)
00771 {
00772 global $ilDB;
00773
00774 $question_id = $this->getId();
00775
00776 $result_array = array();
00777 $cumulated = array();
00778
00779 $query = sprintf("SELECT * FROM survey_answer WHERE question_fi = %s AND survey_fi = %s",
00780 $ilDB->quote($question_id),
00781 $ilDB->quote($survey_id)
00782 );
00783 $result = $ilDB->query($query);
00784
00785 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00786 {
00787 $cumulated["$row->value"]++;
00788 }
00789 asort($cumulated, SORT_NUMERIC);
00790 end($cumulated);
00791 $numrows = $result->numRows();
00792 $result_array["USERS_ANSWERED"] = $result->numRows();
00793 $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
00794
00795 $prefix = "";
00796 if (strcmp(key($cumulated), "") != 0)
00797 {
00798 $prefix = (key($cumulated)+1) . " - ";
00799 }
00800 $result_array["MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
00801 $result_array["MODE_VALUE"] = key($cumulated)+1;
00802 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
00803 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
00804 {
00805 $percentage = 0;
00806 if ($numrows > 0)
00807 {
00808 $percentage = (float)((int)$cumulated[$key]/$numrows);
00809 }
00810 $result_array["variables"][$key] = array("title" => $this->categories->getCategory($key), "selected" => (int)$cumulated[$key], "percentage" => $percentage);
00811 }
00812 ksort($cumulated, SORT_NUMERIC);
00813 $median = array();
00814 $total = 0;
00815 foreach ($cumulated as $value => $key)
00816 {
00817 $total += $key;
00818 for ($i = 0; $i < $key; $i++)
00819 {
00820 array_push($median, $value+1);
00821 }
00822 }
00823 if ($total > 0)
00824 {
00825 if (($total % 2) == 0)
00826 {
00827 $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
00828 if (round($median_value) != $median_value)
00829 {
00830 $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) . ")";
00831 }
00832 }
00833 else
00834 {
00835 $median_value = $median[(($total+1)/2)-1];
00836 }
00837 }
00838 else
00839 {
00840 $median_value = "";
00841 }
00842 $result_array["ARITHMETIC_MEAN"] = "";
00843 $result_array["MEDIAN"] = $median_value;
00844 $result_array["QUESTION_TYPE"] = "SurveyOrdinalQuestion";
00845 return $result_array;
00846 }
00847
00848 }
00849 ?>