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

Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00032 class ilLDAPRoleAssignmentRule
00033 {
00034         private static $instances = null;
00035         
00036         const TYPE_GROUP = 1;
00037         const TYPE_ATTRIBUTE = 2;
00038         
00046         private function __construct($a_id = 0)
00047         {
00048                 global $ilDB;
00049                 
00050                 $this->db = $ilDB;      
00051 
00052                 $this->rule_id = $a_id;
00053                 $this->read();
00054         }
00055         
00064         public static function _getInstanceByRuleId($a_rule_id)
00065         {
00066                 if(isset(self::$instances[$a_rule_id]))
00067                 {
00068                         return self::$instances[$a_rule_id];
00069                 }
00070                 return self::$instances[$a_rule_id] = new ilLDAPRoleAssignmentRule($a_rule_id);
00071         }
00072         
00073         
00080         public function _getRules()
00081         {
00082                 global $ilDB;
00083                 
00084                 $query = "SELECT rule_id FROM ldap_role_assignments ";
00085                 $res = $ilDB->query($query);
00086                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00087                 {
00088                         $rules[] = self::_getInstanceByRuleId($row->rule_id);
00089                 }
00090                 return $rules ? $rules : array();
00091         }
00092         
00100         public function setRoleId($a_role_id)
00101         {
00102                 $this->role_id = $a_role_id;    
00103         }
00104         
00111         public function getRoleId()
00112         {
00113                 return $this->role_id;
00114         }
00115         
00122         public function getRuleId()
00123         {
00124                 return $this->rule_id;
00125         }
00126         
00134         public function setServerId($a_id)
00135         {
00136                 $this->server_id = $a_id;
00137         }
00138         
00145         public function getServerId()
00146         {
00147                 return $this->server_id;
00148         }
00149         
00157         public function setType($a_type)
00158         {
00159                 $this->type = $a_type;
00160         }
00161         
00169         public function getType()
00170         {
00171                 return $this->type;
00172         }
00173         
00181         public function setDN($a_dn)
00182         {
00183                 $this->dn = $a_dn;
00184         }
00185         
00192         public function getDN()
00193         {
00194                 return $this->dn;
00195         }
00196         
00204         public function setMemberAttribute($a_attribute)
00205         {
00206                 $this->member_attribute = $a_attribute;
00207         }
00208         
00215         public function getMemberAttribute()
00216         {
00217                 return $this->member_attribute;
00218         }
00219         
00227         public function setMemberIsDN($a_status)
00228         {
00229                 $this->member_is_dn = $a_status;
00230         }
00231         
00238         public function isMemberAttributeDN()
00239         {
00240                 return (bool) $this->member_is_dn;
00241         }
00242         
00250         public function setAttributeName($a_name)
00251         {
00252                 $this->attribute_name = $a_name;
00253         }
00254         
00261         public function getAttributeName()
00262         {
00263                 return $this->attribute_name;
00264         }
00265         
00273         public function setAttributeValue($a_value)
00274         {
00275                 $this->attribute_value = $a_value;
00276         }
00277         
00284         public function getAttributeValue()
00285         {
00286                 return $this->attribute_value;
00287         }
00288         
00295         public function conditionToString()
00296         {
00297                 switch($this->getType())
00298                 {
00299                         case self::TYPE_GROUP:
00300                                 $dn_arr = explode(',',$this->getDN());
00301                                 return $dn_arr[0];
00302                                 
00303                         
00304                         case self::TYPE_ATTRIBUTE:
00305                                 return $this->getAttributeName().'='.$this->getAttributeValue();
00306                 }
00307         }
00308         
00309         
00317         public function create()
00318         {
00319                 $query = "INSERT INTO ldap_role_assignments ".
00320                         "SET server_id = ".$this->db->quote($this->getServerId()).", ".
00321                         "type = ".$this->db->quote($this->getType()).", ".
00322                         "dn = ".$this->db->quote($this->getDN()).", ".
00323                         "attribute = ".$this->db->quote($this->getMemberAttribute()).", ".
00324                         "isdn = ".$this->db->quote($this->isMemberAttributeDN()).", ".
00325                         "att_name = ".$this->db->quote($this->getAttributeName()).", ".
00326                         "att_value = ".$this->db->quote($this->getAttributeValue()).", ".
00327                         "role_id = ".(int) $this->getRoleId()." ";
00328                 $res = $this->db->query($query);
00329                 
00330                 $this->rule_id = $this->db->getLastInsertId();
00331                 return true;
00332         }
00333 
00340         public function update()
00341         {
00342                 $query = "UPDATE ldap_role_assignments ".
00343                         "SET server_id = ".$this->db->quote($this->getServerId()).", ".
00344                         "type = ".$this->db->quote($this->getType()).", ".
00345                         "dn = ".$this->db->quote($this->getDN()).", ".
00346                         "attribute = ".$this->db->quote($this->getMemberAttribute()).", ".
00347                         "isdn = ".$this->db->quote($this->isMemberAttributeDN()).", ".
00348                         "att_name = ".$this->db->quote($this->getAttributeName()).", ".
00349                         "att_value = ".$this->db->quote($this->getAttributeValue()).", ".
00350                         "role_id = ".(int) $this->getRoleId()." ".
00351                         "WHERE rule_id = ".$this->db->quote($this->getRuleId())." ";
00352                         
00353                 $res = $this->db->query($query);
00354                 
00355                 $this->rule_id = $this->db->getLastInsertId();
00356                 return true;
00357         }
00358         
00365         public function validate()
00366         {
00367                 global $ilErr;
00368                 
00369                 $ilErr->setMessage('');
00370                 
00371                 if(!$this->getRoleId())
00372                 {
00373                         $ilErr->setMessage('fill_out_all_required_fields');
00374                         return false;
00375                 }
00376                 switch($this->getType())
00377                 {
00378                         case self::TYPE_GROUP:
00379                                 if(!strlen($this->getDN()) or !strlen($this->getMemberAttribute()))
00380                                 {
00381                                         $ilErr->setMessage('fill_out_all_required_fields');
00382                                         return false;
00383                                 }
00384                                 break;
00385                         case self::TYPE_ATTRIBUTE:
00386                                 if(!strlen($this->getAttributeName()) or !strlen($this->getAttributeValue()))
00387                                 {
00388                                         $ilErr->setMessage('fill_out_all_required_fields');
00389                                         return false;
00390                                 }
00391                                 break;
00392                                 
00393                         default:
00394                                 $ilErr->setMessage('ldap_no_type_given');
00395                                 return false;
00396                 }
00397                 return true;
00398         }
00399                 
00406         public function delete()
00407         {
00408                 $query = "DELETE FROM ldap_role_assignments ".
00409                         "WHERE rule_id = ".$this->db->quote($this->getRuleId())." ";
00410                 $this->db->query($query);
00411                 return true;
00412                         
00413         }
00420         private function read()
00421         {
00422                 $query = "SELECT * FROM ldap_role_assignments ".
00423                         "WHERE rule_id = ".$this->db->quote($this->getRuleId())." ";
00424                 
00425                 $res = $this->db->query($query);
00426                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00427                 {
00428                         $this->setServerId($row->server_id);
00429                         $this->setType($row->type);
00430                         $this->setDN($row->dn);
00431                         $this->setMemberAttribute($row->attribute);
00432                         $this->setMemberIsDN($row->isdn);
00433                         $this->setAttributeName($row->att_name);
00434                         $this->setAttributeValue($row->att_value);
00435                         $this->setRoleId($row->role_id);
00436                 }
00437         }
00438 }
00439 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1