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.SurveyQuestionGUI.php";
00025 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00026
00038 class SurveyMetricQuestionGUI extends SurveyQuestionGUI
00039 {
00048 function SurveyMetricQuestionGUI(
00049 $id = -1
00050 )
00051
00052 {
00053 $this->SurveyQuestionGUI();
00054 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMetricQuestion.php";
00055 $this->object = new SurveyMetricQuestion();
00056 if ($id >= 0)
00057 {
00058 $this->object->loadFromDb($id);
00059 }
00060 }
00061
00069 function editQuestion()
00070 {
00071 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_metric.html", "Modules/SurveyQuestionPool");
00072 $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
00073 $internallinks = array(
00074 "lm" => $this->lng->txt("obj_lm"),
00075 "st" => $this->lng->txt("obj_st"),
00076 "pg" => $this->lng->txt("obj_pg"),
00077 "glo" => $this->lng->txt("glossary_term")
00078 );
00079 foreach ($internallinks as $key => $value)
00080 {
00081 $this->tpl->setCurrentBlock("internallink");
00082 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00083 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00084 $this->tpl->parseCurrentBlock();
00085 }
00086
00087 $this->tpl->setCurrentBlock("adm_content");
00088 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00089 if (count($this->object->material))
00090 {
00091 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00092 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00093 $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00094 $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00095 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00096 $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00097 $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00098 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00099 }
00100 else
00101 {
00102 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00103 }
00104 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00105 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00106 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00107 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00108 $questiontext = $this->object->getQuestiontext();
00109 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00110 $this->tpl->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
00111 $this->tpl->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
00112 $this->tpl->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
00113 $this->tpl->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
00114 $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt("subtype"));
00115 $this->tpl->setVariable("DESCRIPTION_NONRATIO", $this->lng->txt("metric_subtype_description_interval"));
00116 $this->tpl->setVariable("TEXT_NONRATIO", $this->lng->txt("non_ratio"));
00117 $this->tpl->setVariable("DESCRIPTION_RATIONONABSOLUTE", $this->lng->txt("metric_subtype_description_rationonabsolute"));
00118 $this->tpl->setVariable("TEXT_RATIONONABSOLUTE", $this->lng->txt("ratio_non_absolute"));
00119 $this->tpl->setVariable("DESCRIPTION_RATIOABSOLUTE", $this->lng->txt("metric_subtype_description_ratioabsolute"));
00120 $this->tpl->setVariable("TEXT_RATIOABSOLUTE", $this->lng->txt("ratio_absolute"));
00121 if ($this->object->getSubtype() == SUBTYPE_NON_RATIO)
00122 {
00123 $this->tpl->setVariable("CHECKED_NONRATIO", " checked=\"checked\"");
00124 }
00125 else if ($this->object->getSubtype() == SUBTYPE_RATIO_NON_ABSOLUTE)
00126 {
00127 $this->tpl->setVariable("CHECKED_RATIONONABSOLUTE", " checked=\"checked\"");
00128 }
00129 else if ($this->object->getSubtype() == SUBTYPE_RATIO_ABSOLUTE)
00130 {
00131 $this->tpl->setVariable("CHECKED_RATIOABSOLUTE", " checked=\"checked\"");
00132 }
00133 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00134 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00135 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00136 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00137 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00138 if ($this->object->getObligatory())
00139 {
00140 $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00141 }
00142 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00143 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00144 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00145 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00146 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
00147 $this->tpl->parseCurrentBlock();
00148 include_once "./Services/RTE/classes/class.ilRTE.php";
00149 $rtestring = ilRTE::_getRTEClassname();
00150 include_once "./Services/RTE/classes/class.$rtestring.php";
00151 $rte = new $rtestring();
00152 $rte->addPlugin("latex");
00153 $rte->addButton("latex"); $rte->addButton("pastelatex");
00154 $rte->removePlugin("ibrowser");
00155 include_once "./classes/class.ilObject.php";
00156 $obj_id = $_GET["q_id"];
00157 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00158 $rte->addRTESupport($obj_id, $obj_type, "survey");
00159 }
00160
00169 function writePostData()
00170 {
00171 $result = 0;
00172 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00173 $result = 1;
00174
00175
00176 if ($_POST["id"] > 0)
00177 $this->object->setId($_POST["id"]);
00178
00179 include_once "./Services/Utilities/classes/class.ilUtil.php";
00180 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00181 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00182 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00183 if (strlen($_POST["material"]))
00184 {
00185 $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00186 }
00187 include_once "./classes/class.ilObjAdvancedEditing.php";
00188 $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
00189 $this->object->setQuestiontext($questiontext);
00190 if ($_POST["obligatory"])
00191 {
00192 $this->object->setObligatory(1);
00193 }
00194 else
00195 {
00196 $this->object->setObligatory(0);
00197 }
00198 $this->object->setSubtype($_POST["type"]);
00199 $minimum = $_POST["minimum"];
00200 if ($this->object->getSubtype() > 3)
00201 {
00202 if ($minimum < 0)
00203 {
00204 $this->errormessage = $this->lng->txt("ratio_scale_ge_zero");
00205 $result = 1;
00206 }
00207 }
00208 $this->object->setMinimum($minimum);
00209 $this->object->setMaximum($_POST["maximum"]);
00210
00211 if ($saved) {
00212
00213
00214
00215
00216 $this->object->saveToDb();
00217 }
00218 return $result;
00219 }
00220
00228 function getPrintView($question_title = 1, $show_questiontext = 1)
00229 {
00230 $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00231 $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00249 if ($show_questiontext)
00250 {
00251 $questiontext = $this->object->getQuestiontext();
00252 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00253 }
00254 if (! $this->object->getObligatory())
00255 {
00256 $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00257 }
00258 if ($question_title)
00259 {
00260 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00261 }
00262 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00263 $template->setVariable("QUESTION_ID", $this->object->getId());
00264
00265 $solution_text = "";
00266 $len = 10;
00267 for ($i = 0; $i < 10; $i++) $solution_text .= " ";
00268 $template->setVariable("TEXT_SOLUTION", $solution_text);
00269
00270 $template->parseCurrentBlock();
00271 return $template->get();
00272 }
00273
00281 function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
00282 {
00283 $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00284 if (count($this->object->material))
00285 {
00286 $template->setCurrentBlock("material_metric");
00287 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00288 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00289 $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00290 $template->parseCurrentBlock();
00291 }
00292 $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00309 if ($show_questiontext)
00310 {
00311 $questiontext = $this->object->getQuestiontext();
00312 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00313 }
00314 if (! $this->object->getObligatory())
00315 {
00316 $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00317 }
00318 if ($question_title)
00319 {
00320 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00321 }
00322 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00323 $template->setVariable("QUESTION_ID", $this->object->getId());
00324 if (is_array($working_data))
00325 {
00326 $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
00327 }
00328
00329 $template->setVariable("INPUT_SIZE", 10);
00330
00331 if (strcmp($error_message, "") != 0)
00332 {
00333 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00334 }
00335 $template->parseCurrentBlock();
00336 return $template->get();
00337 }
00338
00346 function preview()
00347 {
00348 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
00349 $question_output = $this->getWorkingForm();
00350 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
00351 $this->tpl->parseCurrentBlock();
00352 }
00353
00354 function setQuestionTabs()
00355 {
00356 $this->setQuestionTabsForClass("surveymetricquestiongui");
00357 }
00358
00367 function getCumulatedResultRow($counter, $css_class, $survey_id)
00368 {
00369 include_once "./classes/class.ilTemplate.php";
00370 if (count($this->cumulated) == 0)
00371 {
00372 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00373 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00374 $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00375 }
00376 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
00377 $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
00378 $maxlen = 37;
00379 $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
00380 if (strlen($questiontext) > $maxlen + 3)
00381 {
00382 $questiontext = substr($questiontext, 0, $maxlen) . "...";
00383 }
00384 $template->setVariable("QUESTION_TEXT", $questiontext);
00385 $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
00386 $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
00387 $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
00388 $template->setVariable("MODE", $this->cumulated["MODE"]);
00389 $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
00390 $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
00391 $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
00392 $template->setVariable("COLOR_CLASS", $css_class);
00393 return $template->get();
00394 }
00395
00406 function getCumulatedResultsDetails($survey_id, $counter)
00407 {
00408 if (count($this->cumulated) == 0)
00409 {
00410 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00411 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00412 $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00413 }
00414
00415 $output = "";
00416 include_once "./classes/class.ilTemplate.php";
00417 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
00418
00419 $template->setCurrentBlock("detail_row");
00420 $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
00421 $questiontext = $this->object->getQuestiontext();
00422 $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
00423 $template->parseCurrentBlock();
00424 $template->setCurrentBlock("detail_row");
00425 $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
00426 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
00427 $template->parseCurrentBlock();
00428 $template->setCurrentBlock("detail_row");
00429 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
00430 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
00431 $template->parseCurrentBlock();
00432 $template->setCurrentBlock("detail_row");
00433 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
00434 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
00435 $template->parseCurrentBlock();
00436 $template->setCurrentBlock("detail_row");
00437 $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
00438 switch ($this->object->getSubType())
00439 {
00440 case SUBTYPE_NON_RATIO:
00441 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
00442 break;
00443 case SUBTYPE_RATIO_NON_ABSOLUTE:
00444 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
00445 break;
00446 case SUBTYPE_RATIO_ABSOLUTE:
00447 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
00448 break;
00449 }
00450 $template->parseCurrentBlock();
00451
00452
00453 $template->setCurrentBlock("detail_row");
00454 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
00455 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
00456 $template->parseCurrentBlock();
00457 $template->setCurrentBlock("detail_row");
00458 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
00459 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
00460 $template->parseCurrentBlock();
00461 $template->setCurrentBlock("detail_row");
00462 $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
00463 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
00464 $template->parseCurrentBlock();
00465 $template->setCurrentBlock("detail_row");
00466 $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
00467 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
00468 $template->parseCurrentBlock();
00469
00470 $template->setCurrentBlock("detail_row");
00471 $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
00472 $values = "";
00473 if (is_array($this->cumulated["values"]))
00474 {
00475 foreach ($this->cumulated["values"] as $key => $value)
00476 {
00477 $values .= "<li>" . $this->lng->txt("value") . ": " . "<span class=\"bold\">" . $value["value"] . "</span><br />" .
00478 $this->lng->txt("value_nr_entered") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
00479 $this->lng->txt("percentage_of_entered_values") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
00480 }
00481 }
00482 $values = "<ol>$values</ol>";
00483 $template->setVariable("TEXT_OPTION_VALUE", $values);
00484 $template->parseCurrentBlock();
00485
00486
00487 $template->setCurrentBlock("chart");
00488 $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
00489 $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
00490 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
00491 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
00492 $template->setVariable("CHART", $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart"));
00493 $template->parseCurrentBlock();
00494
00495 $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
00496 return $template->get();
00497 }
00498
00499 }
00500 ?>