ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
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 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 135 of file class.assFormulaQuestionVariable.php.

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

136  {
137  if (!is_object($this->getUnit())) {
138  return $this->value;
139  } else {
140  return ilMath::_mul($this->value, $this->getUnit()->getFactor());
141  }
142  }
static _mul($left_operand, $right_operand, int $scale=50)
+ Here is the call graph for this function:

◆ getIntprecision()

assFormulaQuestionVariable::getIntprecision ( )

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

References $intprecision.

Referenced by getRandomValue().

208  : int
209  {
210  return $this->intprecision;
211  }
+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

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

References $precision.

Referenced by getRandomValue().

149  : int
150  {
151  //@todo TEST
152 
153  return $this->precision;
154  }
+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

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

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

Referenced by setRandomValue().

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  $mul = ilMath::_pow(10, $this->getPrecision());
78  $r1 = round(ilMath::_mul($this->getRangeMin(), $mul));
79  $r2 = round(ilMath::_mul($this->getRangeMax(), $mul));
80  $calcval = $this->getRangeMin() - 1;
81  //test
82 
83  $roundedRangeMIN = round($this->getRangeMin(), $this->getPrecision());
84  $roundedRangeMAX = round($this->getRangeMax(), $this->getPrecision());
85  while ($calcval < $roundedRangeMIN || $calcval > $roundedRangeMAX) {
86  // while($calcval < $this->getRangeMin() || $calcval > $this->getRangeMax())
87  $rnd = mt_rand($r1, $r2);
88  $calcval = ilMath::_div($rnd, $mul, $this->getPrecision());
89  if (($this->getPrecision() == 0) && ($this->getIntprecision() != 0)) {
90  if ($this->getIntprecision() > 0) {
91  $modulo = $calcval % $this->getIntprecision();
92  if ($modulo != 0) {
93  if ($modulo < ilMath::_div($this->getIntprecision(), 2)) {
94  $calcval = ilMath::_sub($calcval, $modulo, $this->getPrecision());
95  } else {
96  $calcval = ilMath::_add($calcval, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
97  }
98  }
99  }
100  }
101  }
102  return $calcval;
103  }
static _add($left_operand, $right_operand, int $scale=50)
static _div($left_operand, $right_operand, int $scale=50)
static _pow($left_operand, $right_operand, int $scale=50)
static _sub($left_operand, $right_operand, int $scale=50)
$lng
$DIC
Definition: xapitoken.php:62
isIntPrecisionValid($int_precision, $min_range, $max_range)
static _mul($left_operand, $right_operand, int $scale=50)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRangeMax()

assFormulaQuestionVariable::getRangeMax ( )

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

References $range_max.

Referenced by getRandomValue().

188  : float
189  {
190  return (float) $this->range_max;
191  }
+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

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

References $range_min.

Referenced by getRandomValue().

175  : float
176  {
177  return (float) $this->range_min;
178  }
+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

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

References $unit.

Referenced by getBaseValue().

198  : ?object
199  {
200  return $this->unit;
201  }
+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

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

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

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

References $variable.

Referenced by assFormulaQuestionGUI\isSaveCommand().

161  : string
162  {
163  return $this->variable;
164  }
+ Here is the caller graph for this function:

◆ isIntPrecisionValid()

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

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

Referenced by getRandomValue().

111  {
112  $min_abs = abs($min_range);
113  $max_abs = abs($max_range);
114  $bigger_abs = $max_abs > $min_abs ? $max_abs : $min_abs;
115  if ($int_precision > $bigger_abs) {
116  return false;
117  }
118  return true;
119  }
+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

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

References $intprecision.

203  : void
204  {
205  $this->intprecision = $intprecision;
206  }

◆ setPrecision()

assFormulaQuestionVariable::setPrecision (   $precision)

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

References $precision.

144  : void
145  {
146  $this->precision = $precision;
147  }

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

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

References $range_max.

Referenced by __construct().

180  : void
181  {
182  $math = new EvalMath();
183  $math->suppress_errors = true;
184  $result = $math->evaluate($range_max);
185  $this->range_max = $result;
186  }
+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt (   $range_max_txt)

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

References $range_max_txt.

Referenced by __construct().

213  : void
214  {
215  $this->range_max_txt = $range_max_txt;
216  }
+ Here is the caller graph for this function:

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin (   $range_min)

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

References $range_min.

Referenced by __construct().

166  : void
167  {
168  $math = new EvalMath();
169  $math->suppress_errors = true;
170  $result = $math->evaluate($range_min);
171 
172  $this->range_min = $result;
173  }
+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt (   $range_min_txt)

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

References $range_min_txt.

Referenced by __construct(), and assFormulaQuestionGUI\writePostData().

223  : void
224  {
225  $this->range_min_txt = $range_min_txt;
226  }
+ Here is the caller graph for this function:

◆ setUnit()

assFormulaQuestionVariable::setUnit (   $unit)

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

References $unit.

193  : void
194  {
195  $this->unit = $unit;
196  }

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

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

References $value.

Referenced by setRandomValue().

125  : void
126  {
127  $this->value = $value;
128  }
+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

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

References $variable.

156  : void
157  {
158  $this->variable = $variable;
159  }

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: