ILIAS  release_7 Revision v7.30-3-g800a261c036
assFormulaQuestionVariable Class Reference

Formula Question Variable. More...

+ Collaboration diagram for assFormulaQuestionVariable:

Public Member Functions

 __construct ($variable, $range_min, $range_max, $unit=null, $precision=0, $intprecision=1)
 assFormulaQuestionVariable constructor More...
 
 getRandomValue ()
 
 setRandomValue ()
 
 isIntPrecisionValid ($int_precision, $min_range, $max_range)
 
 setValue ($value)
 
 getValue ()
 
 getBaseValue ()
 
 setPrecision ($precision)
 
 getPrecision ()
 
 setVariable ($variable)
 
 getVariable ()
 
 setRangeMin ($range_min)
 
 getRangeMin ()
 
 setRangeMax ($range_max)
 
 getRangeMax ()
 
 setUnit ($unit)
 
 getUnit ()
 
 setIntprecision ($intprecision)
 
 getIntprecision ()
 
 setRangeMaxTxt ($range_max_txt)
 
 getRangeMaxTxt ()
 
 setRangeMinTxt ($range_min_txt)
 
 getRangeMinTxt ()
 

Private Attributes

 $variable
 
 $range_min
 
 $range_max
 
 $unit
 
 $value
 
 $precision
 
 $intprecision
 
 $range_min_txt
 
 $range_max_txt
 

Detailed Description

Formula Question Variable.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
Id
class.assFormulaQuestionVariable.php 465 2009-06-29 08:27:36Z hschottm

Definition at line 10 of file class.assFormulaQuestionVariable.php.

Constructor & Destructor Documentation

◆ __construct()

assFormulaQuestionVariable::__construct (   $variable,
  $range_min,
  $range_max,
  $unit = null,
  $precision = 0,
  $intprecision = 1 
)

assFormulaQuestionVariable constructor

Parameters
string$variableVariable name
float$range_minRange minimum
float$range_maxRange maximum
object$unitUnit
integer$precisionNumber of decimal places of the value
integer$intprecisionValues with precision 0 must be divisible by this value @access public

Definition at line 33 of file class.assFormulaQuestionVariable.php.

References $intprecision, $precision, $range_max, $range_min, $unit, $variable, setRangeMax(), setRangeMaxTxt(), setRangeMin(), and setRangeMinTxt().

+ Here is the call graph for this function:

Member Function Documentation

◆ getBaseValue()

assFormulaQuestionVariable::getBaseValue ( )

Definition at line 123 of file class.assFormulaQuestionVariable.php.

124 {
125 if (!is_object($this->getUnit())) {
126 return $this->value;
127 } else {
128 include_once "./Services/Math/classes/class.ilMath.php";
129 return ilMath::_mul($this->value, $this->getUnit()->getFactor());
130 }
131 }
static _mul($left_operand, $right_operand, $scale=50)

References $value, ilMath\_mul(), and getUnit().

+ Here is the call graph for this function:

◆ getIntprecision()

assFormulaQuestionVariable::getIntprecision ( )

Definition at line 199 of file class.assFormulaQuestionVariable.php.

200 {
201 return $this->intprecision;
202 }

References $intprecision.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

Definition at line 138 of file class.assFormulaQuestionVariable.php.

139 {
140 //@todo TEST
141
142 return (int) $this->precision;
143 }

References $precision.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

Definition at line 46 of file class.assFormulaQuestionVariable.php.

