4 # FILE: PrivilegeFactory.php 6 # Part of the Collection Workflow Integration System (CWIS) 7 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group 8 # http://scout.wisc.edu/cwis/ 18 # ---- PUBLIC INTERFACE -------------------------------------------------- 26 parent::__construct(
"Privilege",
"CustomPrivileges",
"Id",
"Name");
28 $AllConstants = get_defined_constants(TRUE);
29 $UserConstants = $AllConstants[
"user"];
31 foreach ($UserConstants as $Name => $Value)
33 if (strpos($Name,
"PRIV_") === 0)
35 $this->PrivilegeConstants[$Value] = $Name;
52 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE)
54 # if caller wants predefined privileges included 55 if ($IncludePredefined)
57 # get complete list of privilege names 62 # read in only custom privileges from DB 63 $PrivNames = parent::GetItemNames();
66 # if caller requested objects to be returned 69 $PrivObjects = array();
71 # convert strings to objects and return to caller 72 foreach ($PrivNames as $Id => $Name)
81 # return strings to caller 93 global $G_PrivDescriptions;
95 # predefined privilege constant name 96 if (in_array($Name, $this->PrivilegeConstants))
98 $Id = array_search($Name, $this->PrivilegeConstants);
104 # predefined privilege constant description 105 if (in_array($Name, $G_PrivDescriptions))
107 $ConstantName = array_search($Name, $G_PrivDescriptions);
108 $Id = array_search($ConstantName, $this->PrivilegeConstants);
116 # custom privilege name 117 foreach ($CustomPrivileges as $Id => $PrivilegeName)
119 if ($Name == $PrivilegeName)
137 global $G_PrivDescriptions;
139 # predefined privilege constant name 140 if (array_key_exists($Value, $this->PrivilegeConstants))
149 # custom privilege name 150 foreach ($CustomPrivileges as $Id => $PrivilegeName)
169 return $this->PrivilegeConstants;
181 $Names = parent::GetItemNames($SqlCondition);
182 $Names = $Names + $GLOBALS[
"G_PrivDescriptions"];
199 global $G_PrivDescriptions;
201 # predefined privilege constant name 202 if (in_array($Name, $this->PrivilegeConstants))
207 # predefined privilege constant description 208 if (in_array($Name, $G_PrivDescriptions))
215 # custom privilege name 216 if (in_array($Name, $CustomPrivileges))
231 # predefined privilege constant name 232 if (array_key_exists($Value, $this->PrivilegeConstants))
239 foreach ($CustomPrivileges as $Privilege)
241 if ($Value == $Privilege->Id())
252 # ---- PRIVATE INTERFACE ------------------------------------------------- 254 private $PrivilegeConstants = array();
User rights management framework allowing custom privege definition.
GetPrivilegeWithName($Name)
Get the Privilege object with the given name.
__construct()
Object constructor.
GetPredefinedPrivilegeConstants()
Get all predefined privilege constants and their values.
Factory which extracts all defined privileges from the database.
PrivilegeNameExists($Name)
Determine if a privilege with the given name exists.
GetItemNames($SqlCondition=NULL)
Retrieve human-readable privilege names.
GetPrivileges($IncludePredefined=TRUE, $ReturnObjects=TRUE)
Get all privileges.
Common factory class for item manipulation.
GetPrivilegeWithValue($Value)
Get the Privilege object with the given value.
PrivilegeValueExists($Value)
Determine if a privilege with the given value exists.