ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assFormulaQuestionVariable Class Reference

Formula Question Variable. More...

+ Inheritance diagram for assFormulaQuestionVariable:
+ 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 ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

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

44 {
45 $this->setRangeMin($range_min_txt);
46 $this->setRangeMax($range_max_txt);
47 }

References setRangeMax(), and setRangeMin().

+ Here is the call graph for this function:

Member Function Documentation

◆ fromNormalized()

assFormulaQuestionVariable::fromNormalized ( array  $normalized,
Transformations  $transformations 
)

Restore the object from its normalized representation.

Parameters
array<array-key,mixed>$normalized

Implements ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\FromNormalized.

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

227 : static
228 {
229 $clone = clone $this;
230 $clone->variable = $transformations->string($normalized['variable']);
231 $clone->range_min = $transformations->float($normalized['range_min']);
232 $clone->range_max = $transformations->float($normalized['range_max']);
233 $clone->range_min_txt = $transformations->string($normalized['range_min_txt']);
234 $clone->range_max_txt = $transformations->string($normalized['range_max_txt']);
235 $clone->unit = $transformations->denormalize($normalized['unit'], new assFormulaQuestionUnit());
236 $clone->precision = $transformations->int($normalized['precision']);
237 $clone->intprecision = $transformations->int($normalized['intprecision']);
238
239 return $clone;
240 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\float(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\int(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\string().

+ Here is the call graph for this function:

◆ getBaseValue()

assFormulaQuestionVariable::getBaseValue ( )

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

113 {
114 if (!is_object($this->getUnit())) {
115 return $this->value;
116 } else {
117 return ilMath::_mul($this->value, $this->getUnit()->getFactor());
118 }
119 }
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 180 of file class.assFormulaQuestionVariable.php.

180 : int
181 {
182 return $this->intprecision;
183 }

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

+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

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

126 : int
127 {
128 return $this->precision;
129 }

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

+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

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

49 : float
50 {
51 if (
52 $this->getPrecision() === 0
53 && !$this->isIntPrecisionValid(
54 $this->getIntprecision(),
55 $this->getRangeMin(),
56 $this->getRangeMax()
57 )
58 ) {
59 global $DIC;
60 $DIC['tpl']->setOnScreenMessage('failure', $DIC['lng']->txt('err_divider_too_big'));
61 return 0.0;
62 }
63
64 $mul = ilMath::_pow(10, $this->getPrecision());
65 $r1 = round((float) ilMath::_mul($this->getRangeMin(), $mul));
66 $r2 = round((float) ilMath::_mul($this->getRangeMax(), $mul));
67 $calc_val = $this->getRangeMin() - 1.0;
68
69 $rounded_range_min = round($this->getRangeMin(), $this->getPrecision());
70 $rounded_range_max = round($this->getRangeMax(), $this->getPrecision());
71 while ($calc_val < $rounded_range_min || $calc_val > $rounded_range_max) {
72 $rnd = random_int((int) $r1, (int) $r2);
73 $calc_val = (float) ilMath::_div($rnd, $mul, $this->getPrecision());
74
75 if ($this->getPrecision() === 0 && $this->getIntprecision() > 0) {
76 $modulo = $calc_val % $this->getIntprecision();
77 if ($modulo !== 0) {
78 $calc_val = $modulo < ilMath::_div($this->getIntprecision(), 2)
79 ? (float) ilMath::_sub($calc_val, $modulo, $this->getPrecision())
80 : (float) ilMath::_add($calc_val, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
81 }
82 }
83 }
84
85 return $calc_val;
86 }
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 160 of file class.assFormulaQuestionVariable.php.

160 : float
161 {
162 return $this->range_max;
163 }

References $range_max.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

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

190 : string
191 {
192 return $this->range_max_txt;
193 }

Referenced by assFormulaQuestion\buildVariablesForLog().

+ Here is the caller graph for this function:

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

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

148 : float
149 {
150 return $this->range_min;
151 }

References $range_min.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

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

200 : string
201 {
202 return $this->range_min_txt;
203 }

Referenced by assFormulaQuestion\buildVariablesForLog().

+ Here is the caller graph for this function:

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

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

171 {
172 return $this->unit;
173 }

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

+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

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

108 {
109 return $this->value;
110 }

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

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

136 : string
137 {
138 return $this->variable;
139 }

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

93 : bool
94 {
95 return $int_precision !== null && $int_precision <= max(abs($max_range), abs($min_range));
96 }

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

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

175 : void
176 {
177 $this->intprecision = $intprecision;
178 }

◆ setPrecision()

assFormulaQuestionVariable::setPrecision ( int  $precision)

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

121 : void
122 {
123 $this->precision = $precision;
124 }

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

Definition at line 88 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 153 of file class.assFormulaQuestionVariable.php.

153 : void
154 {
155 $math = new EvalMath();
156 $math->suppress_errors = true;
157 $this->range_max = (float) $math->evaluate($range_max);
158 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $range_max.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt ( string  $range_max_txt)

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

185 : void
186 {
187 $this->range_max_txt = $range_max_txt;
188 }

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin ( string  $range_min)

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

141 : void
142 {
143 $math = new EvalMath();
144 $math->suppress_errors = true;
145 $this->range_min = (float) $math->evaluate($range_min);
146 }

References $range_min.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt ( string  $range_min_txt)

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

195 : void
196 {
197 $this->range_min_txt = $range_min_txt;
198 }

◆ setUnit()

assFormulaQuestionVariable::setUnit ( ?assFormulaQuestionUnit  $unit)

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

165 : void
166 {
167 $this->unit = $unit;
168 }

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

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

102 : void
103 {
104 $this->value = $value;
105 }

References $value.

Referenced by setRandomValue().

+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

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

131 : void
132 {
133 $this->variable = $variable;
134 }

◆ toNormalized()

assFormulaQuestionVariable::toNormalized ( Transformations  $transformations,
array  $context = [] 
)

Convert the internal state of the implementing object into a language-neutral array structure.

The resulting array must contain only null, scalar values (string, int, float, bool) and nested arrays following the same rules.

Parameters
array<string,mixed>$context
Returns
array<array-key, mixed>|float|bool|int|string|null

Implements ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\ToNormalized.

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

209 : array|float|bool|int|string|null
210 {
211 return [
212 'variable' => $this->variable,
213 'range_min' => $this->range_min,
214 'range_max' => $this->range_max,
215 'range_min_txt' => $this->range_min_txt,
216 'range_max_txt' => $this->range_max_txt,
217 'unit' => $transformations->normalize($this->unit),
218 'precision' => $this->precision,
219 'intprecision' => $this->intprecision,
220 ];
221 }

References $range_max, $range_min, and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\normalize().

+ Here is the call graph for this function:

Field Documentation

◆ $range_max

float assFormulaQuestionVariable::$range_max
private

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

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

◆ $range_min

float assFormulaQuestionVariable::$range_min
private

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

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

◆ $value

assFormulaQuestionVariable::$value = null
private

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

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


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