3 # FILE: PrivilegeFactory.php 5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2007-2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 25 parent::__construct(
"Privilege",
"CustomPrivileges",
"Id",
"Name");
27 $AllConstants = get_defined_constants(TRUE);
28 $UserConstants = $AllConstants[
"user"];
30 foreach ($UserConstants as $Name => $Value)
32 if (strpos($Name,
"PRIV_") === 0)
34 $this->PrivilegeConstants[$Value] = $Name;
53 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE)
55 # if caller wants predefined privileges included 56 if ($IncludePredefined)
58 # get complete list of privilege names 63 # read in only custom privileges from DB 64 $PrivNames = parent::GetItemNames();
67 # if caller requested objects to be returned 70 $PrivObjects = array();
72 # convert strings to objects and return to caller 73 foreach ($PrivNames as $Id => $Name)
82 # return strings to caller 94 global $G_PrivDescriptions;
96 # predefined privilege constant name 97 if (in_array($Name, $this->PrivilegeConstants))
99 $Id = array_search($Name, $this->PrivilegeConstants);
105 # predefined privilege constant description 106 if (in_array($Name, $G_PrivDescriptions))
108 $ConstantName = array_search($Name, $G_PrivDescriptions);
109 $Id = array_search($ConstantName, $this->PrivilegeConstants);
117 # custom privilege name 118 foreach ($CustomPrivileges as $Id => $PrivilegeName)
120 if ($Name == $PrivilegeName)
138 global $G_PrivDescriptions;
140 # predefined privilege constant name 141 if (array_key_exists($Value, $this->PrivilegeConstants))
150 # custom privilege name 151 foreach ($CustomPrivileges as $Id => $PrivilegeName)
170 return $this->PrivilegeConstants;
185 $Names = parent::GetItemNames($SqlCondition);
186 $Names = $Names + $GLOBALS[
"G_PrivDescriptions"];
188 # divide into Standard, Custom, and Pseudo sections, list 189 # alphabetically within each section 191 foreach ([
"Standard",
"Custom",
"Pseudo"] as $PType)
193 $TestFn =
"Is".$PType.
"Privilege";
195 foreach ($Names as $Id => $Name)
197 if (CWUser::$TestFn($Id))
199 $Section[$Id] = $Name;
205 # append elements from $Section to $TmpNames 206 # (see http://php.net/manual/en/language.operators.array.php) 207 $TmpNames += $Section;
227 global $G_PrivDescriptions;
229 # predefined privilege constant name 230 if (in_array($Name, $this->PrivilegeConstants))
235 # predefined privilege constant description 236 if (in_array($Name, $G_PrivDescriptions))
243 # custom privilege name 244 if (in_array($Name, $CustomPrivileges))
259 # predefined privilege constant name 260 if (array_key_exists($Value, $this->PrivilegeConstants))
267 foreach ($CustomPrivileges as $Privilege)
269 if ($Value == $Privilege->Id())
280 # ---- PRIVATE INTERFACE ------------------------------------------------- 282 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.