34 $this->STATUS_NOT_BUYABLE = 0;
35 $this->STATUS_BUYABLE = 1;
36 $this->STATUS_EXPIRES = 2;
38 $this->PAY_METHOD_NOT_SPECIFIED = 0;
40 $this->pobject_id = $a_pobject_id;
42 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
44 $tmp = $pmObj->readAll();
48 $tmp = strtoupper($pm[
'pm_title']);
49 $this->PAY_METHOD_.$tmp = $pm[
'pm_id'];
61 $this->topic_id = $a_topic_id;
69 $this->ref_id = $a_ref_id;
77 $this->status = $a_status;
85 $this->pay_method = $a_method;
93 $this->vendor_id = $a_vendor_id;
105 $this->vat_id = $a_vat_id;
110 $this->subtype = $a_subtype;
119 $this->is_special = $a_special;
126 function getVat($a_amount = 0, $type =
'CALCULATION')
132 $val = (float)($a_amount - (round(($a_amount / (1 + ($oVAT->getRate() / 100))) * 100) / 100));
133 return number_format((
float)$val,
'2',
'.',
'');
135 $val = (float)($a_amount - (round(($a_amount / (1 + ($oVAT->getRate() / 100))) * 100) / 100));
143 $next_id = $this->db->nextId(
'payment_objects');
145 $this->db->insert(
'payment_objects',array(
146 'pobject_id' => array(
'integer', $next_id),
147 'ref_id' => array(
'integer', $this->
getRefId()),
148 'status' => array(
'integer', $this->
getStatus()),
149 'pay_method' => array(
'integer', $this->
getPayMethod()),
150 'vendor_id' => array(
'integer', $this->
getVendorId()),
151 'pt_topic_fk' => array(
'integer', $this->
getTopicId()),
152 'vat_id' => array(
'integer', $this->
getVatId()),
153 'subtype' => array(
'text', $this->
getSubtype()),
154 'is_special' => array(
'integer', $this->
getSpecial())
159 public function delete()
163 include_once
'Services/Payment/classes/class.ilFileDataShop.php';
165 $oFileData->deassignFileFromPaymentObject();
167 $statement = $this->db->manipulateF(
'DELETE FROM payment_objects WHERE pobject_id = %s',
181 $this->db->update(
'payment_objects',array(
182 'ref_id' => array(
'integer', $this->
getRefId()),
183 'status' => array(
'integer', $this->
getStatus()),
184 'pay_method' => array(
'integer', $this->
getPayMethod()),
185 'vendor_id' => array(
'integer', $this->
getVendorId()),
186 'pt_topic_fk' => array(
'integer', $this->
getTopicId()),
187 'vat_id' => array(
'integer', $this->
getVatId()),
188 'subtype' => array(
'text', $this->
getSubtype()),
189 'is_special' => array(
'integer', $this->
getSpecial())
191 array(
'pobject_id' => array(
'integer', $this->
getPobjectId())));
203 $res = $ilDB->queryf(
'
204 SELECT * FROM payment_objects
209 while(
$row = $ilDB->fetchAssoc(
$res))
211 return $row[
'pobject_id'];
220 static $cache = array();
221 if(isset($cache[$a_ref_id]))
223 return $cache[$a_ref_id];
226 $result = $ilDB->queryf(
'SELECT pt_topic_fk FROM payment_objects WHERE ref_id = %s',
227 array(
'integer'),array($a_ref_id));
231 $cache[$a_ref_id] =
$row->pt_topic_fk;
232 return (
int)$cache[$a_ref_id];
243 $result = $ilDB->queryf(
'SELECT COUNT(pay_method) pm FROM payment_objects WHERE pay_method = %s',
244 array(
'integer'), array($a_id));
248 return (
int)
$row->pm;
259 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
260 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
264 if(ilPaymentVendors::_isVendor($a_user_id))
266 $vendors[] = $a_user_id;
274 $data_types = array();
275 $data_values = array();
276 $cnt_vendors = count($vendors);
278 $query =
'SELECT * FROM payment_objects WHERE vendor_id IN';
280 if (is_array($vendors) &&
285 foreach($vendors as $vendor)
287 array_push($data_values, $vendor);
288 array_push($data_types,
'integer');
290 if($counter > 0)
$in .=
',';
298 $res= $ilDB->queryf(
$query, $data_types, $data_values);
301 while(
$row = $ilDB->fetchObject(
$res))
303 $objects[
$row->pobject_id][
'pobject_id'] =
$row->pobject_id;
304 $objects[
$row->pobject_id][
'ref_id'] =
$row->ref_id;
305 $objects[
$row->pobject_id][
'status'] =
$row->status;
306 $objects[
$row->pobject_id][
'pay_method'] =
$row->pay_method;
307 $objects[
$row->pobject_id][
'vendor_id'] =
$row->vendor_id;
308 $objects[
$row->pobject_id][
'topic_id'] =
$row->pt_topic_fk;
309 $objects[
$row->pobject_id][
'vat_id'] =
$row->vat_id;
310 $objects[
$row->pobject_id][
'subtype'] =
$row->subtype;
311 $objects[
$row->pobject_id][
'is_special'] =
$row->is_special;
313 return $objects ? $objects : array();
320 $data_types = array();
321 $data_values = array();
323 $query =
'SELECT * FROM payment_objects ';
325 if (
$_SESSION[
'pay_objects'][
'title_value'] !=
'')
327 $query .=
', object_reference obr, object_data od ';
330 if (
$_SESSION[
'pay_objects'][
'vendor'] !=
'')
332 $query .=
', usr_data ud ';
335 $query .=
' WHERE 1 = 1 ';
337 if (
$_SESSION[
'pay_objects'][
'title_value'])
339 $query .=
' AND obr.ref_id = payment_objects.ref_id AND od.obj_id = obr.obj_id ';
343 $title_search = explode(
' ', trim(
$_SESSION[
'pay_objects'][
'title_value']));
344 for ($i = 0; $i < count($title_search); $i++)
346 $title_search[$i] = trim($title_search[$i]);
348 if ($title_search[$i] !=
'')
351 $search_string .=
' od.title LIKE %s ';
352 array_push($data_types,
'text');
353 array_push($data_values,
'%'.$title_search[$i].
'%');
355 switch (
$_SESSION[
'pay_objects'][
'title_type'])
358 if ($i < count($title_search) - 1)
360 $search_string .=
' OR ';
364 if ($i < count($title_search) - 1)
366 $search_string .=
' AND ';
373 if ($search_string !=
'')
375 $query .=
' AND (' . $search_string .
') ';
379 if (
$_SESSION[
'pay_objects'][
'vendor'] !=
'')
381 $query .=
' AND ud.usr_id = payment_objects.vendor_id AND login = %s';
382 array_push($data_types,
'text');
383 array_push($data_values,
$_SESSION[
'pay_objects'][
'vendor']);
386 if(
$_SESSION[
'pay_objects'][
'pay_method'] > 0)
388 $query .=
' AND pay_method = %s';
389 array_push($data_types,
'integer');
390 array_push($data_values,
$_SESSION[
'pay_objects'][
'pay_method']);
393 $res = $ilDB->queryf(
$query, $data_types, $data_values);
395 while(
$row = $ilDB->fetchObject(
$res))
397 $objects[
$row->pobject_id][
'pobject_id'] =
$row->pobject_id;
398 $objects[
$row->pobject_id][
'ref_id'] =
$row->ref_id;
399 $objects[
$row->pobject_id][
'status'] =
$row->status;
400 $objects[
$row->pobject_id][
'pay_method'] =
$row->pay_method;
401 $objects[
$row->pobject_id][
'vendor_id'] =
$row->vendor_id;
402 $objects[
$row->pobject_id][
'topic_id'] =
$row->pt_topic_fk;
403 $objects[
$row->pobject_id][
'vat_id'] =
$row->vat_id;
404 $objects[
$row->pobject_id][
'subtype'] =
$row->subtype;
405 $objects[
$row->pobject_id][
'is_special'] =
$row->is_special;
407 return $objects ? $objects : array();
414 $res = $ilDB->queryf(
'
415 SELECT * FROM payment_objects
416 WHERE pobject_id = %s',
417 array(
'integer'), array($a_id));
421 return $ilDB->fetchAssoc(
$res);
428 public static function _isPurchasable($a_ref_id, $a_vendor_id = 0, $a_check_trustee =
false, $a_check_status =
false)
435 $data_types = array();
438 $query =
'SELECT * FROM payment_objects WHERE ref_id = %s ';
439 $data_types[] =
'integer';
445 $query .=
'AND status > %s ';
446 $data_types[] =
'integer';
450 if ($a_vendor_id > 0)
452 $query .=
'AND vendor_id = %s';
453 $data_types[] =
'integer';
454 $data[] = $a_vendor_id;
458 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
459 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
464 if(ilPaymentVendors::_isVendor($a_user_id))
466 $vendors[] = $a_user_id;
469 if(is_array($vendors) && count($vendors))
471 $query .=
' OR '.$ilDB->in(
'vendor_id', $vendors,
false,
'integer');
476 $res = $ilDB->queryf(
$query, $data_types, $data);
477 $rows = $ilDB->numRows(
$res);
479 return $rows ?
true :
false;
484 public static function _hasAccess($a_ref_id, $a_transaction = 0, $a_subtype =
'')
486 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
487 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
488 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
493 if($rbacsystem->checkAccess(
'write', $a_ref_id))
500 if(!IS_PAYMENT_ENABLED)
508 SELECT * FROM payment_objects
509 WHERE ref_id = %s AND (status = %s or status = %s)
511 array(
'integer',
'integer',
'integer',
'text'),
512 array($a_ref_id,
'1',
'2',$a_subtype));
517 SELECT * FROM payment_objects
519 AND (status = %s OR status = %s)
520 OR (vendor_id = %s)',
521 array(
'integer',
'integer',
'integer',
'integer'),
522 array($a_ref_id,
'1',
'2',$ilUser->getId()));
526 if(
$row->vendor_id == $ilUser->getId() || in_array(
$row->vendor_id, $vendors_of_trustee))
543 public static function _isBuyable($a_ref_id, $a_subtype =
'')
548 if(!IS_PAYMENT_ENABLED)
556 SELECT * FROM payment_objects
558 AND (status = %s or status = %s)
560 array(
'integer',
'integer',
'integer',
'text'),
561 array($a_ref_id,
'1',
'2',$a_subtype));
566 SELECT * FROM payment_objects
567 WHERE ref_id = %s AND (status = %s or status = %s)',
568 array(
'integer',
'integer',
'integer'),
569 array($a_ref_id,
'1',
'2'));
584 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE ref_id = %s',
585 array(
'integer'), array($a_ref_id));
587 $rows = $ilDB->numRows(
$res);
589 return $rows ?
false :
true;
607 if( (self::_isBuyable($a_ref_id) && !self::_hasAccess($a_ref_id))
608 || (self::_isBuyable($a_ref_id) && self::_hasAccess($a_ref_id)
609 && self::_hasExtensions($a_ref_id) && isset($a_purchasetype)))
620 if(ANONYMOUS_USER_ID == $ilUser->getId())
623 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
626 AND po.pobject_id = psc.pobject_id',
627 array(
'integer',
'text'),
628 array($a_ref_id, session_id()));
633 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
636 AND po.pobject_id = psc.pobject_id',
637 array(
'integer',
'integer'),
638 array($a_ref_id, $ilUser->getId()));
655 $res = $ilDB->queryf(
'
656 SELECT * FROM payment_prices pp, payment_objects po
658 AND pp.pobject_id = po.pobject_id
659 AND pp.extension = %s',
660 array(
'integer',
'integer'), array($a_ref_id, 1));
673 $result = $this->db->queryf(
'SELECT * FROM payment_objects WHERE pobject_id = %s',
698 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE
699 ref_id = %s', array(
'integer'), array($a_ref_id));
701 while(
$row = $ilDB->fetchAssoc(
$res))
703 $subtypes[] =
$row[
'subtype'];
713 $res = $ilDB->queryF(
'SELECT ref_id FROM payment_objects WHERE status = %s',
714 array(
'integer'), array(1));
717 while(
$row = $ilDB->fetchAssoc(
$res))
719 $obj[] =
$row[
'ref_id'];
728 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
729 WHERE is_special = %s AND status = %s
730 ORDER BY pt_topic_fk',
731 array(
'integer',
'integer'), array(1,1));
734 while(
$row = $ilDB->fetchAssoc(
$res))
751 $res = $ilDB->queryF(
'
752 SELECT * FROM payment_objects
754 ORDER BY pt_topic_fk', array(
'integer'), array(1));
758 $res = $ilDB->queryF(
'
759 SELECT * FROM payment_objects
760 WHERE pt_topic_fk = %s AND status = %s',
761 array(
'integer',
'integer'), array((
int)
$topic_id, 1));
764 while(
$row = $ilDB->fetchAssoc(
$res))
775 $filter = array(
"lm",
"sahs",
"htlm",
'file',
'exc',
'tst',
'icrs',
'crs',
'crsr',
'rcrs',
'glo');
776 $objects = $tree->getChildsByTypeFilter($a_ref_id, $filter);
780 foreach($objects as $object)
782 if(self::_isBuyable($object[
'ref_id']))
784 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
785 WHERE ref_id = %s AND status = %s
786 ORDER BY pt_topic_fk',
787 array(
'integer',
'integer'), array($object[
'ref_id'],1));
789 while(
$row = $ilDB->fetchAssoc(
$res))
791 $obj_res[$counter] =
$row;
792 #$obj_res[$counter]['ref_id'] = $object['ref_id'];
793 $obj_res[$counter][
'obj_id'] = $object[
'obj_id'];
794 $obj_res[$counter][
'type'] = $object[
'type'];
795 $obj_res[$counter][
'title'] = $object[
'title'];
796 $obj_res[$counter][
'child'] = $object[
'child'];
797 $obj_res[$counter][
'description'] = $object[
'description'];