51 public function __construct(
$result,
$range_min,
$range_max,
$tolerance,
$unit,
$formula,
$points,
$precision,
$rating_simple =
true,
$rating_sign = 33,
$rating_value = 34,
$rating_unit = 33,
$result_type = 0)
54 # $this->setRangeMin((is_numeric($range_min)) ? $range_min : NULL); 55 # $this->setRangeMax((is_numeric($range_max)) ? $range_max : NULL); 81 if (preg_match_all(
"/(\\\$r\\d+)/ims",
$formula, $matches)) {
82 foreach ($matches[1] as
$result) {
83 if (strcmp($result, $this->
getResult()) == 0) {
102 $resultunits = array();
103 if ($question_id > 0) {
107 include_once
"./Services/Math/classes/class.ilMath.php";
108 include_once
"./Services/Math/classes/class.EvalMath.php";
110 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
111 foreach ($matches[1] as $variable) {
112 $varObj = $variables[$variable];
113 if (!is_object($varObj)) {
116 $value = $varObj->getBaseValue();
117 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $value .
")" .
"\\1",
$formula);
121 $math->suppress_errors =
true;
125 if (is_object($this->
getUnit())) {
131 if ($use_precision ==
true) {
144 include_once
"./Services/Math/classes/class.EvalMath.php";
147 while (
$i < 1000 && !$inRange) {
149 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
150 foreach ($matches[1] as $variable) {
151 $varObj = $variables[$variable];
152 if (!is_object($varObj)) {
155 $varObj->setRandomValue();
156 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $varObj->getBaseValue() .
")" .
"\\1",
$formula);
160 $math->suppress_errors =
true;
162 $inRange = (is_numeric(
$result)) ?
true :
false;
183 include_once
"./Services/Math/classes/class.EvalMath.php";
186 for (
$i = 0;
$i < 1000;
$i++) {
188 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
189 foreach ($matches[1] as $variable) {
190 $varObj = $variables[$variable];
191 if (!is_object($varObj)) {
194 $varObj->setRandomValue();
195 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $varObj->getBaseValue() .
")" .
"\\1",
$formula);
199 $math->suppress_errors =
true;
208 include_once
"./Services/Math/classes/class.ilMath.php";
209 if (is_object($this->
getUnit())) {
227 if ($value === null || 0 == strlen($value)) {
230 $value = str_replace(
' ',
'', $value);
232 include_once
"./Services/Math/classes/class.EvalMath.php";
233 include_once
"./Services/Math/classes/class.ilMath.php";
236 $check_valid_chars =
true;
238 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
239 foreach ($matches[1] as $variable) {
240 $varObj = $variables[$variable];
241 if (!is_object($varObj)) {
245 if ($varObj->getUnit() != null) {
247 if ($varObj->getUnit()->getBaseUnit() != -1) { #$this->
getUnit() != NULL)
248 $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
250 $tmp_value = $varObj->getValue();
253 $tmp_value = $varObj->getValue();
256 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $tmp_value .
")" .
"\\1",
$formula);
261 $math->suppress_errors =
true;
265 if (is_object($this->
getUnit())) {
269 if ($this->
getUnit()->getBaseUnit() != -1) {
279 if (
$unit->getFactor() == 1 && strlen(trim(
$unit->getFactor())) == 1) {
288 $has_valid_chars = preg_match(
"/^-?([0-9]*)(,|\\.|\\/){0,1}([0-9]*)([eE][\\+|-]([0-9])+)?$/", $value, $matches);
289 if (!$has_valid_chars) {
290 $check_valid_chars =
false;
292 (isset($matches[2]) && $matches[2] ==
'/') &&
293 (isset($matches[4]) && strtolower($matches[4]) ==
"e") &&
294 (!isset($matches[1]) || !strlen($matches[1]) || !isset($matches[3]) || !strlen($matches[3]) || $matches[3] == 0)) {
295 $check_valid_chars =
false;
300 if (substr_count($value,
'.') == 1 || substr_count($value,
',') == 1) {
302 $frac_value = str_replace(
',',
'.', $exp_val);
304 $frac_value = $value;
307 $frac_value = ilMath::_round($frac_value, $this->
getPrecision());
309 if (substr_count($value,
'/') >= 1) {
310 $check_fraction =
false;
312 $check_fraction =
true;
318 $exp_val = explode(
'/', $value);
319 if (count($exp_val) == 1) {
321 if (ilMath::_equals($frac_value, $resultWithRespectedUnit, $this->
getPrecision())) {
322 $check_fraction =
true;
324 $check_fraction =
false;
336 $frac_value = str_replace(
',',
'.', $frac_value);
338 if (ilMath::_equals($frac_value, $resultWithRespectedUnit, $this->
getPrecision())) {
339 $check_fraction =
true;
343 if (!self::isCoprimeFraction($exp_val[0], $exp_val[1])) {
344 $check_fraction =
false;
349 if (substr_count($value,
'.') >= 1 || substr_count($value,
',') >= 1) {
350 $check_fraction =
false;
356 if (substr_count($value,
'.') == 1 || substr_count($value,
',') == 1) {
357 $frac_value = str_replace(
',',
'.', $value);
358 } elseif (substr_count($value,
'/') == 1) {
359 $exp_val = explode(
'/', $value);
370 $frac_value = $value;
372 $frac_value = ilMath::_round($frac_value, $this->
getPrecision());
373 $check_fraction =
true;
377 if (is_object(
$unit)) {
378 if (isset($frac_value)) {
384 if (isset($frac_value)) {
395 if (is_object($this->
getUnit())) {
396 if (is_object(
$unit)) {
402 return $checkvalue && $checkunit && $check_fraction && $check_valid_chars;
407 include_once
"./Services/Math/classes/class.ilMath.php";
411 if (($b1 <= $v1) && ($b2 >= $v1)) {
420 if ((($v1 >= 0) && ($v2 >= 0)) || (($v1 <= 0) && ($v2 <= 0))) {
439 include_once
"./Services/Math/classes/class.EvalMath.php";
440 include_once
"./Services/Math/classes/class.ilMath.php";
443 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
444 foreach ($matches[1] as $variable) {
445 $varObj = $variables[$variable];
446 if (!is_object($varObj)) {
449 if ($varObj->getUnit() != null) {
451 if ($varObj->getUnit()->getBaseUnit() != -1) {
452 $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
454 $tmp_value = $varObj->getValue();
457 $tmp_value = $varObj->getValue();
459 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $tmp_value .
")" .
"\\1",
$formula);
464 $math->suppress_errors =
true;
470 if ((substr_count($value,
'.') == 1) || (substr_count($value,
',') == 1)) {
472 $frac_value = str_replace(
',',
'.', $exp_val);
474 $frac_value = $value;
476 $check_fraction =
true;
479 $exp_val = explode(
'/', $value);
480 if (count($exp_val) == 1) {
483 $check_fraction =
true;
485 $check_fraction =
false;
490 $check_fraction =
true;
495 $exp_val = explode(
'/', $value);
496 if (count($exp_val) == 1) {
497 $check_fraction =
false;
500 if (self::isCoprimeFraction($exp_val[0], $exp_val[1])) {
501 $check_fraction =
true;
507 $check_fraction =
true;
512 if (is_object($this->
getUnit())) {
514 if ($this->
getUnit()->getBaseUnit() != -1) {
522 if (is_object(
$unit)) {
523 if (isset($frac_value)) {
534 if (is_object($this->
getUnit())) {
535 $base1 = $units[
$unit];
536 if (is_object($base1)) {
537 $base1 = $units[$base1->getBaseUnit()];
539 $base2 = $units[$this->
getUnit()->getBaseUnit()];
540 if (is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId()) {
552 return array(
"points" => $this->
getPoints());
554 return array(
"points" => 0);
557 include_once
"./Services/Math/classes/class.EvalMath.php";
558 include_once
"./Services/Math/classes/class.ilMath.php";
561 if (preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches)) {
562 foreach ($matches[1] as $variable) {
563 $varObj = $variables[$variable];
564 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(" . $varObj->getBaseValue() .
")" .
"\\1",
$formula);
568 $math->suppress_errors =
true;
570 if (is_object($this->
getUnit())) {
573 if (is_object(
$unit)) {
588 if (is_object($this->
getUnit())) {
589 $base1 = $units[
$unit];
590 if (is_object($base1)) {
591 $base1 = $units[$base1->getBaseUnit()];
593 $base2 = $units[$this->
getUnit()->getBaseUnit()];
594 if (is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId()) {
600 $details[
'points'] = $totalpoints;
628 include_once
"./Services/Math/classes/class.EvalMath.php";
630 $math->suppress_errors =
true;
643 if (is_object($this->
getUnit())) {
644 include_once
"./Services/Math/classes/class.ilMath.php";
660 include_once
"./Services/Math/classes/class.EvalMath.php";
662 $math->suppress_errors =
true;
675 if (is_object($this->
getUnit())) {
676 include_once
"./Services/Math/classes/class.ilMath.php";
775 $this->result_type = $a_result_type;
806 $ilDB = $DIC[
'ilDB'];
811 FROM il_qpl_qst_fq_res 812 WHERE question_fi = %s 814 array(
'integer',
'text'),
815 array($a_qst_id, $a_result)
820 return $row[
'result_type'];
825 $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
827 return $gcd == 1 ? true :
false;
832 $to_string = (string) $decimal_value;
833 $is_negative = strpos($to_string,
'-') === 0;
835 $decimal_value = substr($decimal_value, 1);
841 $b = 1 / $decimal_value;
846 $h1 = $a * $h1 + $h2;
849 $k1 = $a * $k1 + $k2;
852 }
while ((abs($decimal_value - $h1 / $k1) > $decimal_value *
$tolerance) || ($k1 < 0 || $b < 0));
858 $checkResult = ($h1 / $k1);
862 $checkResult = ($h1 / $k1) * -1;
864 if ($to_string == $checkResult .
'' || $checkResult .
'' ==
$result) {
867 return array($to_string,
$result);
874 return self::getGreatestCommonDivisor($b, $a % $b);
884 $ilDB = $DIC[
'ilDB'];
888 SELECT * FROM il_qpl_qst_fq_res_unit 889 WHERE question_fi = %s 897 $this->available_units[
$row[
'result']][] = $row[
'unit_fi'] ;
static _div($left_operand, $right_operand, $scale=50)
static _add($left_operand, $right_operand, $scale=50)
foreach($_POST as $key=> $value) $res
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _mul($left_operand, $right_operand, $scale=50)
static _sub($left_operand, $right_operand, $scale=50)