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 include_once './payment/classes/class.ilPaymentPrices.php';
00032 include_once './payment/classes/class.ilPaymentObject.php';
00033
00034 class ilPaymentShoppingCart
00035 {
00036
00037
00038
00039 var $user_obj = null;
00040 var $db = null;
00041
00042 var $sc_entries = array();
00043
00044 function ilPaymentShoppingCart(&$user_obj)
00045 {
00046 global $ilDB;
00047
00048 $this->user_obj =& $user_obj;
00049 $this->db =& $ilDB;
00050
00051 $this->__read();
00052 }
00053
00054 function setPobjectId($a_pobject_id)
00055 {
00056 $this->pobject_id = $a_pobject_id;
00057 }
00058 function getPobjectId()
00059 {
00060 return $this->pobject_id;
00061 }
00062 function setPriceId($a_price_id)
00063 {
00064 $this->price_id = $a_price_id;
00065 }
00066 function getPriceId()
00067 {
00068 return $this->price_id;
00069 }
00070
00071 function getEntries($a_pay_method = 0)
00072 {
00073 if ($a_pay_method == 0)
00074 {
00075 return $this->sc_entries ? $this->sc_entries : array();
00076 }
00077 else
00078 {
00079 $tmp_entries = array();
00080 foreach($this->sc_entries as $entry)
00081 {
00082 if ($entry["pay_method"] == $a_pay_method)
00083 {
00084 $tmp_entries[$entry["psc_id"]] = $entry;
00085 }
00086 }
00087 return $tmp_entries;
00088 }
00089 }
00090 function setTotalAmount($a_total_amount)
00091 {
00092 $this->total_amount = $a_total_amount;
00093 }
00094 function getTotalAmount()
00095 {
00096 return $this->total_amount;
00097 }
00098
00099 function isInShoppingCart($a_pobject_id)
00100 {
00101 $query = "SELECT * FROM payment_shopping_cart ".
00102 "WHERE customer_id = '".$this->user_obj->getId()."' ".
00103 "AND pobject_id = '".$a_pobject_id."'";
00104
00105 $res = $this->db->query($query);
00106
00107 return $res->numRows() ? true : false;
00108 }
00109
00110 function getEntry($a_pobject_id)
00111 {
00112 $query = "SELECT * FROM payment_shopping_cart ".
00113 "WHERE customer_id = '".$this->user_obj->getId()."' ".
00114 "AND pobject_id = '".$a_pobject_id."'";
00115
00116 $r = $this->db->query($query);
00117
00118 if (is_object($r))
00119 {
00120 return $r->fetchRow(DB_FETCHMODE_ASSOC);
00121 }
00122 }
00123
00124 function add()
00125 {
00126
00127 $query = "DELETE FROM payment_shopping_cart ".
00128 "WHERE customer_id = '".$this->user_obj->getId()."' ".
00129 "AND pobject_id = '".$this->getPobjectId()."'";
00130
00131 $this->db->query($query);
00132
00133 $query = "INSERT INTO payment_shopping_cart ".
00134 "SET customer_id = '".$this->user_obj->getId()."', ".
00135 "pobject_id = '".$this->getPobjectId()."', ".
00136 "price_id = '".$this->getPriceId()."'";
00137
00138 $this->db->query($query);
00139
00140 $this->__read();
00141
00142 return true;
00143 }
00144
00145 function update($a_psc_id)
00146 {
00147 $query = "UPDATE payment_shopping_cart ".
00148 "SET customer_id = '".$this->user_obj->getId()."',' ".
00149 "pobject_id = '".$this->getPobjectId()."',' ".
00150 "price_id = '".$this->getPriceId()."' ".
00151 "WHERE psc_id = '".$a_psc_id."'";
00152
00153 $this->db->query($query);
00154
00155 $this->__read();
00156
00157 return true;
00158 }
00159
00160 function delete($a_psc_id)
00161 {
00162 $query = "DELETE FROM payment_shopping_cart ".
00163 "WHERE psc_id = '".$a_psc_id."'";
00164
00165 $this->db->query($query);
00166
00167 $this->__read();
00168 }
00169
00170 function emptyShoppingCart()
00171 {
00172 $query = "DELETE FROM payment_shopping_cart ".
00173 "WHERE customer_id = '".$this->user_obj->getId()."'";
00174
00175 $this->db->query($query);
00176
00177 $this->__read();
00178
00179 return true;
00180 }
00181
00182
00183 function _hasEntries($a_user_id)
00184 {
00185 global $ilDB;
00186
00187 $query = "SELECT * FROM payment_shopping_cart ".
00188 "WHERE customer_id = '".$a_user_id."'";
00189
00190 $res = $ilDB->query($query);
00191
00192 return $res->numRows() ? true : false;
00193 }
00194
00195
00196
00197 function __read()
00198 {
00199 include_once './payment/classes/class.ilPaymentPrices.php';
00200
00201 $this->sc_entries = array();
00202
00203 $query = "SELECT * FROM payment_shopping_cart ".
00204 "WHERE customer_id = '".$this->user_obj->getId()."'";
00205
00206 $res = $this->db->query($query);
00207
00208 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00209 {
00210 $this->sc_entries[$row->psc_id]["psc_id"] = $row->psc_id;
00211 $this->sc_entries[$row->psc_id]["customer_id"] = $row->customer_id;
00212 $this->sc_entries[$row->psc_id]["pobject_id"] = $row->pobject_id;
00213 $this->sc_entries[$row->psc_id]["price_id"] = $row->price_id;
00214 }
00215
00216
00217 unset($prices);
00218 foreach($this->sc_entries as $entry)
00219 {
00220
00221 if(!ilPaymentPrices::_priceExists($entry['price_id'],$entry['pobject_id']))
00222 {
00223 $this->delete($entry['psc_id']);
00224 return false;
00225 }
00226
00227
00228 $tmp_pobj =& new ilPaymentObject($this->user_obj,$entry['pobject_id']);
00229 if(($pay_method = $tmp_pobj->getPayMethod()) == $tmp_pobj->PAY_METHOD_BILL)
00230 {
00231 $this->delete($entry['psc_id']);
00232 return false;
00233 }
00234
00235
00236 if($tmp_pobj->getStatus() == $tmp_pobj->STATUS_EXPIRES)
00237 {
00238 $this->delete($entry['psc_id']);
00239
00240 return false;
00241 }
00242
00243 $this->sc_entries[$entry["psc_id"]]["pay_method"] = $pay_method;
00244
00245 $prices[] = array(
00246 "id" => $entry['price_id'],
00247 "pay_method" => $pay_method
00248 );
00249 unset($tmp_pobj);
00250 }
00251
00252
00253 $this->setTotalAmount(ilPaymentPrices::_getTotalAmount($prices ? $prices : array()));
00254
00255 return true;
00256 }
00257
00258 function getShoppingCart($a_pay_method = 0)
00259 {
00260 if(!count($items = $this->getEntries($a_pay_method)))
00261 {
00262 return 0;
00263 }
00264
00265 $counter = 0;
00266 foreach($items as $item)
00267 {
00268 $tmp_pobject =& new ilPaymentObject($this->user_obj,$item['pobject_id']);
00269
00270 $tmp_obj =& ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId());
00271
00272 $f_result[$counter]["pobject_id"] = $item['pobject_id'];
00273 $f_result[$counter]["obj_id"] = $tmp_obj->getId();
00274 $f_result[$counter]["typ"] = $tmp_obj->getType();
00275 $f_result[$counter]["buchungstext"] = $tmp_obj->getTitle();
00276
00277 $price_data = ilPaymentPrices::_getPrice($item['price_id']);
00278 $price_string = ilPaymentPrices::_getPriceString($item['price_id']);
00279
00280 $price = ((int) $price_data["unit_value"]) . "." . ((int) $price_data["sub_unit_value"]);
00281
00282 $f_result[$counter]["betrag"] = (float) $price;
00283 $f_result[$counter]["betrag_string"] = $price_string;
00284 $f_result[$counter]["dauer"] = $price_data["duration"];
00285
00286 unset($tmp_obj);
00287 unset($tmp_pobject);
00288
00289 ++$counter;
00290 }
00291 return $f_result;
00292 }
00293
00294 function getTotalAmountValue($a_pay_method = 0)
00295 {
00296 $amount = 0.0;
00297
00298 if (is_array($result = $this->getShoppingCart($a_pay_method)))
00299 {
00300 for ($i = 0; $i < count($result); $i++)
00301 {
00302 $amount += $result[$i]["betrag"];
00303 }
00304 }
00305
00306 return (float) $amount;
00307 }
00308
00309 function getVat($a_amount = 0)
00310 {
00311 include_once './payment/classes/class.ilGeneralSettings.php';
00312
00313 $genSet = new ilGeneralSettings();
00314
00315 return (float) ($a_amount - (round(($a_amount / (1 + ($genSet->get("vat_rate") / 100.0))) * 100) / 100));
00316 }
00317
00318 }
00319 ?>