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 #
4 # FILE: PrivilegeFactory.php
5 #
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/
9 #
10
16 class PrivilegeFactory extends ItemFactory {
17
18 # ---- PUBLIC INTERFACE --------------------------------------------------
19
22
24 public function PrivilegeFactory()
25 {
26 $this->ItemFactory("Privilege", "CustomPrivileges", "Id", "Name");
27
28 $AllConstants = get_defined_constants(TRUE);
29 $UserConstants = $AllConstants["user"];
30
31 foreach ($UserConstants as $Name => $Value)
32 {
33 if (strpos($Name, "PRIV_") === 0)
34 {
35 $this->PrivilegeConstants[$Value] = $Name;
36 }
37 }
38 }
39
44
52 public function GetPrivileges($IncludePredefined = TRUE, $ReturnObjects = TRUE)
53 {
54 # if caller wants predefined privileges included
55 if ($IncludePredefined)
56 {
57 # get complete list of privilege names
58 $PrivNames = $this->GetItemNames();
59 }
60 else
61 {
62 # read in only custom privileges from DB
63 $PrivNames = parent::GetItemNames();
64 }
65
66 # if caller requested objects to be returned
67 if ($ReturnObjects)
68 {
69 $PrivObjects = array();
70
71 # convert strings to objects and return to caller
72 foreach ($PrivNames as $Id => $Name)
73 {
74 $PrivObjects[$Id] = new Privilege($Id);
75 }
76
77 return $PrivObjects;
78 }
79 else
80 {
81 # return strings to caller
82 return $PrivNames;
83 }
84 }
85
91 public function GetPrivilegeWithName($Name)
92 {
93 global $G_PrivDescriptions;
94
95 # predefined privilege constant name
96 if (in_array($Name, $this->PrivilegeConstants))
97 {
98 $Id = array_search($Name, $this->PrivilegeConstants);
99 $Privilege = new Privilege($Id);
100
101 return $Privilege;
102 }
103
104 # predefined privilege constant description
105 if (in_array($Name, $G_PrivDescriptions))
106 {
107 $ConstantName = array_search($Name, $G_PrivDescriptions);
108 $Id = array_search($ConstantName, $this->PrivilegeConstants);
109 $Privilege = new Privilege($Id);
110
111 return $Privilege;
112 }
113
114 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
115
116 # custom privilege name
117 foreach ($CustomPrivileges as $Id => $PrivilegeName)
118 {
119 if ($Name == $PrivilegeName)
120 {
121 $Privilege = new Privilege($Id);
122
123 return $Privilege;
124 }
125 }
126
127 return NULL;
128 }
129
135 public function GetPrivilegeWithValue($Value)
136 {
137 global $G_PrivDescriptions;
138
139 # predefined privilege constant name
140 if (array_key_exists($Value, $this->PrivilegeConstants))
141 {
142 $Privilege = new Privilege($Value);
143
144 return $Privilege;
145 }
146
147 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
148
149 # custom privilege name
150 foreach ($CustomPrivileges as $Id => $PrivilegeName)
151 {
152 if ($Value == $Id)
153 {
154 $Privilege = new Privilege($Id);
155
156 return $Privilege;
157 }
158 }
159
160 return NULL;
161 }
162
167 public function GetPredefinedPrivilegeConstants()
168 {
169 return $this->PrivilegeConstants;
170 }
171
178 function GetItemNames($SqlCondition = NULL)
179 {
180 $Names = parent::GetItemNames($SqlCondition);
181 $Names = $Names + $GLOBALS["G_PrivDescriptions"];
182 asort($Names);
183 return $Names;
184 }
185
190
196 public function PrivilegeNameExists($Name)
197 {
198 global $G_PrivDescriptions;
199
200 # predefined privilege constant name
201 if (in_array($Name, $this->PrivilegeConstants))
202 {
203 return TRUE;
204 }
205
206 # predefined privilege constant description
207 if (in_array($Name, $G_PrivDescriptions))
208 {
209 return TRUE;
210 }
211
212 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
213
214 # custom privilege name
215 if (in_array($Name, $CustomPrivileges))
216 {
217 return TRUE;
218 }
219
220 return FALSE;
221 }
222
228 public function PrivilegeValueExists($Value)
229 {
230 # predefined privilege constant name
231 if (array_key_exists($Value, $this->PrivilegeConstants))
232 {
233 return TRUE;
234 }
235
236 $CustomPrivileges = $this->GetPrivileges(FALSE);
237
238 foreach ($CustomPrivileges as $Privilege)
239 {
240 if ($Value == $Privilege->Id())
241 {
242 return TRUE;
243 }
244 }
245
246 return FALSE;
247 }
248
251 # ---- PRIVATE INTERFACE -------------------------------------------------
252
253 private $PrivilegeConstants = array();
254
255 }
Privilege
User rights management framework allowing custom privege definition.
Definition: Privilege.php:16
PrivilegeFactory\GetPrivilegeWithName
GetPrivilegeWithName($Name)
Get the Privilege object with the given name.
Definition: PrivilegeFactory.php:91
PrivilegeFactory\GetPredefinedPrivilegeConstants
GetPredefinedPrivilegeConstants()
Get all predefined privilege constants and their values.
Definition: PrivilegeFactory.php:167
PrivilegeFactory
Factory which extracts all defined privileges from the database.
Definition: PrivilegeFactory.php:16
PrivilegeFactory\PrivilegeNameExists
PrivilegeNameExists($Name)
Determine if a privilege with the given name exists.
Definition: PrivilegeFactory.php:196
PrivilegeFactory\PrivilegeFactory
PrivilegeFactory()
Object constructor.
Definition: PrivilegeFactory.php:24
PrivilegeFactory\GetItemNames
GetItemNames($SqlCondition=NULL)
Retrieve human-readable privilege names.
Definition: PrivilegeFactory.php:178
PrivilegeFactory\GetPrivileges
GetPrivileges($IncludePredefined=TRUE, $ReturnObjects=TRUE)
Get all privileges.
Definition: PrivilegeFactory.php:52
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:135
ItemFactory\ItemFactory
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36
PrivilegeFactory\PrivilegeValueExists
PrivilegeValueExists($Value)
Determine if a privilege with the given value exists.
Definition: PrivilegeFactory.php:228