4 # FILE: PrivilegeFactory.php
9 # SomeMethod($SomeParameter, $AnotherParameter)
10 # - short description of method
12 # AUTHOR: Edward Almasy
14 # Part of the Collection Workflow Integration System
15 # Copyright 2007 Edward Almasy and Internet Scout
16 # http://scout.wisc.edu
26 # ---- PUBLIC INTERFACE --------------------------------------------------
34 $this->
ItemFactory(
"Privilege",
"CustomPrivileges",
"Id",
"Name");
36 $AllConstants = get_defined_constants(TRUE);
37 $UserConstants = $AllConstants[
"user"];
39 foreach ($UserConstants as $Name => $Value)
41 if (strpos($Name,
"PRIV_") === 0)
43 $this->PrivilegeConstants[$Value] = $Name;
60 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE)
62 # if caller wants predefined privileges included
63 if ($IncludePredefined)
65 # get complete list of privilege names
70 # read in only custom privileges from DB
71 $PrivNames = parent::GetItemNames();
74 # if caller requested objects to be returned
77 $PrivObjects = array();
79 # convert strings to objects and return to caller
80 foreach ($PrivNames as $Id => $Name)
89 # return strings to caller
101 global $G_PrivDescriptions;
103 # predefined privilege constant name
104 if (in_array($Name, $this->PrivilegeConstants))
106 $Id = array_search($Name, $this->PrivilegeConstants);
112 # predefined privilege constant description
113 if (in_array($Name, $G_PrivDescriptions))
115 $ConstantName = array_search($Name, $G_PrivDescriptions);
116 $Id = array_search($ConstantName, $this->PrivilegeConstants);
124 # custom privilege name
125 foreach ($CustomPrivileges as $Id => $PrivilegeName)
127 if ($Name == $PrivilegeName)
145 global $G_PrivDescriptions;
147 # predefined privilege constant name
148 if (array_key_exists($Value, $this->PrivilegeConstants))
157 # custom privilege name
158 foreach ($CustomPrivileges as $Id => $PrivilegeName)
177 return $this->PrivilegeConstants;
188 $Names = parent::GetItemNames($SqlCondition);
189 $Names = $Names + $GLOBALS[
"G_PrivDescriptions"];
206 global $G_PrivDescriptions;
208 # predefined privilege constant name
209 if (in_array($Name, $this->PrivilegeConstants))
214 # predefined privilege constant description
215 if (in_array($Name, $G_PrivDescriptions))
222 # custom privilege name
223 if (in_array($Name, $CustomPrivileges))
238 # predefined privilege constant name
239 if (array_key_exists($Value, $this->PrivilegeConstants))
246 foreach ($CustomPrivileges as $Privilege)
248 if ($Value == $Privilege->Id())
259 # ---- PRIVATE INTERFACE -------------------------------------------------
261 private $PrivilegeConstants = array();