CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

PrivilegeFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: PrivilegeFactory.php
4 #
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/
8 #
9
14 class PrivilegeFactory extends ItemFactory
15 {
16
17 # ---- PUBLIC INTERFACE --------------------------------------------------
18
21
23 public function __construct()
24 {
25 parent::__construct("Privilege", "CustomPrivileges", "Id", "Name");
26
27 $AllConstants = get_defined_constants(TRUE);
28 $UserConstants = $AllConstants["user"];
29
30 foreach ($UserConstants as $Name => $Value)
31 {
32 if (strpos($Name, "PRIV_") === 0)
33 {
34 $this->PrivilegeConstants[$Value] = $Name;
35 }
36 }
37 }
38
43
53 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE)
54 {
55 # if caller wants predefined privileges included
56 if ($IncludePredefined)
57 {
58 # get complete list of privilege names
59 $PrivNames = $this->GetItemNames();
60 }
61 else
62 {
63 # read in only custom privileges from DB
64 $PrivNames = parent::GetItemNames();
65 }
66
67 # if caller requested objects to be returned
68 if ($ReturnObjects)
69 {
70 $PrivObjects = array();
71
72 # convert strings to objects and return to caller
73 foreach ($PrivNames as $Id => $Name)
74 {
75 $PrivObjects[$Id] = new Privilege($Id);
76 }
77
78 return $PrivObjects;
79 }
80 else
81 {
82 # return strings to caller
83 return $PrivNames;
84 }
85 }
86
92 public function GetPrivilegeWithName($Name)
93 {
94 global $G_PrivDescriptions;
95
96 # predefined privilege constant name
97 if (in_array($Name, $this->PrivilegeConstants))
98 {
99 $Id = array_search($Name, $this->PrivilegeConstants);
100 $Privilege = new Privilege($Id);
101
102 return $Privilege;
103 }
104
105 # predefined privilege constant description
106 if (in_array($Name, $G_PrivDescriptions))
107 {
108 $ConstantName = array_search($Name, $G_PrivDescriptions);
109 $Id = array_search($ConstantName, $this->PrivilegeConstants);
110 $Privilege = new Privilege($Id);
111
112 return $Privilege;
113 }
114
115 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
116
117 # custom privilege name
118 foreach ($CustomPrivileges as $Id => $PrivilegeName)
119 {
120 if ($Name == $PrivilegeName)
121 {
122 $Privilege = new Privilege($Id);
123
124 return $Privilege;
125 }
126 }
127
128 return NULL;
129 }
130
136 public function GetPrivilegeWithValue($Value)
137 {
138 global $G_PrivDescriptions;
139
140 # predefined privilege constant name
141 if (array_key_exists($Value, $this->PrivilegeConstants))
142 {
143 $Privilege = new Privilege($Value);
144
145 return $Privilege;
146 }
147
148 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
149
150 # custom privilege name
151 foreach ($CustomPrivileges as $Id => $PrivilegeName)
152 {
153 if ($Value == $Id)
154 {
155 $Privilege = new Privilege($Id);
156
157 return $Privilege;
158 }
159 }
160
161 return NULL;
162 }
163
168 public function GetPredefinedPrivilegeConstants()
169 {
170 return $this->PrivilegeConstants;
171 }
172
183 public function GetItemNames($SqlCondition = NULL)
184 {
185 $Names = parent::GetItemNames($SqlCondition);
186 $Names = $Names + $GLOBALS["G_PrivDescriptions"];
187
188 # divide into Standard, Custom, and Pseudo sections, list
189 # alphabetically within each section
190 $TmpNames = [];
191 foreach (["Standard", "Custom", "Pseudo"] as $PType)
192 {
193 $TestFn = "Is".$PType."Privilege";
194 $Section = [];
195 foreach ($Names as $Id => $Name)
196 {
197 if (CWUser::$TestFn($Id))
198 {
199 $Section[$Id] = $Name;
200 }
201 }
202
203 asort($Section);
204
205 # append elements from $Section to $TmpNames
206 # (see http://php.net/manual/en/language.operators.array.php)
207 $TmpNames += $Section;
208 }
209
210 $Names = $TmpNames;
211
212 return $Names;
213 }
214
219
225 public function PrivilegeNameExists($Name)
226 {
227 global $G_PrivDescriptions;
228
229 # predefined privilege constant name
230 if (in_array($Name, $this->PrivilegeConstants))
231 {
232 return TRUE;
233 }
234
235 # predefined privilege constant description
236 if (in_array($Name, $G_PrivDescriptions))
237 {
238 return TRUE;
239 }
240
241 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
242
243 # custom privilege name
244 if (in_array($Name, $CustomPrivileges))
245 {
246 return TRUE;
247 }
248
249 return FALSE;
250 }
251
257 public function PrivilegeValueExists($Value)
258 {
259 # predefined privilege constant name
260 if (array_key_exists($Value, $this->PrivilegeConstants))
261 {
262 return TRUE;
263 }
264
265 $CustomPrivileges = $this->GetPrivileges(FALSE);
266
267 foreach ($CustomPrivileges as $Privilege)
268 {
269 if ($Value == $Privilege->Id())
270 {
271 return TRUE;
272 }
273 }
274
275 return FALSE;
276 }
277
280 # ---- PRIVATE INTERFACE -------------------------------------------------
281
282 private $PrivilegeConstants = array();
283 }
Privilege
User rights management framework allowing custom privege definition.
Definition: Privilege.php:15
PrivilegeFactory\GetPrivilegeWithName
GetPrivilegeWithName($Name)
Get the Privilege object with the given name.
Definition: PrivilegeFactory.php:92
PrivilegeFactory\__construct
__construct()
Object constructor.
Definition: PrivilegeFactory.php:23
PrivilegeFactory\GetPredefinedPrivilegeConstants
GetPredefinedPrivilegeConstants()
Get all predefined privilege constants and their values.
Definition: PrivilegeFactory.php:168
PrivilegeFactory
Factory which extracts all defined privileges from the database.
Definition: PrivilegeFactory.php:14
PrivilegeFactory\PrivilegeNameExists
PrivilegeNameExists($Name)
Determine if a privilege with the given name exists.
Definition: PrivilegeFactory.php:225
PrivilegeFactory\GetItemNames
GetItemNames($SqlCondition=NULL)
Retrieve human-readable privilege names.
Definition: PrivilegeFactory.php:183
PrivilegeFactory\GetPrivileges
GetPrivileges($IncludePredefined=TRUE, $ReturnObjects=TRUE)
Get all privileges.
Definition: PrivilegeFactory.php:53
PHP
PHP
Definition: RSSClient--Test.php:12
ItemFactory
Common factory class for item manipulation.
Definition: ItemFactory.php:17
PrivilegeFactory\GetPrivilegeWithValue
GetPrivilegeWithValue($Value)
Get the Privilege object with the given value.
Definition: PrivilegeFactory.php:136
PrivilegeFactory\PrivilegeValueExists
PrivilegeValueExists($Value)
Determine if a privilege with the given value exists.
Definition: PrivilegeFactory.php:257