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 = array();
00142
00143 if (is_array($a_price_ids))
00144 {
00145 for ($i = 0; $i < count($a_price_ids); $i++)
00146 {
00147 $price_data = ilPaymentPrices::_getPrice($a_price_ids[$i]["id"]);
00148
00149 $price = ((int) $price_data["unit_value"]) . "." . ((int) $price_data["sub_unit_value"]);
00150 $amount[$a_price_ids[$i]["pay_method"]] += (float) $price;
00151 }
00152 }
00153
00154 return $amount;
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 }
00190
00191
00192 function setUnitValue($a_value = 0)
00193 {
00194
00195 $this->unit_value = preg_replace('/^0+/','',$a_value);
00196 }
00197 function setSubUnitValue($a_value = 0)
00198 {
00199 $this->sub_unit_value = $a_value;
00200 }
00201 function setCurrency($a_currency_id)
00202 {
00203 $this->currency = $a_currency_id;
00204 }
00205 function setDuration($a_duration)
00206 {
00207 $this->duration = $a_duration;
00208 }
00209
00210 function add()
00211 {
00212 $query = "INSERT INTO payment_prices SET ".
00213 "pobject_id = '".$this->getPobjectId()."', ".
00214 "currency = '".$this->__getCurrency()."', ".
00215 "duration = '".$this->__getDuration()."', ".
00216 "unit_value = '".$this->__getUnitValue()."', ".
00217 "sub_unit_value = '".$this->__getSubUnitValue()."'";
00218
00219 $res = $this->db->query($query);
00220
00221 $this->__read();
00222
00223 return true;
00224 }
00225 function update($a_price_id)
00226 {
00227
00228 $query = "UPDATE payment_prices SET ".
00229 "currency = '".$this->__getCurrency()."', ".
00230 "duration = '".$this->__getDuration()."', ".
00231 "unit_value = '".$this->__getUnitValue()."', ".
00232 "sub_unit_value = '".$this->__getSubUnitValue()."' ".
00233 "WHERE price_id = '".$a_price_id."'";
00234
00235 $res = $this->db->query($query);
00236
00237 $this->__read();
00238
00239 return true;
00240 }
00241 function delete($a_price_id)
00242 {
00243 $query = "DELETE FROM payment_prices ".
00244 "WHERE price_id = '".$a_price_id."'";
00245
00246 $res = $this->db->query($query);
00247
00248
00249 $this->__read();
00250
00251 return true;
00252 }
00253 function deleteAllPrices()
00254 {
00255 $query = "DELETE FROM payment_prices ".
00256 "WHERE pobject_id = '".$this->getPobjectId()."'";
00257
00258 $res = $this->db->query($query);
00259
00260 $this->__read();
00261
00262 return true;
00263 }
00264
00265 function validate()
00266 {
00267 $duration_valid = false;
00268 $price_valid = false;
00269
00270 if(preg_match('/^[1-9][0-9]{0,1}$/',$this->__getDuration()))
00271 {
00272 $duration_valid = true;
00273 }
00274
00275 if(preg_match('/^[1-9]\d{0,4}$/',$this->__getUnitValue()) and
00276 preg_match('/^\d{0,2}$/',$this->__getSubUnitValue()))
00277 {
00278 $price_valid = true;
00279 }
00280 else if(preg_match('/^\d{0,5}$/',$this->__getUnitValue()) and
00281 preg_match('/[1-9]/',$this->__getSubUnitValue()))
00282 {
00283 return true;
00284 }
00285 return $duration_valid and $price_valid;
00286 }
00287
00288 function _priceExists($a_price_id,$a_pobject_id)
00289 {
00290 global $ilDB;
00291
00292 $query = "SELECT * FROM payment_prices ".
00293 "WHERE price_id = '".$a_price_id."' ".
00294 "AND pobject_id = '".$a_pobject_id."'";
00295
00296 $res = $ilDB->query($query);
00297
00298 return $res->numRows() ? true : false;
00299 }
00300
00301
00302
00303
00304 function __getUnitValue()
00305 {
00306 return $this->unit_value;
00307 }
00308 function __getSubUnitValue()
00309 {
00310 return $this->sub_unit_value;
00311 }
00312 function __getCurrency()
00313 {
00314 return $this->currency;
00315 }
00316 function __getDuration()
00317 {
00318 return $this->duration;
00319 }
00320
00321 function __read()
00322 {
00323 $this->prices = array();
00324
00325 $query = "SELECT * FROM payment_prices ".
00326 "WHERE pobject_id = '".$this->getPobjectId()."' ".
00327 "ORDER BY duration";
00328
00329 $res = $this->db->query($query);
00330 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00331 {
00332 $this->prices[$row->price_id]['pobject_id'] = $row->pobject_id;
00333 $this->prices[$row->price_id]['price_id'] = $row->price_id;
00334 $this->prices[$row->price_id]['currency'] = $row->currency;
00335 $this->prices[$row->price_id]['duration'] = $row->duration;
00336 $this->prices[$row->price_id]['unit_value'] = $row->unit_value;
00337 $this->prices[$row->price_id]['sub_unit_value'] = $row->sub_unit_value;
00338 }
00339 }
00340 }
00341 ?>