• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

payment/classes/class.ilPaymentObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 define ("PAY_METHOD_NOT_SPECIFIED", 0);
00034 define ("PAY_METHOD_BILL", 1);
00035 define ("PAY_METHOD_BMF", 2);
00036 define ("PAY_METHOD_PAYPAL", 3);
00037 
00038 class ilPaymentObject
00039 {
00040         var $db = null;
00041         var $user_obj = null;
00042         var $pobject_id = null;
00043 
00044         var $ref_id = null;
00045         var $status = null;
00046         var $pay_method = null;
00047         var $vendor_id = null;
00048 
00049         function ilPaymentObject(&$user_obj,$a_pobject_id = null)
00050         {
00051                 global $ilDB;
00052 
00053                 $this->db =& $ilDB;
00054                 $this->user_obj =& $user_obj;
00055 
00056                 $this->STATUS_NOT_BUYABLE = 0;
00057                 $this->STATUS_BUYABLE = 1;
00058                 $this->STATUS_EXPIRES = 2;
00059 
00060                 $this->PAY_METHOD_NOT_SPECIFIED = PAY_METHOD_NOT_SPECIFIED;
00061                 $this->PAY_METHOD_BILL = PAY_METHOD_BILL;
00062                 $this->PAY_METHOD_BMF = PAY_METHOD_BMF;
00063                 $this->PAY_METHOD_PAYPAL = PAY_METHOD_PAYPAL;
00064                 
00065                 $this->pobject_id = $a_pobject_id;
00066                 $this->__read();
00067         }
00068 
00069         // SETTER GETTER
00070         function getPobjectId()
00071         {
00072                 return $this->pobject_id;
00073         }
00074 
00075         function setRefId($a_ref_id)
00076         {
00077                 $this->ref_id = $a_ref_id;
00078         }
00079         function getRefId()
00080         {
00081                 return $this->ref_id;
00082         }
00083         function setStatus($a_status)
00084         {
00085                 $this->status = $a_status;
00086         }
00087         function getStatus()
00088         {
00089                 return $this->status;
00090         }
00091         function setPayMethod($a_method)
00092         {
00093                 $this->pay_method = $a_method;
00094         }
00095         function getPayMethod()
00096         {
00097                 return $this->pay_method;
00098         }
00099         function setVendorId($a_vendor_id)
00100         {
00101                 $this->vendor_id= $a_vendor_id;
00102         }
00103         function getVendorId()
00104         {
00105                 return $this->vendor_id;
00106         }
00107 
00108         
00109 
00110         // return new unique id
00111         function add()
00112         {
00113                 $query = "INSERT INTO payment_objects ".
00114                         "VALUES('','".
00115                         $this->getRefId()."','".
00116                         $this->getStatus()."',' ".
00117                         $this->getPayMethod()."',' ".
00118                         $this->getVendorId()."')";
00119 
00120                 $this->db->query($query);
00121 
00122                 $query = "SELECT LAST_INSERT_ID() as new_id";
00123 
00124                 $res = $this->db->query($query);
00125                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00126                 {
00127                         return $row->new_id;
00128                 }
00129                 return false;
00130         }
00131         function delete()
00132         {
00133                 if($this->getPobjectId())
00134                 {
00135                         $query = "DELETE FROM payment_objects ".
00136                                 "WHERE pobject_id = '".$this->getPobjectId()."'";
00137                         
00138                         $this->db->query($query);
00139                         
00140                         return true;
00141                 }
00142                 return false;
00143         }
00144 
00145         function update()
00146         {
00147                 $query = "UPDATE payment_objects ".
00148                         "SET ref_id = '".$this->getRefId()."', ".
00149                         "status = '".$this->getStatus()."', ".
00150                         "pay_method = '".$this->getPayMethod()."', ".
00151                         "vendor_id = '".$this->getVendorId()."' ".
00152                         "WHERE pobject_id = '".$this->getPobjectId()."'";
00153 
00154                 $this->db->query($query);
00155 
00156                 return true;
00157         }
00158         // STATIC
00159         function _lookupPobjectId($a_ref_id)
00160         {
00161                 global $ilDB;
00162 
00163                 $query = "SELECT * FROM payment_objects ".
00164                         "WHERE ref_id = '".$a_ref_id."'";
00165 
00166                 $res = $ilDB->query($query);
00167                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00168                 {
00169                         return $row->pobject_id;
00170                 }
00171                 return 0;
00172         }
00173 
00174         function _getCountObjectsByPayMethod($a_type)
00175         {
00176                 global $ilDB;
00177 
00178                 switch($a_type)
00179                 {
00180                         case 'pm_bill':
00181                                 $pm = 1;
00182                                 break;
00183 
00184                         case 'pm_bmf':
00185                                 $pm = 2;
00186                                 break;
00187 
00188                         case 'pm_paypal':
00189                                 $pm = 3;
00190                                 break;
00191 
00192                         default:
00193                                 $pm = -1;
00194                 }
00195                 
00196                 $query = 'SELECT count(pay_method) as pm FROM payment_objects '.
00197                         "WHERE pay_method = '".$pm."'";
00198 
00199                 $res = $ilDB->query($query);
00200 
00201                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00202                 {
00203                         return $row->pm;
00204                 }
00205                 return 0;
00206         }
00207                 
00208 
00209         // only called from payment settings object. Since there is no vendor check.
00210         function _getAllObjectsData()
00211         {
00212                 ;
00213         }
00214 
00215         function _getObjectsData($a_user_id)
00216         {
00217                 global $ilDB;
00218 
00219                 // get all vendors user is assigned to
00220                 include_once './payment/classes/class.ilPaymentTrustees.php';
00221                 include_once './payment/classes/class.ilPaymentVendors.php';
00222 
00223                 $vendors = ilPaymentTrustees::_getVendorsForObjects($a_user_id);
00224 
00225                 if(ilPaymentVendors::_isVendor($a_user_id))
00226                 {
00227                         $vendors[] = $a_user_id;
00228                 }
00229 
00230                 if(!count($vendors))
00231                 {
00232                         return array();
00233                 }
00234                 $in = " IN ('";
00235                 $in .= implode("','",$vendors);
00236                 $in .= "')";
00237 
00238                 $query = "SELECT * FROM payment_objects ".
00239                         "WHERE vendor_id ".$in;
00240 
00241                 $res = $ilDB->query($query);
00242                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00243                 {
00244                         $objects[$row->pobject_id]['pobject_id'] = $row->pobject_id;
00245                         $objects[$row->pobject_id]['ref_id'] = $row->ref_id;
00246                         $objects[$row->pobject_id]['status'] = $row->status;
00247                         $objects[$row->pobject_id]['pay_method'] = $row->pay_method;
00248                         $objects[$row->pobject_id]['vendor_id'] = $row->vendor_id;
00249                 }
00250                 return $objects ? $objects : array();
00251         }
00252 
00253         function _getObjectData($a_id)
00254         {
00255                 global $ilDB;
00256 
00257                 $query = "SELECT * FROM payment_objects ".
00258                         "WHERE pobject_id = '".$a_id."'";
00259 
00260                 $res = $ilDB->query($query);
00261 
00262                 if (is_object($res))
00263                 {
00264                         return $res->fetchRow(DB_FETCHMODE_ASSOC);
00265                 }
00266 
00267                 return false;
00268         }
00269 
00270         function _isPurchasable($a_ref_id, $a_vendor_id = 0)
00271         {
00272                 global $ilDB;
00273 
00274                 // In the moment it's not possible to sell one object twice
00275                 $query = "SELECT * FROM payment_objects ".
00276                         "WHERE ref_id = '".$a_ref_id."' ";
00277                 if ($a_vendor_id > 0)
00278                 {
00279                         $query .= "AND vendor_id = '".$a_vendor_id."' ";
00280                 }
00281                 #"AND status = '1' OR status = '3' ";
00282                 
00283                 $res = $ilDB->query($query);
00284 
00285                 return $res->numRows() ? false : true;
00286         }
00287 
00288         // base method to check access for a specific object
00289         function _hasAccess($a_ref_id)
00290         {
00291                 include_once './payment/classes/class.ilPaymentBookings.php';
00292 
00293                 global $rbacsystem,$ilDB;
00294 
00295                 // check write access
00296                 if($rbacsystem->checkAccess('write',$a_ref_id))
00297                 {
00298                         return true;
00299                 }
00300                 $query = "SELECT * FROM payment_objects ".
00301                         "WHERE ref_id = '".$a_ref_id."' ".
00302                         "AND (status = '1' OR status = '2')";
00303 
00304                 $res = $ilDB->query($query);
00305                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00306                 {
00307                         if(!ilPaymentBookings::_hasAccess($row->pobject_id))
00308                         {
00309                                 return false;
00310                         }
00311                 }
00312                 return true;
00313         }
00314         // base method to check access for a specific object
00315         function _getActivation($a_ref_id)
00316         {
00317                 include_once './payment/classes/class.ilPaymentBookings.php';
00318 
00319                 global $rbacsystem,$ilDB;
00320 
00321                 $query = "SELECT * FROM payment_objects ".
00322                         "WHERE ref_id = '".$a_ref_id."' ".
00323                         "AND (status = '1' OR status = '2')";
00324 
00325                 $res = $ilDB->query($query);
00326                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00327                 return ilPaymentBookings::_getActivation($row->pobject_id);
00328         }
00329         function _isBuyable($a_ref_id)
00330         {
00331                 global $ilDB;
00332 
00333                 $query = "SELECT * FROM payment_objects ".
00334                         "WHERE ref_id = '".$a_ref_id."' ".
00335                         "AND (status = 1 or status = 2)";
00336 
00337                 $res = $ilDB->query($query);
00338                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00339                 {
00340                         return true;
00341                 }
00342                 return false;
00343         }
00344         function _isInCart($a_ref_id)
00345         {
00346                 global $ilDB, $ilUser;
00347 
00348                 $query = "SELECT psc_id FROM payment_objects AS po, payment_shopping_cart AS psc ".
00349                         "WHERE ref_id = '".$a_ref_id."' ".
00350                         "AND customer_id = '".$ilUser->getId()."' ".
00351                         "AND po.pobject_id = psc.pobject_id";
00352 
00353                 $res = $ilDB->query($query);
00354                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00355                 {
00356                         return true;
00357                 }
00358                 return false;
00359         }
00360                 
00361         // PRIVATE
00362         function __read()
00363         {
00364                 if($this->getPobjectId())
00365                 {
00366                         $query = "SELECT * FROM payment_objects ".
00367                                 "WHERE pobject_id = '".$this->getPobjectId()."'";
00368 
00369                         $res = $this->db->query($query);
00370                         while($row =& $res->fetchRow(DB_FETCHMODE_OBJECT))
00371                         {
00372                                 $this->setRefId($row->ref_id);
00373                                 $this->setStatus($row->status);
00374                                 $this->setPayMethod($row->pay_method);
00375                                 $this->setVendorId($row->vendor_id);
00376                                 
00377                                 return true;
00378                         }
00379                 }
00380                 return false;
00381         }
00382                                 
00383 
00384 } // END class.ilPaymentObject
00385 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1