ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 26 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 32 of file class.assFormulaQuestionVariable.php.

References setRangeMax(), and setRangeMin().

39  {
40  $this->setRangeMin($range_min_txt);
41  $this->setRangeMax($range_max_txt);
42  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getBaseValue()

assFormulaQuestionVariable::getBaseValue ( )

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

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

123  {
124  if (!is_object($this->getUnit())) {
125  return $this->value;
126  } else {
127  return ilMath::_mul($this->value, $this->getUnit()->getFactor());
128  }
129  }
static _mul($left_operand, $right_operand, int $scale=50)
+ Here is the call graph for this function:

◆ getIntprecision()

assFormulaQuestionVariable::getIntprecision ( )

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

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

190  : int
191  {
192  return $this->intprecision;
193  }
+ Here is the caller graph for this function:

◆ getPrecision()

assFormulaQuestionVariable::getPrecision ( )

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

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

136  : int
137  {
138  return $this->precision;
139  }
+ Here is the caller graph for this function:

◆ getRandomValue()

assFormulaQuestionVariable::getRandomValue ( )

Definition at line 44 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().

45  {
46  if ($this->getPrecision() === 0
47  && !$this->isIntPrecisionValid(
48  $this->getIntprecision(),
49  $this->getRangeMin(),
50  $this->getRangeMax()
51  )
52  ) {
53  global $DIC;
54  $lng = $DIC['lng'];
55  $DIC->ui()->mainTemplate()->setOnScreenMessage(
56  "failure",
57  $lng->txt('err_divider_too_big')
58  );
59  }
60 
61  $mul = ilMath::_pow(10, $this->getPrecision());
62  $r1 = round((float) ilMath::_mul($this->getRangeMin(), $mul));
63  $r2 = round((float) ilMath::_mul($this->getRangeMax(), $mul));
64  $calcval = $this->getRangeMin() - 1;
65  //test
66 
67  $roundedRangeMIN = round($this->getRangeMin(), $this->getPrecision());
68  $roundedRangeMAX = round($this->getRangeMax(), $this->getPrecision());
69  while ($calcval < $roundedRangeMIN || $calcval > $roundedRangeMAX) {
70  // while($calcval < $this->getRangeMin() || $calcval > $this->getRangeMax())
71  $rnd = mt_rand((int) $r1, (int) $r2);
72  $calcval = ilMath::_div($rnd, $mul, $this->getPrecision());
73  if (($this->getPrecision() == 0) && ($this->getIntprecision() != 0)) {
74  if ($this->getIntprecision() > 0) {
75  $modulo = $calcval % $this->getIntprecision();
76  if ($modulo != 0) {
77  if ($modulo < ilMath::_div($this->getIntprecision(), 2)) {
78  $calcval = ilMath::_sub($calcval, $modulo, $this->getPrecision());
79  } else {
80  $calcval = ilMath::_add($calcval, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
81  }
82  }
83  }
84  }
85  }
86  return $calcval;
87  }
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)
global $DIC
Definition: shib_login.php:22
isIntPrecisionValid(?int $int_precision, float $min_range, float $max_range)
global $lng
Definition: privfeed.php:31
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 170 of file class.assFormulaQuestionVariable.php.

References $range_max.

Referenced by getRandomValue().

170  : float
171  {
172  return $this->range_max;
173  }
+ Here is the caller graph for this function:

◆ getRangeMaxTxt()

assFormulaQuestionVariable::getRangeMaxTxt ( )

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

Referenced by assFormulaQuestion\buildVariablesForLog().

200  : string
201  {
202  return $this->range_max_txt;
203  }
+ Here is the caller graph for this function:

◆ getRangeMin()

assFormulaQuestionVariable::getRangeMin ( )

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

References $range_min.

Referenced by getRandomValue().

158  : float
159  {
160  return $this->range_min;
161  }
+ Here is the caller graph for this function:

◆ getRangeMinTxt()

assFormulaQuestionVariable::getRangeMinTxt ( )

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

Referenced by assFormulaQuestion\buildVariablesForLog().

210  : string
211  {
212  return $this->range_min_txt;
213  }
+ Here is the caller graph for this function:

◆ getUnit()

assFormulaQuestionVariable::getUnit ( )

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

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

181  {
182  return $this->unit;
183  }
+ Here is the caller graph for this function:

◆ getValue()

assFormulaQuestionVariable::getValue ( )

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

References $value.

◆ getVariable()

assFormulaQuestionVariable::getVariable ( )

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

Referenced by assFormulaQuestion\addVariable(), assFormulaQuestion\buildVariablesForLog(), assFormulaQuestionGUI\getSolutionOutput(), and assFormulaQuestionGUI\resetSavedPreviewSession().

146  : string
147  {
148  return $this->variable;
149  }
+ Here is the caller graph for this function:

◆ isIntPrecisionValid()

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

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

References null.

Referenced by getRandomValue().

95  {
96  if ($int_precision === null) {
97  return false;
98  }
99  $min_abs = abs($min_range);
100  $max_abs = abs($max_range);
101  $bigger_abs = $max_abs > $min_abs ? $max_abs : $min_abs;
102  if ($int_precision > $bigger_abs) {
103  return false;
104  }
105  return true;
106  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ setIntprecision()

assFormulaQuestionVariable::setIntprecision (   $intprecision)

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

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

◆ setPrecision()

assFormulaQuestionVariable::setPrecision ( int  $precision)

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

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

◆ setRandomValue()

assFormulaQuestionVariable::setRandomValue ( )

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

Referenced by __construct().

163  : void
164  {
165  $math = new EvalMath();
166  $math->suppress_errors = true;
167  $this->range_max = (float) $math->evaluate($range_max);
168  }
+ Here is the caller graph for this function:

◆ setRangeMaxTxt()

assFormulaQuestionVariable::setRangeMaxTxt ( string  $range_max_txt)

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

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

◆ setRangeMin()

assFormulaQuestionVariable::setRangeMin ( string  $range_min)

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

Referenced by __construct().

151  : void
152  {
153  $math = new EvalMath();
154  $math->suppress_errors = true;
155  $this->range_min = (float) $math->evaluate($range_min);
156  }
+ Here is the caller graph for this function:

◆ setRangeMinTxt()

assFormulaQuestionVariable::setRangeMinTxt ( string  $range_min_txt)

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

205  : void
206  {
207  $this->range_min_txt = $range_min_txt;
208  }

◆ setUnit()

assFormulaQuestionVariable::setUnit ( ?assFormulaQuestionUnit  $unit)

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

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

◆ setValue()

assFormulaQuestionVariable::setValue (   $value)

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

References $value.

Referenced by setRandomValue().

112  : void
113  {
114  $this->value = $value;
115  }
+ Here is the caller graph for this function:

◆ setVariable()

assFormulaQuestionVariable::setVariable (   $variable)

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

141  : void
142  {
143  $this->variable = $variable;
144  }

Field Documentation

◆ $range_max

float assFormulaQuestionVariable::$range_max
private

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

Referenced by getRangeMax().

◆ $range_min

float assFormulaQuestionVariable::$range_min
private

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

Referenced by getRangeMin().

◆ $value

assFormulaQuestionVariable::$value = null
private

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

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


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