47 {
48
49// @todo check this
50 if ($this->getPrecision() == 0) {
51 if (!$this->isIntPrecisionValid(
52 $this->getIntprecision(),
53 $this->getRangeMin(),
54 $this->getRangeMax()
55 )) {
56 global $DIC;
57 $lng = $DIC['lng'];
58 ilUtil::sendFailure($lng->txt('err_divider_too_big'));
59 }
60 }
61
62 include_once "./Services/Math/classes/class.ilMath.php";
63 $mul = ilMath::_pow(10, $this->getPrecision());
64 $r1 = round(ilMath::_mul($this->getRangeMin(), $mul));
65 $r2 = round(ilMath::_mul($this->getRangeMax(), $mul));
66 $calcval = $this->getRangeMin() - 1;
67 //test
68
69 $roundedRangeMIN = round($this->getRangeMin(), $this->getPrecision());
70 $roundedRangeMAX = round($this->getRangeMax(), $this->getPrecision());
71 while ($calcval < $roundedRangeMIN || $calcval > $roundedRangeMAX) {
72
73
74// while($calcval < $this->getRangeMin() || $calcval > $this->getRangeMax())
75 $rnd = mt_rand($r1, $r2);
76 $calcval = ilMath::_div($rnd, $mul, $this->getPrecision());
77 if (($this->getPrecision() == 0) && ($this->getIntprecision() != 0)) {
78 if ($this->getIntprecision() > 0) {
79 $modulo = $calcval % $this->getIntprecision();
80 if ($modulo != 0) {
81 if ($modulo < ilMath::_div($this->getIntprecision(), 2)) {
82 $calcval = ilMath::_sub($calcval, $modulo, $this->getPrecision());
83 } else {
84 $calcval = ilMath::_add($calcval, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
85 }
86 }
87 }
88 }
89 }
90 return $calcval;
91 }
isIntPrecisionValid($int_precision, $min_range, $max_range)
static _div($left_operand, $right_operand, $scale=50)
static _pow($left_operand, $right_operand, $scale=50)
static _sub($left_operand, $right_operand, $scale=50)
static _add($left_operand, $right_operand, $scale=50)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
$lng

References $DIC, $lng, ilMath\_add(), ilMath\_div(), ilMath\_mul(), ilMath\_pow(), ilMath\_sub(), getIntprecision(), getPrecision(), getRangeMax(), getRangeMin(), isIntPrecisionValid(), and ilUtil\sendFailure().

Referenced by setRandomValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRangeMax()

assFormulaQuestionVariable::getRangeMax ( )

Definition at line 179 of file class.assFormulaQuestionVariable.php.

180 {
181 return (double) $this->range_max;
182 }

References $range_max.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

Definition at line 165 of file class.assFormulaQuestionVariable.php.

166 {
167 return (double) $this->range_min;
168 }

References $range_min.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

Definition at line 189 of file class.assFormulaQuestionVariable.php.

190 {
191 return $this->unit;
192 }

References $unit.

Referenced by getBaseValue().

+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

Definition at line 118 of file class.assFormulaQuestionVariable.php.

119 {
120 return $this->value;
121 }

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

Definition at line 150 of file class.assFormulaQuestionVariable.php.

151 {
152 return $this->variable;
153 }

References $variable.

◆ isIntPrecisionValid()

assFormulaQuestionVariable::isIntPrecisionValid (   $int_precision,
  $min_range,
  $max_range 
)

Definition at line 98 of file class.assFormulaQuestionVariable.php.

99 {
100 $min_abs = abs($min_range);
101 $max_abs = abs($max_range);
102 $bigger_abs = $max_abs > $min_abs ? $max_abs : $min_abs;
103 if ($int_precision > $bigger_abs) {
104 return false;
105 }
106 return true;
107 }

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

Definition at line 194 of file class.assFormulaQuestionVariable.php.

195 {
196 $this->intprecision = $intprecision;
197 }

References $intprecision.

◆ setPrecision()

assFormulaQuestionVariable::setPrecision (   $precision)

Definition at line 133 of file class.assFormulaQuestionVariable.php.

134 {
135 $this->precision = $precision;
136 }

References $precision.

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

Definition at line 93 of file class.assFormulaQuestionVariable.php.

References getRandomValue(), and setValue().

+ Here is the call graph for this function:

◆ setRangeMax()

assFormulaQuestionVariable::setRangeMax (   $range_max)

Definition at line 170 of file class.assFormulaQuestionVariable.php.

171 {
172 include_once "./Services/Math/classes/class.EvalMath.php";
173 $math = new EvalMath();
174 $math->suppress_errors = true;
175 $result = $math->evaluate($range_max);
176 $this->range_max = $result;
177 }
$result

References $range_max, and $result.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt (   $range_max_txt)

Definition at line 204 of file class.assFormulaQuestionVariable.php.

205 {
206 $this->range_max_txt = $range_max_txt;
207 }

References $range_max_txt.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin (   $range_min)

Definition at line 155 of file class.assFormulaQuestionVariable.php.

156 {
157 include_once "./Services/Math/classes/class.EvalMath.php";
158 $math = new EvalMath();
159 $math->suppress_errors = true;
160 $result = $math->evaluate($range_min);
161
162 $this->range_min = $result;
163 }

References $range_min, and $result.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt (   $range_min_txt)

Definition at line 214 of file class.assFormulaQuestionVariable.php.

215 {
216 $this->range_min_txt = $range_min_txt;
217 }

References $range_min_txt.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUnit()

assFormulaQuestionVariable::setUnit (   $unit)

Definition at line 184 of file class.assFormulaQuestionVariable.php.

185 {
186 $this->unit = $unit;
187 }

References $unit.

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

Definition at line 113 of file class.assFormulaQuestionVariable.php.

114 {
115 $this->value = $value;
116 }

References $value.

Referenced by setRandomValue().

+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

Definition at line 145 of file class.assFormulaQuestionVariable.php.

146 {
147 $this->variable = $variable;
148 }

References $variable.

Field Documentation

◆ $intprecision

assFormulaQuestionVariable::$intprecision
private

◆ $precision

assFormulaQuestionVariable::$precision
private

Definition at line 17 of file class.assFormulaQuestionVariable.php.

Referenced by __construct(), getPrecision(), and setPrecision().

◆ $range_max

assFormulaQuestionVariable::$range_max
private

Definition at line 14 of file class.assFormulaQuestionVariable.php.

Referenced by __construct(), getRangeMax(), and setRangeMax().

◆ $range_max_txt

assFormulaQuestionVariable::$range_max_txt
private

Definition at line 20 of file class.assFormulaQuestionVariable.php.

Referenced by getRangeMaxTxt(), and setRangeMaxTxt().

◆ $range_min

assFormulaQuestionVariable::$range_min
private

Definition at line 13 of file class.assFormulaQuestionVariable.php.

Referenced by __construct(), getRangeMin(), and setRangeMin().

◆ $range_min_txt

assFormulaQuestionVariable::$range_min_txt
private

Definition at line 19 of file class.assFormulaQuestionVariable.php.

Referenced by getRangeMinTxt(), and setRangeMinTxt().

◆ $unit

assFormulaQuestionVariable::$unit
private

Definition at line 15 of file class.assFormulaQuestionVariable.php.

Referenced by __construct(), getUnit(), and setUnit().

◆ $value

assFormulaQuestionVariable::$value
private

Definition at line 16 of file class.assFormulaQuestionVariable.php.

Referenced by getBaseValue(), getValue(), and setValue().

◆ $variable

assFormulaQuestionVariable::$variable
private

Definition at line 12 of file class.assFormulaQuestionVariable.php.

Referenced by __construct(), getVariable(), and setVariable().


The documentation for this class was generated from the following file: