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
180 public function GetItemNames($SqlCondition = NULL)
181 {
182 $Names = parent::GetItemNames($SqlCondition);
183 $Names = $Names + $GLOBALS["G_PrivDescriptions"];
184 asort($Names);
185 return $Names;
186 }
187
192
198 public function PrivilegeNameExists($Name)
199 {
200 global $G_PrivDescriptions;
201
202 # predefined privilege constant name
203 if (in_array($Name, $this->PrivilegeConstants))
204 {
205 return TRUE;
206 }
207
208 # predefined privilege constant description
209 if (in_array($Name, $G_PrivDescriptions))
210 {
211 return TRUE;
212 }
213
214 $CustomPrivileges = $this->GetPrivileges(FALSE, FALSE);
215
216 # custom privilege name
217 if (in_array($Name, $CustomPrivileges))
218 {
219 return TRUE;
220 }
221
222 return FALSE;
223 }
224
230 public function PrivilegeValueExists($Value)
231 {
232 # predefined privilege constant name
233 if (array_key_exists($Value, $this->PrivilegeConstants))
234 {
235 return TRUE;
236 }
237
238 $CustomPrivileges = $this->GetPrivileges(FALSE);
239
240 foreach ($CustomPrivileges as $Privilege)
241 {
242 if ($Value == $Privilege->Id())
243 {
244 return TRUE;
245 }
246 }
247
248 return FALSE;
249 }
250
253 # ---- PRIVATE INTERFACE -------------------------------------------------
254
255 private $PrivilegeConstants = array();
256 }
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:198
PrivilegeFactory\GetItemNames
GetItemNames($SqlCondition=NULL)
Retrieve human-readable privilege names.
Definition: PrivilegeFactory.php:180
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:230