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 $this->
ItemFactory(
"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;
180 $Names = parent::GetItemNames($SqlCondition);
181 $Names = $Names + $GLOBALS[
"G_PrivDescriptions"];
198 global $G_PrivDescriptions;
200 # predefined privilege constant name
201 if (in_array($Name, $this->PrivilegeConstants))
206 # predefined privilege constant description
207 if (in_array($Name, $G_PrivDescriptions))
214 # custom privilege name
215 if (in_array($Name, $CustomPrivileges))
230 # predefined privilege constant name
231 if (array_key_exists($Value, $this->PrivilegeConstants))
238 foreach ($CustomPrivileges as $Privilege)
240 if ($Value == $Privilege->Id())
251 # ---- PRIVATE INTERFACE -------------------------------------------------
253 private $PrivilegeConstants = array();
User rights management framework allowing custom privege definition.
GetPrivilegeWithName($Name)
Get the Privilege object with the given name.
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.
PrivilegeFactory()
Object constructor.
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.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
PrivilegeValueExists($Value)
Determine if a privilege with the given value exists.