51 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); 80 if(preg_match_all(
"/(\\\$r\\d+)/ims",
$formula, $matches))
84 if(strcmp($result, $this->
getResult()) == 0)
102 return "(".$formula.
")";
108 $resultunits =
array();
114 include_once
"./Services/Math/classes/class.ilMath.php";
115 include_once
"./Services/Math/classes/class.EvalMath.php";
117 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
119 foreach($matches[1] as $variable)
121 $varObj = $variables[$variable];
122 if(!is_object($varObj))
126 $value = $varObj->getBaseValue();
127 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$value.
")" .
"\\1",
$formula);
131 $math->suppress_errors = TRUE;
135 if(is_object($this->
getUnit()))
142 if($use_precision ==
true)
158 include_once
"./Services/Math/classes/class.EvalMath.php";
161 while($i < 1000 && !$inRange)
164 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
166 foreach($matches[1] as $variable)
168 $varObj = $variables[$variable];
169 if(!is_object($varObj))
173 $varObj->setRandomValue();
174 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$varObj->getBaseValue().
")" .
"\\1",
$formula);
178 $math->suppress_errors = TRUE;
180 $inRange = (is_numeric(
$result)) ? TRUE : FALSE;
206 include_once
"./Services/Math/classes/class.EvalMath.php";
209 for($i = 0; $i < 1000; $i++)
212 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
214 foreach($matches[1] as $variable)
216 $varObj = $variables[$variable];
217 if(!is_object($varObj))
221 $varObj->setRandomValue();
222 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$varObj->getBaseValue().
")" .
"\\1",
$formula);
226 $math->suppress_errors = TRUE;
231 include_once
"./Services/Math/classes/class.ilMath.php";
232 if(is_object($this->
getUnit()))
251 if($value === NULL || 0 == strlen($value))
256 $value = str_replace(
' ',
'',$value);
258 include_once
"./Services/Math/classes/class.EvalMath.php";
259 include_once
"./Services/Math/classes/class.ilMath.php";
263 $check_valid_chars =
true;
264 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
266 foreach($matches[1] as $variable)
268 $varObj = $variables[$variable];
269 if(!is_object($varObj))
274 if($varObj->getUnit() != NULL)
277 if($varObj->getUnit()->getBaseUnit() != -1) #$this->
getUnit() != NULL)
279 $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
283 $tmp_value = $varObj->getValue();
288 $tmp_value = $varObj->getValue();
291 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$tmp_value.
")" .
"\\1",
$formula);
296 $math->suppress_errors =
true;
300 if(is_object($this->
getUnit()))
305 if($this->
getUnit()->getBaseUnit() != -1)
320 if(
$unit->getFactor() == 1 && strlen(trim(
$unit->getFactor())) == 1)
332 $has_valid_chars = preg_match(
"/^-?([0-9]*)(,|\\.|\\/){0,1}([0-9]*)([eE][\\+|-]([0-9])+)?$/", $value, $matches);
333 if(!$has_valid_chars)
335 $check_valid_chars =
false;
337 else if($matches[2] ==
'/' && strtolower($matches[4]) ==
"e" && (!strlen($matches[1]) || !strlen($matches[3]) || $matches[3] == 0))
339 $check_valid_chars =
false;
345 if(substr_count($value,
'/') > 0)
347 $check_fraction = FALSE;
351 $check_fraction = TRUE;
356 if(substr_count($value,
'.') == 1 || substr_count($value,
',') == 1)
359 $frac_value = str_replace(
',',
'.', $exp_val);
363 $frac_value = $value;
371 $exp_val = explode(
'/', $value);
372 if(count($exp_val) == 1)
377 $check_fraction = TRUE;
381 $check_fraction = FALSE;
388 $frac_value = str_replace(
',',
'.', $frac_value);
392 $check_fraction = TRUE;
397 if(!self::isCoprimeFraction($exp_val[0], $exp_val[1]))
399 $check_fraction = FALSE;
404 if(substr_count($value,
'.') > 0 || substr_count($value,
',') > 0)
406 $check_fraction = FALSE;
412 if(substr_count($value,
'.') == 1 || substr_count($value,
',') == 1)
414 $frac_value = str_replace(
',',
'.', $value);
416 elseif( substr_count($value,
'/') == 1 )
418 $exp_val = explode(
'/', $value);
423 $frac_value = $value;
426 $check_fraction = TRUE;
432 if(isset($frac_value))
439 if(isset($frac_value))
455 if(is_object($this->
getUnit()))
465 return $checkvalue && $checkunit && $check_fraction && $check_valid_chars;
470 include_once
"./Services/Math/classes/class.ilMath.php";
474 if(($b1 <= $v1) && ($b2 >= $v1))
return TRUE;
480 if((($v1 >= 0) && ($v2 >= 0)) || (($v1 <= 0) && ($v2 <= 0)))
507 include_once
"./Services/Math/classes/class.EvalMath.php";
508 include_once
"./Services/Math/classes/class.ilMath.php";
511 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
513 foreach($matches[1] as $variable)
515 $varObj = $variables[$variable];
516 if(!is_object($varObj))
520 if($varObj->getUnit() != NULL)
523 if($varObj->getUnit()->getBaseUnit() != -1)
525 $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
529 $tmp_value = $varObj->getValue();
534 $tmp_value = $varObj->getValue();
536 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$tmp_value.
")" .
"\\1",
$formula);
541 $math->suppress_errors = TRUE;
548 if((substr_count($value,
'.') == 1) || (substr_count($value,
',') == 1))
551 $frac_value = str_replace(
',',
'.', $exp_val);
555 $frac_value = $value;
557 $check_fraction = TRUE;
560 $exp_val = explode(
'/', $value);
561 if(count($exp_val) == 1)
566 $check_fraction = TRUE;
570 $check_fraction = FALSE;
578 $check_fraction = TRUE;
583 $exp_val = explode(
'/', $value);
584 if(count($exp_val) == 1)
586 $check_fraction = FALSE;
591 if(self::isCoprimeFraction($exp_val[0], $exp_val[1]))
593 $check_fraction = TRUE;
599 $check_fraction = TRUE;
604 if(is_object($this->
getUnit()))
607 if($this->
getUnit()->getBaseUnit() != -1)
620 if(isset($frac_value))
634 if(is_object($this->
getUnit()))
636 $base1 = $units[
$unit];
637 if(is_object($base1)) $base1 = $units[$base1->getBaseUnit()];
638 $base2 = $units[$this->
getUnit()->getBaseUnit()];
639 if(is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId())
658 return array(
"points" => 0);
663 include_once
"./Services/Math/classes/class.EvalMath.php";
664 include_once
"./Services/Math/classes/class.ilMath.php";
667 if(preg_match_all(
"/(\\\$v\\d+)/ims",
$formula, $matches))
669 foreach($matches[1] as $variable)
671 $varObj = $variables[$variable];
672 $formula = preg_replace(
"/\\\$" . substr($variable, 1) .
"(?![0-9]+)/",
"(".$varObj->getBaseValue().
")" .
"\\1",
$formula);
676 $math->suppress_errors = TRUE;
678 if(is_object($this->
getUnit()))
702 if(is_object($this->
getUnit()))
704 $base1 = $units[
$unit];
705 if(is_object($base1)) $base1 = $units[$base1->getBaseUnit()];
706 $base2 = $units[$this->
getUnit()->getBaseUnit()];
707 if(is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId())
714 $details[
'points'] = $totalpoints;
742 include_once
"./Services/Math/classes/class.EvalMath.php";
744 $math->suppress_errors = TRUE;
760 if(is_object($this->
getUnit()))
762 include_once
"./Services/Math/classes/class.ilMath.php";
778 include_once
"./Services/Math/classes/class.EvalMath.php";
780 $math->suppress_errors = TRUE;
795 if(is_object($this->
getUnit()))
797 include_once
"./Services/Math/classes/class.ilMath.php";
896 $this->result_type = $a_result_type;
928 $res = $ilDB->queryF(
' 930 FROM il_qpl_qst_fq_res 931 WHERE question_fi = %s 933 array(
'integer',
'text'),
934 array($a_qst_id, $a_result));
938 return $row[
'result_type'];
944 $gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
946 return $gcd == 1 ? true :
false;
951 $to_string = (
string) $decimal_value;
952 $is_negative = strpos($to_string,
'-') === 0;
955 $decimal_value = substr($decimal_value, 1);
961 $b = 1 / $decimal_value;
966 $h1 = $a * $h1 + $h2;
969 $k1 = $a * $k1 + $k2;
972 }
while ((abs($decimal_value - $h1 / $k1) > $decimal_value *
$tolerance) || ( $k1 < 0 || $b < 0 ));
981 $checkResult = ($h1/$k1);
986 $checkResult = ($h1/$k1)*-1;
988 if($to_string == $checkResult.
'' || $checkResult.
'' ==
$result)
1002 return self::getGreatestCommonDivisor($b, $a % $b);
1015 $res = $ilDB->queryF(
' 1016 SELECT * FROM il_qpl_qst_fq_res_unit 1017 WHERE question_fi = %s 1022 while (
$row = $ilDB->fetchAssoc(
$res))
1024 $this->available_units[
$row[
'result']][] = $row[
'unit_fi'] ;
static _div($left_operand, $right_operand, $scale=50)
Add rich text string
The name of the decorator.
static _equals($value1, $value2, $scale)
static _round($value, $precision=0)
static _add($left_operand, $right_operand, $scale=50)
Create styles array
The data for the language used.
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)