ILIAS  release_8 Revision v8.24
assFormulaQuestionVariable Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 24 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 47 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 138 of file class.assFormulaQuestionVariable.php.

139 {
140 if (!is_object($this->getUnit())) {
141 return $this->value;
142 } else {
143 include_once "./Services/Math/classes/class.ilMath.php";
144 return ilMath::_mul($this->value, $this->getUnit()->getFactor());
145 }
146 }
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 214 of file class.assFormulaQuestionVariable.php.

214 : int
215 {
216 return $this->intprecision;
217 }

References $intprecision.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

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

153 : int
154 {
155 //@todo TEST
156
157 return $this->precision;
158 }

References $precision.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

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

61 {
62 if ($this->getPrecision() == 0) {
63 if (!$this->isIntPrecisionValid(
64 $this->getIntprecision(),
65 $this->getRangeMin(),
66 $this->getRangeMax()
67 )) {
68 global $DIC;
69 $lng = $DIC['lng'];
70 $DIC->ui()->mainTemplate()->setOnScreenMessage(
71 "failure",
72 $lng->txt('err_divider_too_big')
73 );
74 }
75 }
76
77 include_once "./Services/Math/classes/class.ilMath.php";
78 $mul = ilMath::_pow(10, $this->getPrecision());
79 $r1 = round(ilMath::_mul($this->getRangeMin(), $mul));
80 $r2 = round(ilMath::_mul($this->getRangeMax(), $mul));
81 $calcval = $this->getRangeMin() - 1;
82 //test
83
84 $roundedRangeMIN = round($this->getRangeMin(), $this->getPrecision());
85 $roundedRangeMAX = round($this->getRangeMax(), $this->getPrecision());
86 while ($calcval < $roundedRangeMIN || $calcval > $roundedRangeMAX) {
87
88
89// while($calcval < $this->getRangeMin() || $calcval > $this->getRangeMax())
90 $rnd = mt_rand($r1, $r2);
91 $calcval = ilMath::_div($rnd, $mul, $this->getPrecision());
92 if (($this->getPrecision() == 0) && ($this->getIntprecision() != 0)) {
93 if ($this->getIntprecision() > 0) {
94 $modulo = $calcval % $this->getIntprecision();
95 if ($modulo != 0) {
96 if ($modulo < ilMath::_div($this->getIntprecision(), 2)) {
97 $calcval = ilMath::_sub($calcval, $modulo, $this->getPrecision());
98 } else {
99 $calcval = ilMath::_add($calcval, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
100 }
101 }
102 }
103 }
104 }
105 return $calcval;
106 }
isIntPrecisionValid($int_precision, $min_range, $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: feed.php:28
$lng

References $DIC, $lng, 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 194 of file class.assFormulaQuestionVariable.php.

194 : float
195 {
196 return (float) $this->range_max;
197 }

References $range_max.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

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

180 : float
181 {
182 return (float) $this->range_min;
183 }

References $range_min.

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

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

204 : ?object
205 {
206 return $this->unit;
207 }

References $unit.

Referenced by getBaseValue().

+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

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

134 {
135 return $this->value;
136 }

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

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

165 : string
166 {
167 return $this->variable;
168 }

References $variable.

◆ isIntPrecisionValid()

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

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

114 {
115 $min_abs = abs($min_range);
116 $max_abs = abs($max_range);
117 $bigger_abs = $max_abs > $min_abs ? $max_abs : $min_abs;
118 if ($int_precision > $bigger_abs) {
119 return false;
120 }
121 return true;
122 }

Referenced by getRandomValue().

+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

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

209 : void
210 {
211 $this->intprecision = $intprecision;
212 }

References $intprecision.

◆ setPrecision()

assFormulaQuestionVariable::setPrecision (   $precision)

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

148 : void
149 {
150 $this->precision = $precision;
151 }

References $precision.

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

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

185 : void
186 {
187 include_once "./Services/Math/classes/class.EvalMath.php";
188 $math = new EvalMath();
189 $math->suppress_errors = true;
190 $result = $math->evaluate($range_max);
191 $this->range_max = $result;
192 }

References $range_max.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt (   $range_max_txt)

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

219 : void
220 {
221 $this->range_max_txt = $range_max_txt;
222 }

References $range_max_txt.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin (   $range_min)

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

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

References $range_min.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt (   $range_min_txt)

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

229 : void
230 {
231 $this->range_min_txt = $range_min_txt;
232 }

References $range_min_txt.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUnit()

assFormulaQuestionVariable::setUnit (   $unit)

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

199 : void
200 {
201 $this->unit = $unit;
202 }

References $unit.

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

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

128 : void
129 {
130 $this->value = $value;
131 }

References $value.

Referenced by setRandomValue().

+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

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

160 : void
161 {
162 $this->variable = $variable;
163 }

References $variable.

Field Documentation

◆ $intprecision

assFormulaQuestionVariable::$intprecision
private

◆ $precision

assFormulaQuestionVariable::$precision
private

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

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

◆ $range_max

assFormulaQuestionVariable::$range_max
private

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

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

◆ $range_max_txt

assFormulaQuestionVariable::$range_max_txt
private

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

Referenced by getRangeMaxTxt(), and setRangeMaxTxt().

◆ $range_min

assFormulaQuestionVariable::$range_min
private

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

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

◆ $range_min_txt

assFormulaQuestionVariable::$range_min_txt
private

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

Referenced by getRangeMinTxt(), and setRangeMinTxt().

◆ $unit

assFormulaQuestionVariable::$unit
private

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

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

◆ $value

assFormulaQuestionVariable::$value
private

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

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

◆ $variable

assFormulaQuestionVariable::$variable
private

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

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


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