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';
462 if(ilPaymentVendors::_isVendor($a_user_id))
464 $vendors[] = $a_user_id;
467 if(is_array($vendors) && count($vendors))
469 $query .=
' OR '.$ilDB->in(
'vendor_id', $vendors,
false,
'integer');
474 $res = $ilDB->queryf(
$query, $data_types, $data);
475 $rows = $ilDB->numRows(
$res);
477 return $rows ?
true :
false;
482 public static function _hasAccess($a_ref_id, $a_transaction = 0, $a_subtype =
'')
484 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
485 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
486 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
488 global $rbacsystem,$ilDB,
$ilUser;
491 if($rbacsystem->checkAccess(
'write', $a_ref_id))
498 if(!IS_PAYMENT_ENABLED)
506 SELECT * FROM payment_objects
507 WHERE ref_id = %s AND (status = %s or status = %s)
509 array(
'integer',
'integer',
'integer',
'text'),
510 array($a_ref_id,
'1',
'2',$a_subtype));
515 SELECT * FROM payment_objects
517 AND (status = %s OR status = %s)
518 OR (vendor_id = %s)',
519 array(
'integer',
'integer',
'integer',
'integer'),
520 array($a_ref_id,
'1',
'2',$ilUser->getId()));
524 if(
$row->vendor_id == $ilUser->getId() || in_array(
$row->vendor_id, $vendors_of_trustee))
541 public static function _isBuyable($a_ref_id, $a_subtype =
'')
546 if(!IS_PAYMENT_ENABLED)
554 SELECT * FROM payment_objects
556 AND (status = %s or status = %s)
558 array(
'integer',
'integer',
'integer',
'text'),
559 array($a_ref_id,
'1',
'2',$a_subtype));
564 SELECT * FROM payment_objects
565 WHERE ref_id = %s AND (status = %s or status = %s)',
566 array(
'integer',
'integer',
'integer'),
567 array($a_ref_id,
'1',
'2'));
582 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE ref_id = %s',
583 array(
'integer'), array($a_ref_id));
585 $rows = $ilDB->numRows(
$res);
587 return $rows ?
false :
true;
605 if( (self::_isBuyable($a_ref_id) && !self::_hasAccess($a_ref_id))
606 || (self::_isBuyable($a_ref_id) && self::_hasAccess($a_ref_id)
607 && self::_hasExtensions($a_ref_id) && isset($a_purchasetype)))
618 if(ANONYMOUS_USER_ID == $ilUser->getId())
621 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
624 AND po.pobject_id = psc.pobject_id',
625 array(
'integer',
'text'),
626 array($a_ref_id, session_id()));
631 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
634 AND po.pobject_id = psc.pobject_id',
635 array(
'integer',
'integer'),
636 array($a_ref_id, $ilUser->getId()));
653 $res = $ilDB->queryf(
'
654 SELECT * FROM payment_prices pp, payment_objects po
656 AND pp.pobject_id = po.pobject_id
657 AND pp.extension = %s',
658 array(
'integer',
'integer'), array($a_ref_id, 1));
671 $result = $this->db->queryf(
'SELECT * FROM payment_objects WHERE pobject_id = %s',
696 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE
697 ref_id = %s', array(
'integer'), array($a_ref_id));
699 while(
$row = $ilDB->fetchAssoc(
$res))
701 $subtypes[] =
$row[
'subtype'];
711 $res = $ilDB->queryF(
'SELECT ref_id FROM payment_objects WHERE status = %s',
712 array(
'integer'), array(1));
715 while(
$row = $ilDB->fetchAssoc(
$res))
717 $obj[] =
$row[
'ref_id'];
726 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
727 WHERE is_special = %s AND status = %s
728 ORDER BY pt_topic_fk',
729 array(
'integer',
'integer'), array(1,1));
732 while(
$row = $ilDB->fetchAssoc(
$res))
743 $filter = array(
"lm",
"sahs",
"htlm",
'file',
'exc',
'tst',
'icrs',
'crs',
'crsr',
'rcrs',
'glo');
744 $objects = $tree->getChildsByTypeFilter($a_ref_id, $filter);
748 foreach($objects as $object)
750 if(self::_isBuyable($object[
'ref_id']))
752 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
753 WHERE ref_id = %s AND status = %s
754 ORDER BY pt_topic_fk',
755 array(
'integer',
'integer'), array($object[
'ref_id'],1));
757 while(
$row = $ilDB->fetchAssoc(
$res))
759 $obj_res[$counter] =
$row;
760 #$obj_res[$counter]['ref_id'] = $object['ref_id'];
761 $obj_res[$counter][
'obj_id'] = $object[
'obj_id'];
762 $obj_res[$counter][
'type'] = $object[
'type'];
763 $obj_res[$counter][
'title'] = $object[
'title'];
764 $obj_res[$counter][
'child'] = $object[
'child'];
765 $obj_res[$counter][
'description'] = $object[
'description'];