ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assFormulaQuestionVariable.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 private $variable;
13 private $range_min;
14 private $range_max;
15 private $unit;
16 private $value;
17 private $precision;
21
22
34 {
35 $this->variable = $variable;
36 $this->setRangeMin($range_min);
37 $this->setRangeMax($range_max);
38 $this->unit = $unit;
39 $this->value = NULL;
40 $this->precision = $precision;
41 $this->intprecision = $intprecision;
44 }
45
46 public function getRandomValue()
47 {
48
49// @todo check this
50
51 include_once "./Services/Math/classes/class.ilMath.php";
52 $mul = ilMath::_pow(10, $this->getPrecision());
53 $r1 = round(ilMath::_mul($this->getRangeMin(), $mul));
54 $r2 = round(ilMath::_mul($this->getRangeMax(), $mul));
55 $calcval = $this->getRangeMin() - 1;
56//test
57
58 $roundedRangeMIN = round($this->getRangeMin(), $this->getPrecision());
59 $roundedRangeMAX = round($this->getRangeMax(), $this->getPrecision());
60 while($calcval < $roundedRangeMIN || $calcval > $roundedRangeMAX)
61
62
63// while($calcval < $this->getRangeMin() || $calcval > $this->getRangeMax())
64 {
65 $rnd = mt_rand($r1, $r2);
66 $calcval = ilMath::_div($rnd, $mul, $this->getPrecision());
67 if(($this->getPrecision() == 0) && ($this->getIntprecision() != 0))
68 {
69 if($this->getIntprecision() > 0)
70 {
71 $modulo = $calcval % $this->getIntprecision();
72 if($modulo != 0)
73 {
74 if($modulo < ilMath::_div($this->getIntprecision(), 2))
75 {
76 $calcval = ilMath::_sub($calcval, $modulo, $this->getPrecision());
77 }
78 else
79 {
80 $calcval = ilMath::_add($calcval, ilMath::_sub($this->getIntprecision(), $modulo, $this->getPrecision()), $this->getPrecision());
81 }
82 }
83 }
84 }
85 }
86 return $calcval;
87 }
88
89 public function setRandomValue()
90 {
91 $this->setValue($this->getRandomValue());
92 }
93
94 /************************************
95 * Getter and Setter
96 ************************************/
97
98 function setValue($value)
99 {
100 $this->value = $value;
101 }
102
103 function getValue()
104 {
105 return $this->value;
106 }
107
108 function getBaseValue()
109 {
110 if(!is_object($this->getUnit()))
111 {
112 return $this->value;
113 }
114 else
115 {
116 include_once "./Services/Math/classes/class.ilMath.php";
117 return ilMath::_mul($this->value, $this->getUnit()->getFactor());
118 }
119 }
120
122 {
123 $this->precision = $precision;
124 }
125
126 function getPrecision()
127 {
128 //@todo TEST
129
130 return (int)$this->precision;
131 }
132
134 {
135 $this->variable = $variable;
136 }
137
138 function getVariable()
139 {
140 return $this->variable;
141 }
142
144 {
145 include_once "./Services/Math/classes/class.EvalMath.php";
146 $math = new EvalMath();
147 $math->suppress_errors = TRUE;
148 $result = $math->evaluate($range_min);
149
150 $this->range_min = $result;
151 }
152
153 function getRangeMin()
154 {
155 return (double)$this->range_min;
156 }
157
159 {
160 include_once "./Services/Math/classes/class.EvalMath.php";
161 $math = new EvalMath();
162 $math->suppress_errors = TRUE;
163 $result = $math->evaluate($range_max);
164 $this->range_max = $result;
165 }
166
167 function getRangeMax()
168 {
169 return (double)$this->range_max;
170 }
171
172 function setUnit($unit)
173 {
174 $this->unit = $unit;
175 }
176
177 function getUnit()
178 {
179 return $this->unit;
180 }
181
183 {
184 $this->intprecision = $intprecision;
185 }
186
188 {
189 return $this->intprecision;
190 }
191
193 {
194 $this->range_max_txt = $range_max_txt;
195 }
196
197 public function getRangeMaxTxt()
198 {
200 }
201
203 {
204 $this->range_min_txt = $range_min_txt;
205 }
206
207 public function getRangeMinTxt()
208 {
210 }
211
212}
213
214?>
$result
__construct($variable, $range_min, $range_max, $unit=null, $precision=0, $intprecision=1)
assFormulaQuestionVariable constructor
static _mul($left_operand, $right_operand, $scale=50)
static _div($left_operand, $right_operand, $scale=50)
static _pow($left_operand, $right_operand, $scale=50)
static _sub($left_operand, $right_operand, $scale=50)
static _add($left_operand, $right_operand, $scale=50)