private function eval_route() { $route = URI::current(); $formula = $this->get_formula($route, $action_count); $m = new EvalMath(); $result = $m->e($formula); if ($action_count <= 10 && $result !== false) { return round($result, 0, PHP_ROUND_HALF_UP); } else { return 'Incorrect arithmetic route'; } }
/** * Check input, strip slashes etc. set alert, if input is not ok. * * @return boolean Input ok, true/false */ function checkInput() { global $lng; $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]); if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") { $this->setAlert($lng->txt("msg_input_is_required")); return false; } else { $eval = new EvalMath(); $eval->suppress_errors = true; $result = $eval->e(str_replace(",", ".", ilUtil::stripSlashes($_POST[$this->getPostVar()], FALSE))); if ($result === false) { $this->setAlert($lng->txt("form_msg_formula_is_required")); return false; } } return $this->checkSubItemsInput(); }
/** * Checks the range limits * * Checks the Range limits Upper and Lower for their correctness * * @return boolean */ public function checkRange() { include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = TRUE; if ($eval->e($_POST["rang_lower_limit"]) !== FALSE and $eval->e($_POST["range_upper_limit"]) !== FALSE) { if ($eval->e($_POST["rang_lower_limit"]) < $eval->e($_POST["range_upper_limit"])) { return TRUE; } else { return FALSE; } } return FALSE; }
/** * Returns the points, a learner has reached answering the question. * The points are calculated from the given answers. * * @access public * @param integer $active_id * @param integer $pass * @param boolean $returndetails (deprecated !!) * @return integer/array $points/$details (array $details is deprecated !!) */ public function calculateReachedPoints($active_id, $pass = NULL, $returndetails = FALSE) { global $ilDB; $found_value1 = array(); $found_value2 = array(); $detailed = array(); if (is_null($pass)) { $pass = $this->getSolutionMaxPass($active_id); } $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s", array("integer", "integer", "integer"), array($active_id, $this->getId(), $pass)); $user_result = array(); while ($data = $ilDB->fetchAssoc($result)) { if (strcmp($data["value2"], "") != 0) { $user_result[$data["value1"]] = array("gap_id" => $data["value1"], "value" => $data["value2"]); } } $points = 0; $counter = 0; $solution_values_text = array(); // for identical scoring checks $solution_values_select = array(); // for identical scoring checks $solution_values_numeric = array(); // for identical scoring checks foreach ($user_result as $gap_id => $value) { if (array_key_exists($gap_id, $this->gaps)) { switch ($this->gaps[$gap_id]->getType()) { case CLOZE_TEXT: $gappoints = 0; for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); $gotpoints = $this->getTextgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } if (!$this->getIdenticalScoring()) { // check if the same solution text was already entered if (in_array($value["value"], $solution_values_text) && $gappoints > 0) { $gappoints = 0; } } $points += $gappoints; $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE); array_push($solution_values_text, $value["value"]); break; case CLOZE_NUMERIC: $gappoints = 0; for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); $gotpoints = $this->getNumericgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } if (!$this->getIdenticalScoring()) { // check if the same solution value was already entered include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = TRUE; $found_value = FALSE; foreach ($solution_values_numeric as $solval) { if ($eval->e($solval) == $eval->e($value["value"])) { $found_value = TRUE; } } if ($found_value && $gappoints > 0) { $gappoints = 0; } } $points += $gappoints; $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE); array_push($solution_values_numeric, $value["value"]); break; case CLOZE_SELECT: if ($value["value"] >= 0) { for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); if ($value["value"] == $answer->getOrder()) { $answerpoints = $answer->getPoints(); if (!$this->getIdenticalScoring()) { // check if the same solution value was already entered if (in_array($answer->getAnswertext(), $solution_values_select) && $answerpoints > 0) { $answerpoints = 0; } } $points += $answerpoints; $detailed[$gap_id] = array("points" => $answerpoints, "best" => $this->getMaximumGapPoints($gap_id) == $answerpoints ? TRUE : FALSE, "positive" => $answerpoints > 0 ? TRUE : FALSE); array_push($solution_values_select, $answer->getAnswertext()); } } } break; } } } if ($returndetails) { return $detailed; } else { return $points; } }
/** * Checks for a given value within the range * * @param double $value The value to check * @return boolean TRUE if the value is in the range, FALSE otherwise * @access public * @see $upperlimit * @see $lowerlimit */ function contains($value) { include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = TRUE; $result = $eval->e($value); if ($result === FALSE || $result === TRUE) { return FALSE; } if ($result >= $eval->e($this->getLowerLimit()) && $result <= $eval->e($this->getUpperLimit())) { return TRUE; } else { return FALSE; } }
/** * Checks for a given value within the range * * Checks for a given value within the range * * @param double $value The value to check * * @return boolean TRUE if the value is in the range, FALSE otherwise * * @see $upperlimit * @see $lowerlimit */ public function contains($value) { require_once './Services/Math/classes/class.EvalMath.php'; $eval = new EvalMath(); $eval->suppress_errors = TRUE; $result = $eval->e($value); if ($result === FALSE || $result === TRUE) { return FALSE; } if ($result >= $eval->e($this->lowerlimit) && $result <= $eval->e($this->upperlimit)) { return TRUE; } else { return FALSE; } }
/** * Returns a QTI xml representation of the question * * Returns a QTI xml representation of the question and sets the internal * domxml variable with the DOM XML representation of the QTI xml representation * * @return string The QTI xml representation of the question * @access public */ function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false) { global $ilias; include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = TRUE; include_once "./Services/Xml/classes/class.ilXmlWriter.php"; $a_xml_writer = new ilXmlWriter(); // set xml header $a_xml_writer->xmlHeader(); $a_xml_writer->xmlStartTag("questestinterop"); $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries()); $a_xml_writer->xmlStartTag("item", $attrs); // add question description $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment()); // add estimated working time $workingtime = $this->object->getEstimatedWorkingTime(); $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]); $a_xml_writer->xmlElement("duration", NULL, $duration); // add ILIAS specific metadata $a_xml_writer->xmlStartTag("itemmetadata"); $a_xml_writer->xmlStartTag("qtimetadata"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION"); $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version")); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE"); $a_xml_writer->xmlElement("fieldentry", NULL, CLOZE_TEST_IDENTIFIER); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR"); $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor()); $a_xml_writer->xmlEndTag("qtimetadatafield"); // additional content editing information $this->addAdditionalContentEditingModeInformation($a_xml_writer); $this->addGeneralMetadata($a_xml_writer); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "textgaprating"); $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextgapRating()); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "fixedTextLength"); $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getFixedTextLength()); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "identicalScoring"); $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getIdenticalScoring()); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlStartTag("qtimetadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "combinations"); $a_xml_writer->xmlElement("fieldentry", NULL, base64_encode(json_encode($this->object->getGapCombinations()))); $a_xml_writer->xmlEndTag("qtimetadatafield"); $a_xml_writer->xmlEndTag("qtimetadata"); $a_xml_writer->xmlEndTag("itemmetadata"); // PART I: qti presentation $attrs = array("label" => $this->object->getTitle()); $a_xml_writer->xmlStartTag("presentation", $attrs); // add flow to presentation $a_xml_writer->xmlStartTag("flow"); $questionText = $this->object->getQuestion() ? $this->object->getQuestion() : ' '; $this->object->addQTIMaterial($a_xml_writer, $questionText); $text_parts = preg_split("/\\[gap.*?\\[\\/gap\\]/", $this->object->getClozeText()); // add material with question text to presentation for ($i = 0; $i <= $this->object->getGapCount(); $i++) { $this->object->addQTIMaterial($a_xml_writer, $text_parts[$i]); if ($i < $this->object->getGapCount()) { // add gap $gap = $this->object->getGap($i); switch ($gap->getType()) { case CLOZE_SELECT: // comboboxes $attrs = array("ident" => "gap_{$i}", "rcardinality" => "Single"); $a_xml_writer->xmlStartTag("response_str", $attrs); $solution = $this->object->getSuggestedSolution($i); if (count($solution)) { if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) { $attrs = array("label" => "suggested_solution"); $a_xml_writer->xmlStartTag("material", $attrs); $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3]; if (strcmp($matches[1], "") != 0) { $intlink = $solution["internal_link"]; } $a_xml_writer->xmlElement("mattext", NULL, $intlink); $a_xml_writer->xmlEndTag("material"); } } $attrs = array("shuffle" => $gap->getShuffle() ? "Yes" : "No"); $a_xml_writer->xmlStartTag("render_choice", $attrs); // add answers foreach ($gap->getItems() as $answeritem) { $attrs = array("ident" => $answeritem->getOrder()); $a_xml_writer->xmlStartTag("response_label", $attrs); $a_xml_writer->xmlStartTag("material"); $a_xml_writer->xmlElement("mattext", NULL, $answeritem->getAnswertext()); $a_xml_writer->xmlEndTag("material"); $a_xml_writer->xmlEndTag("response_label"); } $a_xml_writer->xmlEndTag("render_choice"); $a_xml_writer->xmlEndTag("response_str"); break; case CLOZE_TEXT: // text fields $attrs = array("ident" => "gap_{$i}", "rcardinality" => "Single"); $a_xml_writer->xmlStartTag("response_str", $attrs); $solution = $this->object->getSuggestedSolution($i); if (count($solution)) { if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) { $attrs = array("label" => "suggested_solution"); $a_xml_writer->xmlStartTag("material", $attrs); $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3]; if (strcmp($matches[1], "") != 0) { $intlink = $solution["internal_link"]; } $a_xml_writer->xmlElement("mattext", NULL, $intlink); $a_xml_writer->xmlEndTag("material"); } } $attrs = array("fibtype" => "String", "prompt" => "Box", "columns" => $gap->getGapSize()); $a_xml_writer->xmlStartTag("render_fib", $attrs); $a_xml_writer->xmlEndTag("render_fib"); $a_xml_writer->xmlEndTag("response_str"); break; case CLOZE_NUMERIC: // numeric fields $attrs = array("ident" => "gap_{$i}", "numtype" => "Decimal", "rcardinality" => "Single"); $a_xml_writer->xmlStartTag("response_num", $attrs); $solution = $this->object->getSuggestedSolution($i); if (count($solution)) { if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) { $attrs = array("label" => "suggested_solution"); $a_xml_writer->xmlStartTag("material", $attrs); $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3]; if (strcmp($matches[1], "") != 0) { $intlink = $solution["internal_link"]; } $a_xml_writer->xmlElement("mattext", NULL, $intlink); $a_xml_writer->xmlEndTag("material"); } } $answeritem = $gap->getItem(0); $attrs = array("fibtype" => "Decimal", "prompt" => "Box", "columns" => $gap->getGapSize()); if (is_object($answeritem)) { if ($eval->e($answeritem->getLowerBound()) !== FALSE) { $attrs["minnumber"] = $answeritem->getLowerBound(); } if ($eval->e($answeritem->getUpperBound()) !== FALSE) { $attrs["maxnumber"] = $answeritem->getUpperBound(); } } $a_xml_writer->xmlStartTag("render_fib", $attrs); $a_xml_writer->xmlEndTag("render_fib"); $a_xml_writer->xmlEndTag("response_num"); break; } } } $a_xml_writer->xmlEndTag("flow"); $a_xml_writer->xmlEndTag("presentation"); // PART II: qti resprocessing $a_xml_writer->xmlStartTag("resprocessing"); $a_xml_writer->xmlStartTag("outcomes"); $a_xml_writer->xmlStartTag("decvar"); $a_xml_writer->xmlEndTag("decvar"); $a_xml_writer->xmlEndTag("outcomes"); // add response conditions for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); switch ($gap->getType()) { case CLOZE_SELECT: foreach ($gap->getItems() as $answer) { $attrs = array("continue" => "Yes"); $a_xml_writer->xmlStartTag("respcondition", $attrs); // qti conditionvar $a_xml_writer->xmlStartTag("conditionvar"); $attrs = array("respident" => "gap_{$i}"); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); $a_xml_writer->xmlEndTag("conditionvar"); // qti setvar $attrs = array("action" => "Add"); $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints()); // qti displayfeedback $linkrefid = ""; $linkrefid = "{$i}" . "_Response_" . $answer->getOrder(); $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid); $a_xml_writer->xmlElement("displayfeedback", $attrs); $a_xml_writer->xmlEndTag("respcondition"); } break; case CLOZE_TEXT: foreach ($gap->getItems() as $answer) { $attrs = array("continue" => "Yes"); $a_xml_writer->xmlStartTag("respcondition", $attrs); // qti conditionvar $a_xml_writer->xmlStartTag("conditionvar"); $attrs = array("respident" => "gap_{$i}"); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); $a_xml_writer->xmlEndTag("conditionvar"); // qti setvar $attrs = array("action" => "Add"); $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints()); // qti displayfeedback $linkrefid = "{$i}" . "_Response_" . $answer->getOrder(); $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid); $a_xml_writer->xmlElement("displayfeedback", $attrs); $a_xml_writer->xmlEndTag("respcondition"); } break; case CLOZE_NUMERIC: foreach ($gap->getItems() as $answer) { $attrs = array("continue" => "Yes"); $a_xml_writer->xmlStartTag("respcondition", $attrs); // qti conditionvar $a_xml_writer->xmlStartTag("conditionvar"); $attrs = array("respident" => "gap_{$i}"); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); $a_xml_writer->xmlEndTag("conditionvar"); // qti setvar $attrs = array("action" => "Add"); $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints()); // qti displayfeedback $linkrefid = "{$i}" . "_Response_" . $answer->getOrder(); $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid); $a_xml_writer->xmlElement("displayfeedback", $attrs); $a_xml_writer->xmlEndTag("respcondition"); } break; } } $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true); if (strlen($feedback_allcorrect)) { $attrs = array("continue" => "Yes"); $a_xml_writer->xmlStartTag("respcondition", $attrs); // qti conditionvar $a_xml_writer->xmlStartTag("conditionvar"); for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); $indexes = $gap->getBestSolutionIndexes(); if ($i > 0) { $a_xml_writer->xmlStartTag("and"); } switch ($gap->getType()) { case CLOZE_SELECT: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; case CLOZE_TEXT: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; case CLOZE_NUMERIC: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; } if ($i > 0) { $a_xml_writer->xmlEndTag("and"); } } $a_xml_writer->xmlEndTag("conditionvar"); // qti displayfeedback $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect"); $a_xml_writer->xmlElement("displayfeedback", $attrs); $a_xml_writer->xmlEndTag("respcondition"); } $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false); if (strlen($feedback_onenotcorrect)) { $attrs = array("continue" => "Yes"); $a_xml_writer->xmlStartTag("respcondition", $attrs); // qti conditionvar $a_xml_writer->xmlStartTag("conditionvar"); $a_xml_writer->xmlStartTag("not"); for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); $indexes = $gap->getBestSolutionIndexes(); if ($i > 0) { $a_xml_writer->xmlStartTag("and"); } switch ($gap->getType()) { case CLOZE_SELECT: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; case CLOZE_TEXT: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; case CLOZE_NUMERIC: $k = 0; foreach ($indexes as $key) { if ($k > 0) { $a_xml_writer->xmlStartTag("or"); } $attrs = array("respident" => "gap_{$i}"); $answer = $gap->getItem($key); $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext()); if ($k > 0) { $a_xml_writer->xmlEndTag("or"); } $k++; } break; } if ($i > 0) { $a_xml_writer->xmlEndTag("and"); } } $a_xml_writer->xmlEndTag("not"); $a_xml_writer->xmlEndTag("conditionvar"); // qti displayfeedback $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect"); $a_xml_writer->xmlElement("displayfeedback", $attrs); $a_xml_writer->xmlEndTag("respcondition"); } $a_xml_writer->xmlEndTag("resprocessing"); // PART III: qti itemfeedback for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); switch ($gap->getType()) { case CLOZE_SELECT: break; case CLOZE_TEXT: break; case CLOZE_NUMERIC: break; } /*foreach ($gap->getItems() as $answer) { $linkrefid = "$i" . "_Response_" . $answer->getOrder(); $attrs = array( "ident" => $linkrefid, "view" => "All" ); $a_xml_writer->xmlStartTag("itemfeedback", $attrs); // qti flow_mat $a_xml_writer->xmlStartTag("flow_mat"); // $a_xml_writer->xmlStartTag("material"); // $a_xml_writer->xmlElement("mattext"); // $a_xml_writer->xmlEndTag("material"); $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation( $this->object->getId(), $index ); $this->object->addQTIMaterial($a_xml_writer, $fb); $a_xml_writer->xmlEndTag("flow_mat"); $a_xml_writer->xmlEndTag("itemfeedback"); }*/ $attrs = array("ident" => $i, "view" => "All"); $a_xml_writer->xmlStartTag("itemfeedback", $attrs); // qti flow_mat $a_xml_writer->xmlStartTag("flow_mat"); // $a_xml_writer->xmlStartTag("material"); // $a_xml_writer->xmlElement("mattext"); // $a_xml_writer->xmlEndTag("material"); $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->object->getId(), $i); $this->object->addQTIMaterial($a_xml_writer, $fb); $a_xml_writer->xmlEndTag("flow_mat"); $a_xml_writer->xmlEndTag("itemfeedback"); } if (strlen($feedback_allcorrect)) { $attrs = array("ident" => "response_allcorrect", "view" => "All"); $a_xml_writer->xmlStartTag("itemfeedback", $attrs); // qti flow_mat $a_xml_writer->xmlStartTag("flow_mat"); $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect); $a_xml_writer->xmlEndTag("flow_mat"); $a_xml_writer->xmlEndTag("itemfeedback"); } if (strlen($feedback_onenotcorrect)) { $attrs = array("ident" => "response_onenotcorrect", "view" => "All"); $a_xml_writer->xmlStartTag("itemfeedback", $attrs); // qti flow_mat $a_xml_writer->xmlStartTag("flow_mat"); $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect); $a_xml_writer->xmlEndTag("flow_mat"); $a_xml_writer->xmlEndTag("itemfeedback"); } $a_xml_writer->xmlEndTag("item"); $a_xml_writer->xmlEndTag("questestinterop"); $xml = $a_xml_writer->xmlDumpMem(FALSE); if (!$a_include_header) { $pos = strpos($xml, "?>"); $xml = substr($xml, $pos + 2); } return $xml; }
$lang = array('en' => array('help' => 'Usage: %CMD% <expression>. Evaluate a mathematical expression and print results. Use _ and $ to referr to the last result.', '00' => '1 ... No ... 0 ... No ... UNDEFINED!', 'err_in' => 'Error in expression.', 'err_lib' => 'The "EvalMath" class by Miles Kaufmann is missing.')); $plugin = Dog::getPlugin(); if ('' === ($message = $plugin->msg())) { return $plugin->showHelp(); } if (false !== ($last = Dog_Conf_Plug_User::getConf($plugin->getName(), Dog::getUID(), 'last', false))) { $message = str_replace(array('_', '$'), $last, $message); } if ($message === '0^0') { return $plugin->rply('00'); } if ($message === 'pi') { return $plugin->reply('4'); } $path = GWF_PATH . 'core/inc/3p/EvalMath.php'; if (!Common::isFile($path)) { return $plugin->rply('err_lib'); } require_once $path; $eval = new EvalMath(); if (false === ($result = $eval->e($message))) { return $plugin->rply('err_in'); } $result = sprintf('%.09f', $result); if (strpos($result, '.') !== false) { $result = rtrim($result, '0'); $result = rtrim($result, '.'); } Dog_Conf_Plug_User::setConf($plugin->getName(), Dog::getUID(), 'last', $result); Dog::reply($result);
public function checkInput() { $error = false; $json = json_decode(ilUtil::stripSlashes($_POST['gap_json_post'])); $_POST['gap'] = ilUtil::stripSlashesRecursive($_POST['gap']); $gaps_used_in_combination = array(); if (array_key_exists('gap_combination', $_POST)) { $_POST['gap_combination'] = ilUtil::stripSlashesRecursive($_POST['gap_combination']); $_POST['gap_combination_values'] = ilUtil::stripSlashesRecursive($_POST['gap_combination_values']); $gap_with_points = array(); for ($i = 0; $i < count($_POST['gap_combination']['select']); $i++) { foreach ($_POST['gap_combination']['select'][$i] as $key => $item) { if ($item == 'none_selected_minus_one') { return false; } $gaps_used_in_combination[$item] = $item; $check_points_for_best_scoring = false; foreach ($_POST['gap_combination_values'][$i] as $index => $answeritems) { foreach ($answeritems as $answeritem) { if ($answeritem == 'none_selected_minus_one') { return false; } } $points = $_POST['gap_combination']['points'][$i][$index]; if ($points > 0) { $check_points_for_best_scoring = true; } } if (!$check_points_for_best_scoring) { return false; } } } } if (isset($_POST['gap']) && is_array($_POST['gap'])) { foreach ($_POST['gap'] as $key => $item) { $_POST['clozetype_' . $key] = ilUtil::stripSlashes($_POST['clozetype_' . $key]); $getType = $_POST['clozetype_' . $key]; $gapsize = $_POST['gap_' . $key . '_gapsize']; $json[0][$key]->text_field_length = $gapsize > 0 ? $gapsize : ''; if ($getType == CLOZE_TEXT || $getType == CLOZE_SELECT) { $_POST['gap_' . $key] = ilUtil::stripSlashesRecursive($_POST['gap_' . $key]); $gapText = $_POST['gap_' . $key]; foreach ($gapText['answer'] as $row => $answer) { if (!isset($answer) || $answer == '') { $error = true; } } $points_sum = 0; if (array_key_exists('points', $gapText)) { foreach ($gapText['points'] as $row => $points) { if (isset($points) && $points != '' && is_numeric($points)) { $points_sum += $points; } else { $error = true; } } if (is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) { $points_sum += $gap_with_points[$key]; } if ($points_sum == 0) { if (!array_key_exists($key, $gaps_used_in_combination)) { $error = true; } } if ($getType == CLOZE_SELECT) { $_POST['shuffle_' . $key] = ilUtil::stripSlashes($_POST['shuffle_' . $key]); if (!isset($_POST['shuffle_' . $key])) { $error = true; } } } else { $error = true; } } if ($getType == CLOZE_NUMERIC) { $_POST['gap_' . $key . 'numeric'] = ilUtil::stripSlashes($_POST['gap_' . $key . 'numeric'], FALSE); $_POST['gap_' . $key . 'numeric_lower'] = ilUtil::stripSlashes($_POST['gap_' . $key . 'numeric_lower'], FALSE); $_POST['gap_' . $key . 'numeric_upper'] = ilUtil::stripSlashes($_POST['gap_' . $key . 'numeric_upper'], FALSE); $_POST['gap_' . $key . 'numeric_points'] = ilUtil::stripSlashes($_POST['gap_' . $key . 'numeric_points']); $mark_errors = array('answer' => false, 'lower' => false, 'upper' => false, 'points' => false); $eval = new EvalMath(); $eval->suppress_errors = true; $formula = $_POST['gap_' . $key . '_numeric']; $result = $eval->e(str_replace(',', '.', $_POST['gap_' . $key . '_numeric'], $formula)); if ($result === false) { $error = true; } $lower = $_POST['gap_' . $key . '_numeric_lower']; $assClozeTestObject = new assClozeTest(); $has_valid_chars = $assClozeTestObject->checkForValidFormula($lower); $result = $eval->e(str_replace(',', '.', $lower), FALSE); if ($result === false || !$has_valid_chars) { $error = true; } $_POST['gap_' . $key . '_numeric_lower'] = $result; $result = $eval->e(str_replace(',', '.', $_POST['gap_' . $key . '_numeric_upper']), FALSE); if ($result === false) { $error = true; } $_POST['gap_' . $key . '_numeric_upper'] = $result; $points = $_POST['gap_' . $key . '_numeric_points']; if (is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) { $points += $gap_with_points[$key]; } if (!isset($points) || $points == '' || !is_numeric($points) || $points == 0) { if (!array_key_exists($key, $gaps_used_in_combination)) { $error = true; } } $json[0][$key]->values[0]->error = $mark_errors; } } } $_POST['gap_json_post'] = json_encode($json); return !$error; }
protected function getNumericValueFromAnswerText() { include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = true; return $eval->e(str_replace(",", ".", ilUtil::stripSlashes($this->getAnswertext(), FALSE))); }
/** * @param $user_result * @param $detailed * @return array */ protected function calculateReachedPointsForSolution($user_result, &$detailed = null) { if ($detailed === null) { $detailed = array(); } $assClozeGapCombinationObj = new assClozeGapCombination(); $combinations[1] = array(); if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) { $combinations = $this->calculateCombinationResult($user_result); $points = $combinations[0]; } $counter = 0; $solution_values_text = array(); // for identical scoring checks $solution_values_select = array(); // for identical scoring checks $solution_values_numeric = array(); // for identical scoring checks foreach ($user_result as $gap_id => $value) { if (is_string($value)) { $value = array("value" => $value); } if (array_key_exists($gap_id, $this->gaps) && !array_key_exists($gap_id, $combinations[1])) { switch ($this->gaps[$gap_id]->getType()) { case CLOZE_TEXT: $gappoints = 0; for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); $gotpoints = $this->getTextgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } if (!$this->getIdenticalScoring()) { // check if the same solution text was already entered if (in_array($value["value"], $solution_values_text) && $gappoints > 0) { $gappoints = 0; } } $points += $gappoints; $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE); array_push($solution_values_text, $value["value"]); break; case CLOZE_NUMERIC: $gappoints = 0; for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); $gotpoints = $this->getNumericgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } if (!$this->getIdenticalScoring()) { // check if the same solution value was already entered include_once "./Services/Math/classes/class.EvalMath.php"; $eval = new EvalMath(); $eval->suppress_errors = TRUE; $found_value = FALSE; foreach ($solution_values_numeric as $solval) { if ($eval->e($solval) == $eval->e($value["value"])) { $found_value = TRUE; } } if ($found_value && $gappoints > 0) { $gappoints = 0; } } $points += $gappoints; $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE); array_push($solution_values_numeric, $value["value"]); break; case CLOZE_SELECT: if ($value["value"] >= 0) { for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) { $answer = $this->gaps[$gap_id]->getItem($order); if ($value["value"] == $answer->getOrder()) { $answerpoints = $answer->getPoints(); if (!$this->getIdenticalScoring()) { // check if the same solution value was already entered if (in_array($answer->getAnswertext(), $solution_values_select) && $answerpoints > 0) { $answerpoints = 0; } } $points += $answerpoints; $detailed[$gap_id] = array("points" => $answerpoints, "best" => $this->getMaximumGapPoints($gap_id) == $answerpoints ? TRUE : FALSE, "positive" => $answerpoints > 0 ? TRUE : FALSE); array_push($solution_values_select, $answer->getAnswertext()); } } } break; } } } return $points; }
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?> "> y(x) = <input type="text" name="function" value="<?php echo isset($_POST['function']) ? htmlspecialchars($_POST['function']) : ''; ?> "> <input type="submit"> </form> <?php if (isset($_POST['function']) and $_POST['function']) { include 'evalmath.class.php'; $m = new EvalMath(); $m->suppress_errors = true; if ($m->evaluate('y(x) = ' . $_POST['function'])) { print "\t<table border=\"1\">\n"; print "\t\t<tr><th>x</th><th>y(x)</th>\n"; for ($x = -2; $x <= 2; $x += 0.2) { $x = round($x, 2); print "\t\t<tr><td>{$x}</td><td>" . $m->e("y({$x})") . "</td></tr>\n"; } print "\t</table>\n"; } else { print "\t<p>Could not evaluate function: " . $m->last_error . "</p>\n"; } } ?> </body> </html>