PrivilegeFactory.php
Go to the documentation of this file.
00001 <?PHP 00002 00003 # 00004 # FILE: PrivilegeFactory.php 00005 # 00006 # METHODS PROVIDED: 00007 # PrivilegeFactory() 00008 # - constructor 00009 # SomeMethod($SomeParameter, $AnotherParameter) 00010 # - short description of method 00011 # 00012 # AUTHOR: Edward Almasy 00013 # 00014 # Part of the Collection Workflow Integration System 00015 # Copyright 2007 Edward Almasy and Internet Scout 00016 # http://scout.wisc.edu 00017 # 00018 00024 class PrivilegeFactory extends ItemFactory { 00025 00026 # ---- PUBLIC INTERFACE -------------------------------------------------- 00027 00030 00032 public function PrivilegeFactory() 00033 { 00034 $this->ItemFactory("Privilege", "CustomPrivileges", "Id", "Name"); 00035 00036 $AllConstants = get_defined_constants(TRUE); 00037 $UserConstants = $AllConstants["user"]; 00038 00039 foreach ($UserConstants as $Name => $Value) 00040 { 00041 if (strpos($Name, "PRIV_") === 0) 00042 { 00043 $this->PrivilegeConstants[$Value] = $Name; 00044 } 00045 } 00046 } 00047 00052 00060 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE) 00061 { 00062 # if caller wants predefined privileges included 00063 if ($IncludePredefined) 00064 { 00065 # get complete list of privilege names 00066 $PrivNames = $this->GetItemNames(); 00067 } 00068 else 00069 { 00070 # read in only custom privileges from DB 00071 $PrivNames = parent::GetItemNames(); 00072 } 00073 00074 # if caller requested objects to be returned 00075 if ($ReturnObjects) 00076 { 00077 # convert strings to objects and return to caller 00078 foreach ($PrivNames as $Id => $Name) 00079 { 00080 $PrivObjects[$Id] = new Privilege($Id); 00081 } 00082 return $PrivObjects; 00083 } 00084 else 00085 { 00086 # return strings to caller 00087 return $PrivNames; 00088 } 00089 } 00090 00096 public function GetPrivilegeWithName($Name) 00097 { 00098 global $G_PrivDescriptions; 00099 00100 # predefined privilege constant name 00101 if (in_array($Name, $this->PrivilegeConstants)) 00102 { 00103 $Id = array_search($Name, $this->PrivilegeConstants); 00104 $Privilege = new Privilege($Id); 00105 00106 return $Privilege; 00107 } 00108 00109 # predefined privilege constant description 00110 if (in_array($Name, $G_PrivDescriptions)) 00111 { 00112 $ConstantName = array_search($Name, $G_PrivDescriptions); 00113 $Id = array_search($ConstantName, $this->PrivilegeConstants); 00114 $Privilege = new Privilege($Id); 00115 00116 return $Privilege; 00117 } 00118 00119 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE); 00120 00121 # custom privilege name 00122 foreach ($CustomPrivileges as $Id => $PrivilegeName) 00123 { 00124 if ($Name == $PrivilegeName) 00125 { 00126 $Privilege = new Privilege($Id); 00127 00128 return $Privilege; 00129 } 00130 } 00131 00132 return NULL; 00133 } 00134 00140 public function GetPrivilegeWithValue($Value) 00141 { 00142 global $G_PrivDescriptions; 00143 00144 # predefined privilege constant name 00145 if (array_key_exists($Value, $this->PrivilegeConstants)) 00146 { 00147 $Privilege = new Privilege($Value); 00148 00149 return $Privilege; 00150 } 00151 00152 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE); 00153 00154 # custom privilege name 00155 foreach ($CustomPrivileges as $Id => $PrivilegeName) 00156 { 00157 if ($Value == $Id) 00158 { 00159 $Privilege = new Privilege($Id); 00160 00161 return $Privilege; 00162 } 00163 } 00164 00165 return NULL; 00166 } 00167 00172 public function GetPredefinedPrivilegeConstants() 00173 { 00174 return $this->PrivilegeConstants; 00175 } 00176 00183 function GetItemNames($SqlCondition = NULL) 00184 { 00185 $Names = parent::GetItemNames($SqlCondition); 00186 $Names = $Names + $GLOBALS["G_PrivDescriptions"]; 00187 asort($Names); 00188 return $Names; 00189 } 00190 00195 00201 public function PrivilegeNameExists($Name) 00202 { 00203 global $G_PrivDescriptions; 00204 00205 # predefined privilege constant name 00206 if (in_array($Name, $this->PrivilegeConstants)) 00207 { 00208 return TRUE; 00209 } 00210 00211 # predefined privilege constant description 00212 if (in_array($Name, $G_PrivDescriptions)) 00213 { 00214 return TRUE; 00215 } 00216 00217 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE); 00218 00219 # custom privilege name 00220 if (in_array($Name, $CustomPrivileges)) 00221 { 00222 return TRUE; 00223 } 00224 00225 return FALSE; 00226 } 00227 00233 public function PrivilegeValueExists($Value) 00234 { 00235 # predefined privilege constant name 00236 if (array_key_exists($Value, $this->PrivilegeConstants)) 00237 { 00238 return TRUE; 00239 } 00240 00241 $CustomPrivileges = $this->GetPrivileges(FALSE); 00242 00243 foreach ($CustomPrivileges as $Privilege) 00244 { 00245 if ($Value == $Privilege->Id()) 00246 { 00247 return TRUE; 00248 } 00249 } 00250 00251 return FALSE; 00252 } 00253 00256 # ---- PRIVATE INTERFACE ------------------------------------------------- 00257 00258 private $PrivilegeConstants = array(); 00259 00260 }