39 $this->pobject_id = $a_pobject_id;
46 $this->price_type = $a_price_type;
65 return $this->prices ? $this->prices : array();
69 return $this->prices[$a_price_id] ? $this->prices[$a_price_id] : array();
78 $res = $ilDB->queryf(
'
79 SELECT * FROM payment_prices
81 array(
'integer'), array($a_price_id));
83 while(
$row = $ilDB->fetchObject(
$res))
87 $price[
'duration_until'] =
$row->duration_until;
89 $price[
'unlimited_duration'] =
$row->unlimited_duration;
91 $price[
'price'] = number_format(
$row->price, 2,
'.',
'');
103 $res = $ilDB->queryf(
'
104 SELECT count(price_id) FROM payment_prices
105 WHERE pobject_id = %s',
107 array($a_pobject_id));
126 $system_lng = $lng->getDefaultLanguage();
129 $use_comma_seperator = array(
'ar',
'bg',
'cs',
'de',
'da',
'es',
'et',
'it',
130 'fr',
'nl',
'el',
'sr',
'uk',
'ru',
'ro',
'tr',
'pl',
'lt',
'pt',
'sq',
'hu');
134 if(in_array($system_lng, $use_comma_seperator))
136 $gui_price = number_format((
float)$a_price, 2,
',',
'');
139 $gui_price = number_format((
float)$a_price, 2,
'.',
'');
146 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
149 $currency_unit = $genSet->get(
'currency_unit');
153 return $gui_price .
' ' . $currency_unit;
160 include_once
'./Services/Payment/classes/class.ilPaymentCurrency.php';
161 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
164 $currency_unit = $genSet->get(
"currency_unit");
167 $pr_str .= number_format($a_price , 2,
",",
".");
169 return $pr_str .
" " . $currency_unit;
175 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
179 if (is_array($a_price_ids))
181 for ($i = 0; $i < count($a_price_ids); $i++)
185 $price = (float) $price_data[
"price"];
186 $amount[$a_price_ids[$i][
"pay_method"]] += (float)
$price;
195 $this->price = preg_replace(
'/,/',
'.',$a_price);
196 $this->price = (float)$a_price;
201 $this->currency = $a_currency_id;
205 if($this->unlimited_duration ==
'1' && ($a_duration ==
'' || null))
208 $this->duration = (int)$a_duration;
213 if($a_unlimited_duration)
214 $this->unlimited_duration = (int)$a_unlimited_duration;
216 $this->unlimited_duration = 0;
222 $this->extension = (int)$a_extension;
233 $next_id = $this->db->nextId(
'payment_prices');
235 $res = $this->db->insert(
'payment_prices', array(
236 'price_id' => array(
'integer', $next_id),
237 'pobject_id' => array(
'integer', $this->
getPobjectId()),
241 'price' => array(
'float', $this->
__getPrice()),
254 $this->db->update(
'payment_prices',
255 array(
'pobject_id' => array(
'integer', $this->
getPobjectId()),
259 'price' => array(
'float', $this->
__getPrice()),
266 array(
'price_id'=> array(
'integer', $a_price_id)));
272 public function delete($a_price_id)
274 $statement = $this->db->manipulateF(
'
275 DELETE FROM payment_prices
276 WHERE price_id = %s',
277 array(
'integer'), array($a_price_id));
285 $statement = $this->db->manipulateF(
'
286 DELETE FROM payment_prices
287 WHERE pobject_id = %s',
306 include_once
'Services/Payment/exceptions/class.ilShopException.php';
310 case self::TYPE_DURATION_MONTH:
311 if(!preg_match(
'/^[1-9][0-9]{0,1}$/', $this->
__getDuration()))
315 case self::TYPE_DURATION_DATE:
316 if(!preg_match(
'/^[0-9]{4,4}-[0-9]{1,2}-[0-9]{1,2}$/', $this->
__getDurationFrom()))
317 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from'));
320 if(!checkdate($from_date[1], $from_date[2], $from_date[0]))
321 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from'));
324 throw new ilShopException($lng->txt(
'payment_price_invalid_date_until'));
327 if(!checkdate($till_date[1], $till_date[2], $till_date[0]))
328 throw new ilShopException($lng->txt(
'payment_price_invalid_date_until'));
330 $from = mktime(12, 12, 12, $from_date[1], $from_date[2], $from_date[0]);
331 $till = mktime(12, 12, 12, $till_date[1], $till_date[2], $till_date[0]);
334 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from_gt_until'));
337 case self::TYPE_UNLIMITED_DURATION:
342 throw new ilShopException($lng->txt(
'payment_no_price_type_selected_sdf'));
358 $res = $ilDB->queryf(
'
359 SELECT * FROM payment_prices
361 AND pobject_id = %s',
362 array(
'integer',
'integer'),
363 array($a_price_id, $a_pobject_id));
365 return $res->numRows() ?
true :
false;
377 if($this->currency == null)
390 private function __read($with_extension_prices =
false)
392 $this->prices = array();
394 if(!$with_extension_prices)
396 $res = $this->db->queryf(
'
397 SELECT * FROM payment_prices
398 WHERE pobject_id = %s
401 array(
'integer',
'integer'),
407 $res = $this->db->queryf(
'
408 SELECT * FROM payment_prices
409 WHERE pobject_id = %s
415 while(
$row = $this->db->fetchObject(
$res))
417 $this->prices[
$row->price_id][
'pobject_id'] =
$row->pobject_id;
418 $this->prices[
$row->price_id][
'price_id'] =
$row->price_id;
419 $this->prices[
$row->price_id][
'currency'] =
$row->currency;
420 $this->prices[
$row->price_id][
'duration'] =
$row->duration;
421 $this->prices[
$row->price_id][
'unlimited_duration'] =
$row->unlimited_duration;
422 $this->prices[
$row->price_id][
'price'] =
$row->price;
423 $this->prices[
$row->price_id][
'extension'] =
$row->extension;
424 $this->prices[
$row->price_id][
'duration_from'] =
$row->duration_from;
425 $this->prices[
$row->price_id][
'duration_until'] =
$row->duration_until;
426 $this->prices[
$row->price_id][
'description'] =
$row->description;
427 $this->prices[
$row->price_id][
'price_type'] =
$row->price_type;
435 $res = $this->db->queryf(
'
436 SELECT * FROM payment_prices
437 WHERE pobject_id = %s
440 array(
'integer',
'integer'),
443 while(
$row = $this->db->fetchObject(
$res))
449 $prices[
$row->price_id][
'unlimited_duration'] =
$row->unlimited_duration;
462 return count($this->prices);
467 $lowest_price_id = 0;
470 foreach ($this->prices as $price_id => $data)
472 $current_price = $data[
'price'];
474 if($lowest_price == 0||
475 $lowest_price > (
float)$current_price)
477 $lowest_price = (float)$current_price;
478 $lowest_price_id = $price_id;
482 return is_array($this->prices[$lowest_price_id]) ? $this->prices[$lowest_price_id] : array();
488 $this->duration_from = $a_duration_from;
493 $this->duration_until = $a_duration_until;
498 $this->description = $a_description;