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'];
64 $this->topic_id = $a_topic_id;
72 $this->ref_id = $a_ref_id;
80 $this->status = $a_status;
88 $this->pay_method = $a_method;
96 $this->vendor_id = $a_vendor_id;
108 $this->vat_id = $a_vat_id;
113 $this->subtype = $a_subtype;
122 $this->is_special = $a_special;
129 function getVat($a_amount = 0, $type =
'CALCULATION')
135 $val = (float)($a_amount - (round(($a_amount / (1 + ($oVAT->getRate() / 100))) * 100) / 100));
136 return number_format((
float)$val,
'2',
'.',
'');
140 $val = (float)($a_amount - (round(($a_amount / (1 + ($oVAT->getRate() / 100))) * 100) / 100));
148 $next_id = $this->db->nextId(
'payment_objects');
150 $this->db->insert(
'payment_objects',array(
151 'pobject_id' => array(
'integer', $next_id),
152 'ref_id' => array(
'integer', $this->
getRefId()),
153 'status' => array(
'integer', $this->
getStatus()),
154 'pay_method' => array(
'integer', $this->
getPayMethod()),
155 'vendor_id' => array(
'integer', $this->
getVendorId()),
156 'pt_topic_fk' => array(
'integer', $this->
getTopicId()),
157 'vat_id' => array(
'integer', $this->
getVatId()),
158 'subtype' => array(
'text', $this->
getSubtype()),
159 'is_special' => array(
'integer', $this->
getSpecial())
164 public function delete()
168 include_once
'Services/Payment/classes/class.ilFileDataShop.php';
170 $oFileData->deassignFileFromPaymentObject();
172 $statement = $this->db->manipulateF(
'DELETE FROM payment_objects WHERE pobject_id = %s',
186 $this->db->update(
'payment_objects',array(
187 'ref_id' => array(
'integer', $this->
getRefId()),
188 'status' => array(
'integer', $this->
getStatus()),
189 'pay_method' => array(
'integer', $this->
getPayMethod()),
190 'vendor_id' => array(
'integer', $this->
getVendorId()),
191 'pt_topic_fk' => array(
'integer', $this->
getTopicId()),
192 'vat_id' => array(
'integer', $this->
getVatId()),
193 'subtype' => array(
'text', $this->
getSubtype()),
194 'is_special' => array(
'integer', $this->
getSpecial())
196 array(
'pobject_id' => array(
'integer', $this->
getPobjectId())));
208 $res = $ilDB->queryf(
'
209 SELECT * FROM payment_objects
214 while(
$row = $ilDB->fetchAssoc(
$res))
216 return $row[
'pobject_id'];
225 static $cache = array();
226 if(isset($cache[$a_ref_id]))
228 return $cache[$a_ref_id];
231 $result = $ilDB->queryf(
'SELECT pt_topic_fk FROM payment_objects WHERE ref_id = %s',
232 array(
'integer'),array($a_ref_id));
236 $cache[$a_ref_id] =
$row->pt_topic_fk;
237 return (
int)$cache[$a_ref_id];
248 $result = $ilDB->queryf(
'SELECT COUNT(pay_method) pm FROM payment_objects WHERE pay_method = %s',
249 array(
'integer'), array($a_id));
253 return (
int)
$row->pm;
264 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
265 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
271 $vendors[] = $a_user_id;
279 $data_types = array();
280 $data_values = array();
281 $cnt_vendors = count($vendors);
283 $query =
'SELECT * FROM payment_objects WHERE vendor_id IN';
285 if (is_array($vendors) &&
292 array_push($data_values, $vendor);
293 array_push($data_types,
'integer');
295 if($counter > 0)
$in .=
',';
303 $res= $ilDB->queryf(
$query, $data_types, $data_values);
306 while(
$row = $ilDB->fetchObject(
$res))
308 $objects[
$row->pobject_id][
'pobject_id'] =
$row->pobject_id;
309 $objects[
$row->pobject_id][
'ref_id'] =
$row->ref_id;
310 $objects[
$row->pobject_id][
'status'] =
$row->status;
311 $objects[
$row->pobject_id][
'pay_method'] =
$row->pay_method;
312 $objects[
$row->pobject_id][
'vendor_id'] =
$row->vendor_id;
313 $objects[
$row->pobject_id][
'topic_id'] =
$row->pt_topic_fk;
314 $objects[
$row->pobject_id][
'vat_id'] =
$row->vat_id;
315 $objects[
$row->pobject_id][
'subtype'] =
$row->subtype;
316 $objects[
$row->pobject_id][
'is_special'] =
$row->is_special;
318 return $objects ? $objects : array();
325 $data_types = array();
326 $data_values = array();
328 $query =
'SELECT * FROM payment_objects ';
330 if (
$_SESSION[
'pay_objects'][
'title_value'] !=
'')
332 $query .=
', object_reference obr, object_data od ';
335 if (
$_SESSION[
'pay_objects'][
'vendor'] !=
'')
337 $query .=
', usr_data ud ';
340 $query .=
' WHERE 1 = 1 ';
342 if (
$_SESSION[
'pay_objects'][
'title_value'])
344 $query .=
' AND obr.ref_id = payment_objects.ref_id AND od.obj_id = obr.obj_id ';
348 $title_search = explode(
' ', trim(
$_SESSION[
'pay_objects'][
'title_value']));
349 for ($i = 0; $i < count($title_search); $i++)
351 $title_search[$i] = trim($title_search[$i]);
353 if ($title_search[$i] !=
'')
356 $search_string .=
' od.title LIKE %s ';
357 array_push($data_types,
'text');
358 array_push($data_values,
'%'.$title_search[$i].
'%');
360 switch (
$_SESSION[
'pay_objects'][
'title_type'])
363 if ($i < count($title_search) - 1)
365 $search_string .=
' OR ';
369 if ($i < count($title_search) - 1)
371 $search_string .=
' AND ';
378 if ($search_string !=
'')
380 $query .=
' AND (' . $search_string .
') ';
384 if (
$_SESSION[
'pay_objects'][
'vendor'] !=
'')
386 $query .=
' AND ud.usr_id = payment_objects.vendor_id AND login = %s';
387 array_push($data_types,
'text');
388 array_push($data_values,
$_SESSION[
'pay_objects'][
'vendor']);
391 if(
$_SESSION[
'pay_objects'][
'pay_method'] > 0)
393 $query .=
' AND pay_method = %s';
394 array_push($data_types,
'integer');
395 array_push($data_values,
$_SESSION[
'pay_objects'][
'pay_method']);
398 $res = $ilDB->queryf(
$query, $data_types, $data_values);
400 while(
$row = $ilDB->fetchObject(
$res))
402 $objects[
$row->pobject_id][
'pobject_id'] =
$row->pobject_id;
403 $objects[
$row->pobject_id][
'ref_id'] =
$row->ref_id;
404 $objects[
$row->pobject_id][
'status'] =
$row->status;
405 $objects[
$row->pobject_id][
'pay_method'] =
$row->pay_method;
406 $objects[
$row->pobject_id][
'vendor_id'] =
$row->vendor_id;
407 $objects[
$row->pobject_id][
'topic_id'] =
$row->pt_topic_fk;
408 $objects[
$row->pobject_id][
'vat_id'] =
$row->vat_id;
409 $objects[
$row->pobject_id][
'subtype'] =
$row->subtype;
410 $objects[
$row->pobject_id][
'is_special'] =
$row->is_special;
412 return $objects ? $objects : array();
419 $res = $ilDB->queryf(
'
420 SELECT * FROM payment_objects
421 WHERE pobject_id = %s',
422 array(
'integer'), array($a_id));
426 return $ilDB->fetchAssoc(
$res);
433 function _isPurchasable($a_ref_id, $a_vendor_id = 0, $a_check_trustee =
false, $a_check_status =
false)
440 $data_types = array();
443 $query =
'SELECT * FROM payment_objects WHERE ref_id = %s ';
444 $data_types[] =
'integer';
450 $query .=
'AND status > %s ';
451 $data_types[] =
'integer';
455 if ($a_vendor_id > 0)
457 $query .=
'AND vendor_id = %s';
458 $data_types[] =
'integer';
459 $data[] = $a_vendor_id;
463 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
464 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
469 $vendors[] = $a_user_id;
472 if(is_array($vendors) && count($vendors))
474 $query .=
' OR '.$ilDB->in(
'vendor_id', $vendors,
false,
'integer');
480 $rows = $ilDB->numRows(
$res);
482 return $rows ?
true :
false;
487 function _hasAccess($a_ref_id, $a_transaction = 0, $a_subtype =
'')
489 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
490 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
491 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
493 global $rbacsystem,
$ilDB, $ilUser;
496 if($rbacsystem->checkAccess(
'write', $a_ref_id))
503 if(!IS_PAYMENT_ENABLED)
511 SELECT * FROM payment_objects
512 WHERE ref_id = %s AND (status = %s or status = %s)
514 array(
'integer',
'integer',
'integer',
'text'),
515 array($a_ref_id,
'1',
'2',$a_subtype));
520 SELECT * FROM payment_objects
522 AND (status = %s OR status = %s)
523 OR (vendor_id = %s)',
524 array(
'integer',
'integer',
'integer',
'integer'),
525 array($a_ref_id,
'1',
'2',$ilUser->getId()));
529 if(
$row->vendor_id == $ilUser->getId() || in_array(
$row->vendor_id, $vendors_of_trustee))
548 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
550 global $rbacsystem,
$ilDB;
552 $res = $ilDB->queryf(
'
553 SELECT * FROM payment_objects
555 AND (status = %s OR status = %s)',
556 array(
'integer',
'integer',
'integer'),
557 array($a_ref_id,
'1',
'2'));
563 public static function _isBuyable($a_ref_id, $a_subtype =
'')
568 if(!IS_PAYMENT_ENABLED)
576 SELECT * FROM payment_objects
578 AND (status = %s or status = %s)
580 array(
'integer',
'integer',
'integer',
'text'),
581 array($a_ref_id,
'1',
'2',$a_subtype));
586 SELECT * FROM payment_objects
587 WHERE ref_id = %s AND (status = %s or status = %s)',
588 array(
'integer',
'integer',
'integer'),
589 array($a_ref_id,
'1',
'2'));
604 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE ref_id = %s',
605 array(
'integer'), array($a_ref_id));
607 $rows = $ilDB->numRows(
$res);
609 return $rows ?
false :
true;
623 global $ilUser,$ilObjDataCache;
629 if( (self::_isBuyable($a_ref_id) && !self::_hasAccess($a_ref_id))
630 || (self::_isBuyable($a_ref_id) && self::_hasAccess($a_ref_id)
631 && self::_hasExtensions($a_ref_id) && isset($a_purchasetype)))
640 global
$ilDB, $ilUser;
642 if(ANONYMOUS_USER_ID == $ilUser->getId())
645 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
648 AND po.pobject_id = psc.pobject_id',
649 array(
'integer',
'text'),
650 array($a_ref_id, session_id()));
655 SELECT psc_id FROM payment_objects po, payment_shopping_cart psc
658 AND po.pobject_id = psc.pobject_id',
659 array(
'integer',
'integer'),
660 array($a_ref_id, $ilUser->getId()));
677 $res = $ilDB->queryf(
'
678 SELECT * FROM payment_prices pp, payment_objects po
680 AND pp.pobject_id = po.pobject_id
681 AND pp.extension = %s',
682 array(
'integer',
'integer'), array($a_ref_id, 1));
695 $result = $this->db->queryf(
'SELECT * FROM payment_objects WHERE pobject_id = %s',
720 $res = $ilDB->queryF(
'SELECT * FROM payment_objects WHERE
721 ref_id = %s', array(
'integer'), array($a_ref_id));
723 while(
$row = $ilDB->fetchAssoc(
$res))
725 $subtypes[] =
$row[
'subtype'];
735 $res = $ilDB->queryF(
'SELECT ref_id FROM payment_objects WHERE status = %s',
736 array(
'integer'), array(1));
738 while(
$row = $ilDB->fetchAssoc(
$res))
740 $obj[] =
$row[
'ref_id'];
749 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
750 WHERE is_special = %s AND status = %s
751 ORDER BY pt_topic_fk',
752 array(
'integer',
'integer'), array(1,1));
754 while(
$row = $ilDB->fetchAssoc(
$res))
765 $filter = array(
"lm",
"sahs",
"htlm",
'file',
'exc',
'tst',
'icrs',
'crs',
'crsr',
'rcrs',
'glo');
766 $objects = $tree->getChildsByTypeFilter($a_ref_id, $filter);
770 foreach($objects as $object)
772 if(self::_isBuyable($object[
'ref_id']))
774 $res = $ilDB->queryF(
'SELECT * FROM payment_objects
775 WHERE ref_id = %s AND status = %s
776 ORDER BY pt_topic_fk',
777 array(
'integer',
'integer'), array($object[
'ref_id'],1));
779 while(
$row = $ilDB->fetchAssoc(
$res))
781 $obj_res[$counter] =
$row;
782 #$obj_res[$counter]['ref_id'] = $object['ref_id'];
783 $obj_res[$counter][
'obj_id'] = $object[
'obj_id'];
784 $obj_res[$counter][
'type'] = $object[
'type'];
785 $obj_res[$counter][
'title'] = $object[
'title'];
786 $obj_res[$counter][
'child'] = $object[
'child'];
787 $obj_res[$counter][
'description'] = $object[
'description'];