Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 toggleCouponsPermission($a_on)
00082 {
00083 $this->perm_coupons = (bool) $a_on;
00084 }
00085 function setTrusteeId($a_id)
00086 {
00087 $this->trustee_id = $a_id;
00088 }
00089
00090 function add()
00091 {
00092 $query = "INSERT INTO payment_trustees ".
00093 "SET vendor_id = '".$this->user_obj->getId()."', ".
00094 "trustee_id = '".$this->__getTrusteeId()."', ".
00095 "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
00096 "perm_coupons = '".$this->__getCouponsPermissisonStatus()."', ".
00097 "perm_obj = '".$this->__getObjectPermissisonStatus()."'";
00098
00099 $this->db->query($query);
00100 $this->__read();
00101
00102 return true;
00103 }
00104 function modify()
00105 {
00106 if(!$this->__getTrusteeId())
00107 {
00108 die("ilPaymentTrustees::modify() no id given");
00109 }
00110
00111 $query = "UPDATE payment_trustees SET ".
00112 "trustee_id = '".$this->__getTrusteeId()."', ".
00113 "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
00114 "perm_obj = '".$this->__getObjectPermissisonStatus()."', ".
00115 "perm_coupons = '".$this->__getCouponsPermissisonStatus()."' ".
00116 "WHERE vendor_id = '".$this->user_obj->getId()."' ".
00117 "AND trustee_id = '".$this->__getTrusteeId()."'";
00118
00119 $this->db->query($query);
00120 $this->__read();
00121
00122 return true;
00123 }
00124 function delete()
00125 {
00126 if(!$this->__getTrusteeId())
00127 {
00128 die("ilPaymentTrustees::delete() no id given");
00129 }
00130 $query = "DELETE FROM payment_trustees ".
00131 "WHERE vendor_id = '".$this->user_obj->getId()."' ".
00132 "AND trustee_id = '".$this->__getTrusteeId()."'";
00133
00134 $this->db->query($query);
00135 $this->__read();
00136
00137 return true;
00138 }
00139
00140 function deleteAll()
00141 {
00142 $query = "DELETE FROM payment_trustees ".
00143 "WHERE vendor_id = '".$this->user_obj->getId()."'";
00144
00145 $this->db->query($query);
00146 $this->__read();
00147
00148 return true;
00149 }
00150
00151
00152
00153 function __getTrusteeId()
00154 {
00155 return $this->trustee_id;
00156 }
00157 function __getStatisticPermissionStatus()
00158 {
00159 return (int) $this->perm_stat;
00160 }
00161 function __getObjectPermissisonStatus()
00162 {
00163 return (int) $this->perm_obj;
00164 }
00165 function __getCouponsPermissisonStatus()
00166 {
00167 return (int) $this->perm_coupons;
00168 }
00169 function __read()
00170 {
00171 $this->trustees = array();
00172
00173 $query = "SELECT * FROM payment_trustees ".
00174 "WHERE vendor_id = '".$this->user_obj->getId()."'";
00175
00176 $res = $this->db->query($query);
00177 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00178 {
00179 $this->trustees[$row->trustee_id]['trustee_id'] = $row->trustee_id;
00180 $this->trustees[$row->trustee_id]['perm_stat'] = $row->perm_stat;
00181 $this->trustees[$row->trustee_id]['perm_obj'] = $row->perm_obj;
00182 $this->trustees[$row->trustee_id]['perm_coupons'] = $row->perm_coupons;
00183 }
00184 }
00185
00186
00187 function _deleteTrusteesOfVendor($a_vendor_id)
00188 {
00189 global $ilDB;
00190
00191 $query = "DELETE FROM payment_trustees ".
00192 "WHERE vendor_id = '".$a_vendor_id."'";
00193
00194 $ilDB->query($query);
00195
00196 return true;
00197 }
00198
00199 function _hasStatisticPermission($a_trustee)
00200 {
00201 global $ilDB;
00202
00203 $query = "SELECT * FROM payment_trustees ".
00204 "WHERE trustee_id = '".$a_trustee."'";
00205
00206 $res = $ilDB->query($query);
00207 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00208 {
00209 if((bool) $row->perm_stat)
00210 {
00211 return true;
00212 }
00213 }
00214 return false;
00215 }
00216 function _hasObjectPermission($a_trustee)
00217 {
00218 global $ilDB;
00219
00220 $query = "SELECT * FROM payment_trustees ".
00221 "WHERE trustee_id = '".$a_trustee."'";
00222
00223 $res = $ilDB->query($query);
00224 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00225 {
00226 if((bool) $row->perm_obj)
00227 {
00228 return true;
00229 }
00230 }
00231 return false;
00232 }
00233 function _hasCouponsPermission($a_trustee)
00234 {
00235 global $ilDB;
00236
00237 $query = "SELECT * FROM payment_trustees ".
00238 "WHERE trustee_id = '".$a_trustee."'";
00239
00240 $res = $ilDB->query($query);
00241 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00242 {
00243 if((bool) $row->perm_coupons)
00244 {
00245 return true;
00246 }
00247 }
00248 return false;
00249 }
00250 function _hasStatisticPermissionByVendor($a_trustee,$a_vendor)
00251 {
00252 global $ilDB;
00253
00254 $query = "SELECT * FROM payment_trustees ".
00255 "WHERE trustee_id = '".$a_trustee."' ".
00256 "AND vendor_id = '".$a_vendor."' ".
00257 "AND perm_stat = '1'";
00258
00259 $res = $ilDB->query($query);
00260
00261 return $res->numRows() ? true : false;
00262 }
00263
00264 function _hasObjectPermissionByVendor($a_trustee,$a_vendor)
00265 {
00266 global $ilDB;
00267
00268 $query = "SELECT * FROM payment_trustees ".
00269 "WHERE trustee_id = '".$a_trustee."' ".
00270 "AND vendor_id = '".$a_vendor."' ".
00271 "AND perm_obj = '1'";
00272
00273 $res = $ilDB->query($query);
00274
00275 return $res->numRows() ? true : false;
00276 }
00277
00278 function _hasCouponsPermissionByVendor($a_trustee,$a_vendor)
00279 {
00280 global $ilDB;
00281
00282 $query = "SELECT * FROM payment_trustees ".
00283 "WHERE trustee_id = '".$a_trustee."' ".
00284 "AND vendor_id = '".$a_vendor."' ".
00285 "AND perm_coupons = '1'";
00286
00287 $res = $ilDB->query($query);
00288
00289 return $res->numRows() ? true : false;
00290 }
00291
00292 function _hasAccess($a_usr_id)
00293 {
00294 return ilPaymentTrustees::_hasStatisticPermission($a_usr_id) or
00295 ilPaymentTrustees::_hasObjectPermission($a_usr_id) or
00296 ilPaymentTrustees::_hasCouponsPermission($a_usr_id);
00297 }
00298
00299 function _getVendorsForObjects($a_usr_id)
00300 {
00301 global $ilDB;
00302
00303 $query = "SELECT vendor_id FROM payment_trustees ".
00304 "WHERE perm_obj = '1' ".
00305 "AND trustee_id = '".$a_usr_id."'";
00306
00307 $res = $ilDB->query($query);
00308 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00309 {
00310 $vendors[] = $row->vendor_id;
00311 }
00312
00313 return $vendors ? $vendors : array();
00314 }
00315
00316 function _getVendorsForCouponsByTrusteeId($a_usr_id)
00317 {
00318 global $ilDB;
00319
00320 $query = "SELECT vendor_id FROM payment_trustees ".
00321 "WHERE perm_coupons = '1' ".
00322 "AND trustee_id = '".$a_usr_id."'";
00323
00324 $res = $ilDB->query($query);
00325 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00326 {
00327 $vendors[] = $row->vendor_id;
00328 }
00329
00330 return $vendors ? $vendors : array();
00331 }
00332
00333 function _getTrusteesForCouponsByVendorId($a_usr_id)
00334 {
00335 global $ilDB;
00336
00337 $query = "SELECT trustee_id FROM payment_trustees ".
00338 "WHERE perm_coupons = '1' ".
00339 "AND vendor_id = '".$a_usr_id."'";
00340
00341 $res = $ilDB->query($query);
00342 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00343 {
00344 $trustees[] = $row->trustee_id;
00345 }
00346
00347 return $trustees ? $trustees : array();
00348 }
00349
00350 }
00351 ?>