44 $this->pobject_id = $a_pobject_id;
51 $this->price_type = $a_price_type;
70 return $this->prices ? $this->prices : array();
74 return $this->prices[$a_price_id] ? $this->prices[$a_price_id] : array();
83 $res = $ilDB->queryf(
'
84 SELECT * FROM payment_prices
86 array(
'integer'), array($a_price_id));
88 while(
$row = $ilDB->fetchObject(
$res))
92 $price[
'duration_until'] =
$row->duration_until;
94 $price[
'unlimited_duration'] =
$row->unlimited_duration;
96 $price[
'price'] = number_format(
$row->price, 2,
'.',
'');
108 $res = $ilDB->queryf(
'
109 SELECT count(price_id) FROM payment_prices
110 WHERE pobject_id = %s',
112 array($a_pobject_id));
131 $system_lng = $lng->getDefaultLanguage();
134 $use_comma_seperator = array(
'ar',
'bg',
'cs',
'de',
'da',
'es',
'et',
'it',
135 'fr',
'nl',
'el',
'sr',
'uk',
'ru',
'ro',
'tr',
'pl',
'lt',
'pt',
'sq',
'hu');
139 if(in_array($system_lng, $use_comma_seperator))
141 $gui_price = number_format((
float)$a_price, 2,
',',
'');
144 $gui_price = number_format((
float)$a_price, 2,
'.',
'');
151 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
154 $currency_unit = $genSet->get(
'currency_unit');
158 return $gui_price .
' ' . $currency_unit;
174 include_once
'./Services/Payment/classes/class.ilPaymentCurrency.php';
175 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
178 $currency_unit = $genSet->get(
"currency_unit");
181 $pr_str .= number_format($a_price , 2,
",",
".");
186 return $pr_str .
" " . $currency_unit;
192 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
196 if (is_array($a_price_ids))
198 for ($i = 0; $i < count($a_price_ids); $i++)
202 $price = (float) $price_data[
"price"];
203 $amount[$a_price_ids[$i][
"pay_method"]] += (float)
$price;
212 $this->price = preg_replace(
'/,/',
'.',$a_price);
213 $this->price = (float)$a_price;
218 $this->currency = $a_currency_id;
222 if($this->unlimited_duration ==
'1' && ($a_duration ==
'' || null))
225 $this->duration = (int)$a_duration;
230 if($a_unlimited_duration)
231 $this->unlimited_duration = (int)$a_unlimited_duration;
233 $this->unlimited_duration = 0;
239 $this->extension = (int)$a_extension;
250 $next_id = $this->db->nextId(
'payment_prices');
252 $res = $this->db->insert(
'payment_prices', array(
253 'price_id' => array(
'integer', $next_id),
254 'pobject_id' => array(
'integer', $this->
getPobjectId()),
258 'price' => array(
'float', $this->
__getPrice()),
271 $this->db->update(
'payment_prices',
272 array(
'pobject_id' => array(
'integer', $this->
getPobjectId()),
276 'price' => array(
'float', $this->
__getPrice()),
283 array(
'price_id'=> array(
'integer', $a_price_id)));
289 public function delete($a_price_id)
291 $statement = $this->db->manipulateF(
'
292 DELETE FROM payment_prices
293 WHERE price_id = %s',
294 array(
'integer'), array($a_price_id));
302 $statement = $this->db->manipulateF(
'
303 DELETE FROM payment_prices
304 WHERE pobject_id = %s',
323 include_once
'Services/Payment/exceptions/class.ilShopException.php';
327 case self::TYPE_DURATION_MONTH:
328 if(!preg_match(
'/^[1-9][0-9]{0,1}$/', $this->
__getDuration()))
332 case self::TYPE_DURATION_DATE:
333 if(!preg_match(
'/^[0-9]{4,4}-[0-9]{1,2}-[0-9]{1,2}$/', $this->
__getDurationFrom()))
334 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from'));
337 if(!checkdate($from_date[1], $from_date[2], $from_date[0]))
338 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from'));
341 throw new ilShopException($lng->txt(
'payment_price_invalid_date_until'));
344 if(!checkdate($till_date[1], $till_date[2], $till_date[0]))
345 throw new ilShopException($lng->txt(
'payment_price_invalid_date_until'));
347 $from = mktime(12, 12, 12, $from_date[1], $from_date[2], $from_date[0]);
348 $till = mktime(12, 12, 12, $till_date[1], $till_date[2], $till_date[0]);
351 throw new ilShopException($lng->txt(
'payment_price_invalid_date_from_gt_until'));
354 case self::TYPE_UNLIMITED_DURATION:
359 throw new ilShopException($lng->txt(
'payment_no_price_type_selected_sdf'));
375 $res = $ilDB->queryf(
'
376 SELECT * FROM payment_prices
378 AND pobject_id = %s',
379 array(
'integer',
'integer'),
380 array($a_price_id, $a_pobject_id));
382 return $res->numRows() ?
true :
false;
394 if($this->currency == null)
407 private function __read($with_extension_prices =
false)
409 $this->prices = array();
411 if(!$with_extension_prices)
413 $res = $this->db->queryf(
'
414 SELECT * FROM payment_prices
415 WHERE pobject_id = %s
418 array(
'integer',
'integer'),
424 $res = $this->db->queryf(
'
425 SELECT * FROM payment_prices
426 WHERE pobject_id = %s
432 while(
$row = $this->db->fetchObject(
$res))
434 $this->prices[
$row->price_id][
'pobject_id'] =
$row->pobject_id;
435 $this->prices[
$row->price_id][
'price_id'] =
$row->price_id;
436 $this->prices[
$row->price_id][
'currency'] =
$row->currency;
437 $this->prices[
$row->price_id][
'duration'] =
$row->duration;
438 $this->prices[
$row->price_id][
'unlimited_duration'] =
$row->unlimited_duration;
439 $this->prices[
$row->price_id][
'price'] =
$row->price;
440 $this->prices[
$row->price_id][
'extension'] =
$row->extension;
441 $this->prices[
$row->price_id][
'duration_from'] =
$row->duration_from;
442 $this->prices[
$row->price_id][
'duration_until'] =
$row->duration_until;
443 $this->prices[
$row->price_id][
'description'] =
$row->description;
444 $this->prices[
$row->price_id][
'price_type'] =
$row->price_type;
452 $res = $this->db->queryf(
'
453 SELECT * FROM payment_prices
454 WHERE pobject_id = %s
457 array(
'integer',
'integer'),
460 while(
$row = $this->db->fetchObject(
$res))
466 $prices[
$row->price_id][
'unlimited_duration'] =
$row->unlimited_duration;
479 return count($this->prices);
484 $lowest_price_id = 0;
487 foreach ($this->prices as $price_id => $data)
489 $current_price = $data[
'price'];
491 if($lowest_price == 0||
492 $lowest_price > (
float)$current_price)
494 $lowest_price = (float)$current_price;
495 $lowest_price_id = $price_id;
499 return is_array($this->prices[$lowest_price_id]) ? $this->prices[$lowest_price_id] : array();
505 $this->duration_from = $a_duration_from;
510 $this->duration_until = $a_duration_until;
515 $this->description = $a_description;