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

payment/classes/class.ilPaymentTrustees.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 
00034 class ilPaymentTrustees
00035 {
00036         var $db = null;
00037 
00038         var $user_obj;
00039         var $trustees = array();
00040 
00045         function ilPaymentTrustees(&$user_obj)
00046         {
00047                 global $ilDB;
00048 
00049                 $this->db =& $ilDB;
00050                 $this->user_obj =& $user_obj;
00051 
00052                 $this->PERM_STATISTIC = 1;
00053                 $this->PERM_OBJECT = 2;
00054 
00055                 $this->__read();
00056         }
00057         
00058         function getTrustees()
00059         {
00060                 return $this->trustees ? $this->trustees : array();
00061         }
00062         function getTrustee($a_usr_id)
00063         {
00064                 return isset($this->trustees[$a_usr_id]) ? $this->trustees[$a_usr_id] : array();
00065         }
00066         function isTrustee($a_usr_id)
00067         {
00068                 return isset($this->trustees[$a_usr_id]);
00069         }
00070 
00071 
00072         
00073         function toggleStatisticPermission($a_on)
00074         {
00075                 $this->perm_stat = (bool) $a_on;
00076         }
00077         function toggleObjectPermission($a_on)
00078         {
00079                 $this->perm_obj = (bool) $a_on;
00080         }
00081         function setTrusteeId($a_id)
00082         {
00083                 $this->trustee_id = $a_id;
00084         }
00085 
00086         function add()
00087         {
00088                 $query = "INSERT INTO payment_trustees ".
00089                         "SET vendor_id = '".$this->user_obj->getId()."', ".
00090                         "trustee_id = '".$this->__getTrusteeId()."', ".
00091                         "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
00092                         "perm_obj = '".$this->__getObjectPermissisonStatus()."'";
00093                 
00094                 $this->db->query($query);
00095                 $this->__read();
00096 
00097                 return true;
00098         }
00099         function modify()
00100         {
00101                 if(!$this->__getTrusteeId())
00102                 {
00103                         die("ilPaymentTrustees::modify() no id given");
00104                 }
00105 
00106                 $query = "UPDATE payment_trustees SET ".
00107                         "trustee_id = '".$this->__getTrusteeId()."', ".
00108                         "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
00109                         "perm_obj = '".$this->__getObjectPermissisonStatus()."' ".
00110                         "WHERE vendor_id = '".$this->user_obj->getId()."' ".
00111                         "AND trustee_id = '".$this->__getTrusteeId()."'";
00112 
00113                 $this->db->query($query);
00114                 $this->__read();
00115 
00116                 return true;
00117         }
00118         function delete()
00119         {
00120                 if(!$this->__getTrusteeId())
00121                 {
00122                         die("ilPaymentTrustees::delete() no id given");
00123                 }
00124                 $query = "DELETE FROM payment_trustees ".
00125                         "WHERE vendor_id = '".$this->user_obj->getId()."' ".
00126                         "AND trustee_id = '".$this->__getTrusteeId()."'";
00127 
00128                 $this->db->query($query);
00129                 $this->__read();
00130 
00131                 return true;
00132         }
00133         
00134         function deleteAll()
00135         {
00136                 $query = "DELETE FROM payment_trustees ".
00137                         "WHERE vendor_id = '".$this->user_obj->getId()."'";
00138 
00139                 $this->db->query($query);
00140                 $this->__read();
00141 
00142                 return true;
00143         }
00144                         
00145 
00146         // PRIVATE
00147         function __getTrusteeId()
00148         {
00149                 return $this->trustee_id;
00150         }
00151         function __getStatisticPermissionStatus()
00152         {
00153                 return (int) $this->perm_stat;
00154         }
00155         function __getObjectPermissisonStatus()
00156         {
00157                 return (int) $this->perm_obj;
00158         }
00159         function __read()
00160         {
00161                 $this->trustees = array();
00162 
00163                 $query = "SELECT * FROM payment_trustees ".
00164                         "WHERE vendor_id = '".$this->user_obj->getId()."'";
00165 
00166                 $res = $this->db->query($query);
00167                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00168                 {
00169                         $this->trustees[$row->trustee_id]['trustee_id'] = $row->trustee_id;
00170                         $this->trustees[$row->trustee_id]['perm_stat'] = $row->perm_stat;
00171                         $this->trustees[$row->trustee_id]['perm_obj'] = $row->perm_obj;
00172                 }
00173         }
00174 
00175         // STATIC
00176         function _deleteTrusteesOfVendor($a_vendor_id)
00177         {
00178                 global $ilDB;
00179 
00180                 $query = "DELETE FROM payment_trustees ".
00181                         "WHERE vendor_id = '".$a_vendor_id."'";
00182 
00183                 $ilDB->query($query);
00184 
00185                 return true;
00186         }
00187 
00188         function _hasStatisticPermission($a_trustee)
00189         {
00190                 global $ilDB;
00191                 
00192                 $query = "SELECT * FROM payment_trustees ".
00193                         "WHERE trustee_id = '".$a_trustee."'";
00194 
00195                 $res = $ilDB->query($query);
00196                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00197                 {
00198                         if((bool) $row->perm_stat)
00199                         {
00200                                 return true;
00201                         }
00202                 }
00203                 return false;
00204         }
00205         function _hasObjectPermission($a_trustee)
00206         {
00207                 global $ilDB;
00208                 
00209                 $query = "SELECT * FROM payment_trustees ".
00210                         "WHERE trustee_id = '".$a_trustee."'";
00211 
00212                 $res = $ilDB->query($query);
00213                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00214                 {
00215                         if((bool) $row->perm_obj)
00216                         {
00217                                 return true;
00218                         }
00219                 }
00220                 return false;
00221         }
00222         function _hasStatisticPermissionByVendor($a_trustee,$a_vendor)
00223         {
00224                 global $ilDB;
00225 
00226                 $query = "SELECT * FROM payment_trustees ".
00227                         "WHERE trustee_id = '".$a_trustee."' ".
00228                         "AND vendor_id = '".$a_vendor."' ".
00229                         "AND perm_stat = '1'";
00230 
00231                 $res = $ilDB->query($query);
00232 
00233                 return $res->numRows() ? true : false;
00234         }
00235 
00236         function _hasObjectPermissionByVendor($a_trustee,$a_vendor)
00237         {
00238                 global $ilDB;
00239 
00240                 $query = "SELECT * FROM payment_trustees ".
00241                         "WHERE trustee_id = '".$a_trustee."' ".
00242                         "AND vendor_id = '".$a_vendor."' ".
00243                         "AND perm_obj = '1'";
00244 
00245                 $res = $ilDB->query($query);
00246 
00247                 return $res->numRows() ? true : false;
00248         }
00249 
00250         function _hasAccess($a_usr_id)
00251         {
00252                 return ilPaymentTrustees::_hasStatisticPermission($a_usr_id) or 
00253                         ilPaymentTrustees::_hasObjectPermission($a_usr_id);
00254         }
00255 
00256         function _getVendorsForObjects($a_usr_id)
00257         {
00258                 global $ilDB;
00259 
00260                 $query = "SELECT vendor_id FROM payment_trustees ".
00261                         "WHERE perm_obj = '1' ".
00262                         "AND trustee_id = '".$a_usr_id."'";
00263 
00264                 $res = $ilDB->query($query);
00265                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00266                 {
00267                         $vendors[] = $row->vendor_id;
00268                 }
00269 
00270                 return $vendors ? $vendors : array();
00271         }
00272 
00273 } // END class.ilPaymentTrustees
00274 ?>

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