ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
assFormulaQuestionVariable Class Reference

Formula Question Variable. More...

+ Collaboration diagram for assFormulaQuestionVariable:

Public Member Functions

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

Private Attributes

 $value = null
 
float $range_min
 
float $range_max
 

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 27 of file class.assFormulaQuestionVariable.php.

Constructor & Destructor Documentation

◆ __construct()

assFormulaQuestionVariable::__construct ( private string  $variable,
private string  $range_min_txt,
private string  $range_max_txt,
private ?assFormulaQuestionUnit  $unit = null,
private int  $precision = 0,
private int  $intprecision = 1 
)

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

40 {
41 $this->setRangeMin($range_min_txt);
42 $this->setRangeMax($range_max_txt);
43 }

References setRangeMax(), and setRangeMin().

+ Here is the call graph for this function:

Member Function Documentation

◆ getBaseValue()

assFormulaQuestionVariable::getBaseValue ( )

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

109 {
110 if (!is_object($this->getUnit())) {
111 return $this->value;
112 } else {
113 return ilMath::_mul($this->value, $this->getUnit()->getFactor());
114 }
115 }
static _mul($left_operand, $right_operand, int $scale=50)

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

+ Here is the call graph for this function:

◆ getIntprecision()

assFormulaQuestionVariable::getIntprecision ( )

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

176 : int
177 {
178 return $this->intprecision;
179 }

Referenced by assFormulaQuestion\buildVariablesForLog(), and getRandomValue().

+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

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

122 : int
123 {
124 return $this->precision;
125 }

Referenced by assFormulaQuestion\buildVariablesForLog(), and getRandomValue().

+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

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

45 : float
46 {
47 if (
48 $this->getPrecision() === 0
49 && !$this->isIntPrecisionValid(
50 $this->getIntprecision(),
51 $this->getRangeMin(),
52 $this->getRangeMax()
53 )
54 ) {
55 global $DIC;
56 $DIC['tpl']->setOnScreenMessage('failure', $DIC['lng']->txt('err_divider_too_big'));
57 return 0.0;
58 }
59
60 $mul = ilMath::_pow(10, $this->getPrecision());
61 $r1 = round((float) ilMath::_mul($this->getRangeMin(), $mul));
62 $r2 = round((float) ilMath::_mul($this->getRangeMax(), $mul));
63 $calc_val = $this->getRangeMin() - 1.0;
64
65 $rounded_range_min = round($this->getRangeMin(), $this->getPrecision());
66 $rounded_range_max = round($this->getRangeMax(), $this->getPrecision());
67 while ($calc_val < $rounded_range_min || $calc_val > $rounded_range_max) {
68 $rnd = random_int((int) $r1, (int) $r2);
69 $calc_val = (float) ilMath::_div($rnd, $mul, $this->getPrecision());
70
71 if ($this->getPrecision() === 0 && $this->getIntprecision() > 0) {
72 $modulo = $calc_val % $this->getIntprecision();
73 if ($modulo !== 0) {
74 $calc_val = $modulo < ilMath::_div($this->getIntprecision(), 2)
75 ? (float) ilMath::_sub($calc_val, $modulo, $this->getPrecision())
76 : (float) ilMath::_add($calc_val, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
77 }
78 }
79 }
80
81 return $calc_val;
82 }
isIntPrecisionValid(?int $int_precision, float $min_range, float $max_range)
static _sub($left_operand, $right_operand, int $scale=50)
static _pow($left_operand, $right_operand, int $scale=50)
static _add($left_operand, $right_operand, int $scale=50)
static _div($left_operand, $right_operand, int $scale=50)
global $DIC
Definition: shib_login.php:26

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

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 156 of file class.assFormulaQuestionVariable.php.

156 : float
157 {
158 return $this->range_max;
159 }

References $range_max.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

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

186 : string
187 {
188 return $this->range_max_txt;
189 }

Referenced by assFormulaQuestion\buildVariablesForLog().

+ Here is the caller graph for this function:

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

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

144 : float
145 {
146 return $this->range_min;
147 }

References $range_min.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

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

196 : string
197 {
198 return $this->range_min_txt;
199 }

Referenced by assFormulaQuestion\buildVariablesForLog().

+ Here is the caller graph for this function:

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

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

167 {
168 return $this->unit;
169 }

Referenced by assFormulaQuestion\buildVariablesForLog(), and getBaseValue().

+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

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

104 {
105 return $this->value;
106 }

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

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

132 : string
133 {
134 return $this->variable;
135 }

Referenced by assFormulaQuestion\addVariable(), and assFormulaQuestion\buildVariablesForLog().

+ Here is the caller graph for this function:

◆ isIntPrecisionValid()

assFormulaQuestionVariable::isIntPrecisionValid ( ?int  $int_precision,
float  $min_range,
float  $max_range 
)

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

89 : bool
90 {
91 return $int_precision !== null && $int_precision <= max(abs($max_range), abs($min_range));
92 }

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

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

171 : void
172 {
173 $this->intprecision = $intprecision;
174 }

◆ setPrecision()

assFormulaQuestionVariable::setPrecision ( int  $precision)

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

117 : void
118 {
119 $this->precision = $precision;
120 }

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

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

References getRandomValue(), and setValue().

+ Here is the call graph for this function:

◆ setRangeMax()

assFormulaQuestionVariable::setRangeMax ( string  $range_max)

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

149 : void
150 {
151 $math = new EvalMath();
152 $math->suppress_errors = true;
153 $this->range_max = (float) $math->evaluate($range_max);
154 }

References $range_max.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt ( string  $range_max_txt)

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

181 : void
182 {
183 $this->range_max_txt = $range_max_txt;
184 }

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin ( string  $range_min)

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

137 : void
138 {
139 $math = new EvalMath();
140 $math->suppress_errors = true;
141 $this->range_min = (float) $math->evaluate($range_min);
142 }

References $range_min.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt ( string  $range_min_txt)

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

191 : void
192 {
193 $this->range_min_txt = $range_min_txt;
194 }

◆ setUnit()

assFormulaQuestionVariable::setUnit ( ?assFormulaQuestionUnit  $unit)

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

161 : void
162 {
163 $this->unit = $unit;
164 }

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

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

98 : void
99 {
100 $this->value = $value;
101 }

References $value.

Referenced by setRandomValue().

+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

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

127 : void
128 {
129 $this->variable = $variable;
130 }

Field Documentation

◆ $range_max

float assFormulaQuestionVariable::$range_max
private

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

Referenced by getRangeMax(), and setRangeMax().

◆ $range_min

float assFormulaQuestionVariable::$range_min
private

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

Referenced by getRangeMin(), and setRangeMin().

◆ $value

assFormulaQuestionVariable::$value = null
private

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

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


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