• Main Page
  • Related Pages
  • 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 class ilPaymentObject
00034 {
00035         var $db = null;
00036         var $user_obj = null;
00037         var $pobject_id = null;
00038 
00039         var $ref_id = null;
00040         var $status = null;
00041         var $pay_method = null;
00042         var $vendor_id = null;
00043 
00044         function ilPaymentObject(&$user_obj,$a_pobject_id = null)
00045         {
00046                 global $ilDB;
00047 
00048                 $this->db =& $ilDB;
00049                 $this->user_obj =& $user_obj;
00050 
00051                 $this->STATUS_NOT_BUYABLE = 0;
00052                 $this->STATUS_BUYABLE = 1;
00053                 $this->STATUS_EXPIRES = 2;
00054 
00055                 $this->PAY_METHOD_NOT_SPECIFIED = 0;
00056                 $this->PAY_METHOD_BILL = 1;
00057                 $this->PAY_METHOD_BMF = 2;
00058                 
00059 
00060                 $this->pobject_id = $a_pobject_id;
00061                 $this->__read();
00062         }
00063 
00064         // SETTER GETTER
00065         function getPobjectId()
00066         {
00067                 return $this->pobject_id;
00068         }
00069 
00070         function setRefId($a_ref_id)
00071         {
00072                 $this->ref_id = $a_ref_id;
00073         }
00074         function getRefId()
00075         {
00076                 return $this->ref_id;
00077         }
00078         function setStatus($a_status)
00079         {
00080                 $this->status = $a_status;
00081         }
00082         function getStatus()
00083         {
00084                 return $this->status;
00085         }
00086         function setPayMethod($a_method)
00087         {
00088                 $this->pay_method = $a_method;
00089         }
00090         function getPayMethod()
00091         {
00092                 return $this->pay_method;
00093         }
00094         function setVendorId($a_vendor_id)
00095         {
00096                 $this->vendor_id= $a_vendor_id;
00097         }
00098         function getVendorId()
00099         {
00100                 return $this->vendor_id;
00101         }
00102 
00103         
00104 
00105         // return new unique id
00106         function add()
00107         {
00108                 $query = "INSERT INTO payment_objects ".
00109                         "VALUES('','".
00110                         $this->getRefId()."','".
00111                         $this->getStatus()."',' ".
00112                         $this->getPayMethod()."',' ".
00113                         $this->getVendorId()."')";
00114 
00115                 $this->db->query($query);
00116 
00117                 $query = "SELECT LAST_INSERT_ID() as new_id";
00118 
00119                 $res = $this->db->query($query);
00120                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00121                 {
00122                         return $row->new_id;
00123                 }
00124                 return false;
00125         }
00126         function delete()
00127         {
00128                 if($this->getPobjectId())
00129                 {
00130                         $query = "DELETE FROM payment_objects ".
00131                                 "WHERE pobject_id = '".$this->getPobjectId()."'";
00132                         
00133                         $this->db->query($query);
00134                         
00135                         return true;
00136                 }
00137                 return false;
00138         }
00139 
00140         function update()
00141         {
00142                 $query = "UPDATE payment_objects ".
00143                         "SET ref_id = '".$this->getRefId()."', ".
00144                         "status = '".$this->getStatus()."', ".
00145                         "pay_method = '".$this->getPayMethod()."', ".
00146                         "vendor_id = '".$this->getVendorId()."' ".
00147                         "WHERE pobject_id = '".$this->getPobjectId()."'";
00148 
00149                 $this->db->query($query);
00150 
00151                 return true;
00152         }
00153         // STATIC
00154         function _lookupPobjectId($a_ref_id)
00155         {
00156                 global $ilDB;
00157 
00158                 $query = "SELECT * FROM payment_objects ".
00159                         "WHERE ref_id = '".$a_ref_id."'";
00160 
00161                 $res = $ilDB->query($query);
00162                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00163                 {
00164                         return $row->pobject_id;
00165                 }
00166                 return 0;
00167         }
00168 
00169         function _getCountObjectsByPayMethod($a_type)
00170         {
00171                 global $ilDB;
00172 
00173                 switch($a_type)
00174                 {
00175                         case 'pm_bill':
00176                                 $pm = 1;
00177                                 break;
00178 
00179                         case 'pm_bmf':
00180                                 $pm = 2;
00181                                 break;
00182 
00183                         default:
00184                                 $pm = -1;
00185                 }
00186                 
00187                 $query = 'SELECT count(pay_method) as pm FROM payment_objects '.
00188                         "WHERE pay_method = '".$pm."'";
00189 
00190                 $res = $ilDB->query($query);
00191 
00192                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00193                 {
00194                         return $row->pm;
00195                 }
00196                 return 0;
00197         }
00198                 
00199 
00200         // only called from payment settings object. Since there is no vendor check.
00201         function _getAllObjectsData()
00202         {
00203                 ;
00204         }
00205 
00206         function _getObjectsData($a_user_id)
00207         {
00208                 global $ilDB;
00209 
00210                 // get all vendors user is assigned to
00211                 include_once './payment/classes/class.ilPaymentTrustees.php';
00212                 include_once './payment/classes/class.ilPaymentVendors.php';
00213 
00214                 $vendors = ilPaymentTrustees::_getVendorsForObjects($a_user_id);
00215 
00216                 if(ilPaymentVendors::_isVendor($a_user_id))
00217                 {
00218                         $vendors[] = $a_user_id;
00219                 }
00220 
00221                 if(!count($vendors))
00222                 {
00223                         return array();
00224                 }
00225                 $in = " IN ('";
00226                 $in .= implode("','",$vendors);
00227                 $in .= "')";
00228 
00229                 $query = "SELECT * FROM payment_objects ".
00230                         "WHERE vendor_id ".$in;
00231 
00232                 $res = $ilDB->query($query);
00233                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00234                 {
00235                         $objects[$row->pobject_id]['pobject_id'] = $row->pobject_id;
00236                         $objects[$row->pobject_id]['ref_id'] = $row->ref_id;
00237                         $objects[$row->pobject_id]['status'] = $row->status;
00238                         $objects[$row->pobject_id]['pay_method'] = $row->pay_method;
00239                         $objects[$row->pobject_id]['vendor_id'] = $row->vendor_id;
00240                 }
00241                 return $objects ? $objects : array();
00242         }
00243 
00244         function _isPurchasable($a_ref_id)
00245         {
00246                 global $ilDB;
00247 
00248                 // In the moment it's not possible to sell one object twice
00249                 $query = "SELECT * FROM payment_objects ".
00250                         "WHERE ref_id = '".$a_ref_id."'";
00251 
00252                 #"AND status = '1' OR status = '3' ";
00253                 
00254                 $res = $ilDB->query($query);
00255 
00256                 return $res->numRows() ? false : true;
00257         }
00258 
00259         // base method to check access for a specific object
00260         function _hasAccess($a_ref_id)
00261         {
00262                 include_once './payment/classes/class.ilPaymentBookings.php';
00263 
00264                 global $rbacsystem,$ilDB;
00265 
00266                 // check write access
00267                 if($rbacsystem->checkAccess('write',$a_ref_id))
00268                 {
00269                         return true;
00270                 }
00271                 $query = "SELECT * FROM payment_objects ".
00272                         "WHERE ref_id = '".$a_ref_id."' ".
00273                         "AND (status = '1' OR status = '2')";
00274 
00275                 $res = $ilDB->query($query);
00276                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00277                 {
00278                         if(!ilPaymentBookings::_hasAccess($row->pobject_id))
00279                         {
00280                                 return false;
00281                         }
00282                 }
00283                 return true;
00284         }
00285         // base method to check access for a specific object
00286         function _getActivation($a_ref_id)
00287         {
00288                 include_once './payment/classes/class.ilPaymentBookings.php';
00289 
00290                 global $rbacsystem,$ilDB;
00291 
00292                 $query = "SELECT * FROM payment_objects ".
00293                         "WHERE ref_id = '".$a_ref_id."' ".
00294                         "AND (status = '1' OR status = '2')";
00295 
00296                 $res = $ilDB->query($query);
00297                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00298                 return ilPaymentBookings::_getActivation($row->pobject_id);
00299         }
00300         function _isBuyable($a_ref_id)
00301         {
00302                 global $ilDB;
00303 
00304                 $query = "SELECT * FROM payment_objects ".
00305                         "WHERE ref_id = '".$a_ref_id."' ".
00306                         "AND (status = 1 or status = 2)";
00307 
00308                 $res = $ilDB->query($query);
00309                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00310                 {
00311                         return true;
00312                 }
00313                 return false;
00314         }
00315                 
00316         // PRIVATE
00317         function __read()
00318         {
00319                 if($this->getPobjectId())
00320                 {
00321                         $query = "SELECT * FROM payment_objects ".
00322                                 "WHERE pobject_id = '".$this->getPobjectId()."'";
00323 
00324                         $res = $this->db->query($query);
00325                         while($row =& $res->fetchRow(DB_FETCHMODE_OBJECT))
00326                         {
00327                                 $this->setRefId($row->ref_id);
00328                                 $this->setStatus($row->status);
00329                                 $this->setPayMethod($row->pay_method);
00330                                 $this->setVendorId($row->vendor_id);
00331                                 
00332                                 return true;
00333                         }
00334                 }
00335                 return false;
00336         }
00337                                 
00338 
00339 } // END class.ilPaymentObject
00340 ?>

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1