Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00031 class ilPaymentPrices
00032 {
00033 var $ilDB;
00034
00035 var $pobject_id;
00036 var $unit_value;
00037 var $sub_unit_value;
00038 var $currency;
00039 var $duration;
00040
00041 var $prices;
00042
00043 function ilPaymentPrices($a_pobject_id = 0)
00044 {
00045 global $ilDB;
00046
00047 $this->db =& $ilDB;
00048
00049 $this->pobject_id = $a_pobject_id;
00050
00051 $this->__read();
00052 }
00053
00054
00055 function getPobjectId()
00056 {
00057 return $this->pobject_id;
00058 }
00059
00060 function getPrices()
00061 {
00062 return $this->prices ? $this->prices : array();
00063 }
00064 function getPrice($a_price_id)
00065 {
00066 return $this->prices[$a_price_id] ? $this->prices[$a_price_id] : array();
00067 }
00068
00069
00070 function _getPrice($a_price_id)
00071 {
00072 global $ilDB;
00073
00074 $query = "SELECT * FROM payment_prices ".
00075 "WHERE price_id = '".$a_price_id."'";
00076
00077 $res = $ilDB->query($query);
00078
00079 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00080 {
00081 $price['duration'] = $row->duration;
00082 $price['currency'] = $row->currency;
00083 $price['unit_value'] = $row->unit_value;
00084 $price['sub_unit_value'] = $row->sub_unit_value;
00085 }
00086 return count($price) ? $price : array();
00087 }
00088
00089 function _countPrices($a_pobject_id)
00090 {
00091 $query = "SELECT count(price_id) FROM payment_prices ".
00092 "WHERE pobject_id = '".$a_pobject_id."'";
00093
00094 $res = $this->db->query($query);
00095 $row = $res->fetchRow(DB_FETCHMODE_ARRAY);
00096
00097 return ($row[0]);
00098 }
00099
00100 function _getPriceString($a_price_id)
00101 {
00102 include_once './payment/classes/class.ilPaymentCurrency.php';
00103 include_once './payment/classes/class.ilGeneralSettings.php';
00104
00105 global $lng;
00106
00107 $genSet = new ilGeneralSettings();
00108 $unit_string = $genSet->get("currency_unit");
00109
00110 $pr_str = '';
00111 $price = ilPaymentPrices::_getPrice($a_price_id);
00112
00113 $pr_str = number_format( ((int) $price["unit_value"]) . "." . ((int) $price["sub_unit_value"]) , 2, ",", ".");
00114 return $pr_str . " " . $unit_string;
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 }
00129
00130 function _getTotalAmount($a_price_ids)
00131 {
00132 include_once './payment/classes/class.ilPaymentPrices.php';
00133 # include_once './payment/classes/class.ilPaymentCurrency.php';
00134 include_once './payment/classes/class.ilGeneralSettings.php';
00135
00136 global $ilDB,$lng;
00137
00138 $genSet = new ilGeneralSettings();
00139 $unit_string = $genSet->get("currency_unit");
00140
00141 $amount = 0.0;
00142
00143 foreach($a_price_ids as $id)
00144 {
00145 $price_data = ilPaymentPrices::_getPrice($id);
00146
00147 $price = ((int) $price_data["unit_value"]) . "." . ((int) $price_data["sub_unit_value"]);
00148 $amount += (float) $price;
00149 }
00150
00151 return $amount;
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 }
00187
00188
00189 function setUnitValue($a_value = 0)
00190 {
00191
00192 $this->unit_value = preg_replace('/^0+/','',$a_value);
00193 }
00194 function setSubUnitValue($a_value = 0)
00195 {
00196 $this->sub_unit_value = $a_value;
00197 }
00198 function setCurrency($a_currency_id)
00199 {
00200 $this->currency = $a_currency_id;
00201 }
00202 function setDuration($a_duration)
00203 {
00204 $this->duration = $a_duration;
00205 }
00206
00207 function add()
00208 {
00209 $query = "INSERT INTO payment_prices SET ".
00210 "pobject_id = '".$this->getPobjectId()."', ".
00211 "currency = '".$this->__getCurrency()."', ".
00212 "duration = '".$this->__getDuration()."', ".
00213 "unit_value = '".$this->__getUnitValue()."', ".
00214 "sub_unit_value = '".$this->__getSubUnitValue()."'";
00215
00216 $res = $this->db->query($query);
00217
00218 $this->__read();
00219
00220 return true;
00221 }
00222 function update($a_price_id)
00223 {
00224
00225 $query = "UPDATE payment_prices SET ".
00226 "currency = '".$this->__getCurrency()."', ".
00227 "duration = '".$this->__getDuration()."', ".
00228 "unit_value = '".$this->__getUnitValue()."', ".
00229 "sub_unit_value = '".$this->__getSubUnitValue()."' ".
00230 "WHERE price_id = '".$a_price_id."'";
00231
00232 $res = $this->db->query($query);
00233
00234 $this->__read();
00235
00236 return true;
00237 }
00238 function delete($a_price_id)
00239 {
00240 $query = "DELETE FROM payment_prices ".
00241 "WHERE price_id = '".$a_price_id."'";
00242
00243 $res = $this->db->query($query);
00244
00245
00246 $this->__read();
00247
00248 return true;
00249 }
00250 function deleteAllPrices()
00251 {
00252 $query = "DELETE FROM payment_prices ".
00253 "WHERE pobject_id = '".$this->getPobjectId()."'";
00254
00255 $res = $this->db->query($query);
00256
00257 $this->__read();
00258
00259 return true;
00260 }
00261
00262 function validate()
00263 {
00264 $duration_valid = false;
00265 $price_valid = false;
00266
00267 if(preg_match('/^[1-9][0-9]{0,1}$/',$this->__getDuration()))
00268 {
00269 $duration_valid = true;
00270 }
00271
00272 if(preg_match('/^[1-9]\d{0,4}$/',$this->__getUnitValue()) and
00273 preg_match('/^\d{0,2}$/',$this->__getSubUnitValue()))
00274 {
00275 $price_valid = true;
00276 }
00277 else if(preg_match('/^\d{0,5}$/',$this->__getUnitValue()) and
00278 preg_match('/[1-9]/',$this->__getSubUnitValue()))
00279 {
00280 return true;
00281 }
00282 return $duration_valid and $price_valid;
00283 }
00284
00285 function _priceExists($a_price_id,$a_pobject_id)
00286 {
00287 global $ilDB;
00288
00289 $query = "SELECT * FROM payment_prices ".
00290 "WHERE price_id = '".$a_price_id."' ".
00291 "AND pobject_id = '".$a_pobject_id."'";
00292
00293 $res = $ilDB->query($query);
00294
00295 return $res->numRows() ? true : false;
00296 }
00297
00298
00299
00300
00301 function __getUnitValue()
00302 {
00303 return $this->unit_value;
00304 }
00305 function __getSubUnitValue()
00306 {
00307 return $this->sub_unit_value;
00308 }
00309 function __getCurrency()
00310 {
00311 return $this->currency;
00312 }
00313 function __getDuration()
00314 {
00315 return $this->duration;
00316 }
00317
00318 function __read()
00319 {
00320 $this->prices = array();
00321
00322 $query = "SELECT * FROM payment_prices ".
00323 "WHERE pobject_id = '".$this->getPobjectId()."' ".
00324 "ORDER BY duration";
00325
00326 $res = $this->db->query($query);
00327 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00328 {
00329 $this->prices[$row->price_id]['pobject_id'] = $row->pobject_id;
00330 $this->prices[$row->price_id]['price_id'] = $row->price_id;
00331 $this->prices[$row->price_id]['currency'] = $row->currency;
00332 $this->prices[$row->price_id]['duration'] = $row->duration;
00333 $this->prices[$row->price_id]['unit_value'] = $row->unit_value;
00334 $this->prices[$row->price_id]['sub_unit_value'] = $row->sub_unit_value;
00335 }
00336 }
00337 }
00338 ?>