5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
15 # ---- PUBLIC INTERFACE --------------------------------------------------
23 static $EmailWrapperSet = FALSE;
24 if (!$EmailWrapperSet)
27 $EmailWrapperSet = TRUE;
30 # call the parent constructor
31 parent::User($UserInfo);
33 # try to fetch the associated resource if the user was found
34 if ($this->Result ===
U_OKAY)
38 # the associated resource was successfully found
44 # there was a problem finding the resource
59 # if new set of privileges supplied
60 if ($NewValue !== NULL)
62 # retrieve privilege list from set
63 $PrivList = $NewValue->GetPrivilegeList();
65 # set new privilege list for user
69 # retrieve privilege list for user
72 # convert privilege list to privilege set
74 foreach ($Privs as $Priv) { $Set->AddPrivilege($Priv); }
76 # set user associated with privilege set
77 $Set->AssociatedUserId($this->
Id());
79 # return privilege set to caller
107 public function HasPriv($Privilege, $Privileges = NULL)
112 if ($Privileges instanceof
Resource)
113 return $UserPrivs->IsGreaterThan($Privilege, $Privileges);
115 return $UserPrivs->IsGreaterThan($Privilege);
119 return call_user_func_array(
"parent::HasPriv", func_get_args() );
133 public static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
135 # extract "From" address from supplied headers if available
136 if (strlen($AdditionalHeaders))
138 $HeaderLines = explode(
"\n", $AdditionalHeaders);
140 foreach ($HeaderLines as $Line)
142 $HeaderLine = trim($Line);
143 if (preg_match(
"/^from:/i", $Line))
145 $From = preg_replace(
"/^from:/i",
"", $Line);
149 $Headers[] = $HeaderLine;
156 if (isset($From)) { $Msg->From($From); }
158 $Msg->Subject($Subject);
159 $Msg->AddHeaders($Headers);
160 $Msg->Body($Message);
163 # report success to caller
173 static $CustomFields;
175 if (!isset($CustomFields))
177 $CustomFields = array();
180 foreach ($Schema->GetFields() as $Field)
182 # they're custom if not owned by CWIS
183 if ($Field->Owner() !=
"CWISCore")
185 $CustomFields[$Field->Id()] = $Field;
190 return $CustomFields;
199 static $DefaultFields;
201 if (!isset($DefaultFields))
203 $DefaultFields = array();
206 foreach ($Schema->GetFields() as $Field)
208 # they're default if owned by CWIS
209 if ($Field->Owner() ==
"CWISCore")
211 $DefaultFields[$Field->Id()] = $Field;
216 return $DefaultFields;
219 # ---- OVERRIDDEN METHODS ------------------------------------------------
228 # delete the associated user resource if set
235 return parent::Delete();
244 public function Get($FieldName)
246 # provide backwards-compatibility for data migrated to users fields as
248 if (in_array($FieldName, self::$MigratedUserFields))
250 # return NULL if the resource object isn't set
256 # return the value from the associated resource
260 # otherwise, get it from the APUsers table
261 return parent::Get($FieldName);
270 public function Set($FieldName, $NewValue)
272 # provide backwards-compatibility for data migrated to users fields as
274 if (in_array($FieldName, self::$MigratedUserFields))
276 # set the value only if the resource object is set
284 # transform boolean values to 1 or 0 because that's what the User
286 if (is_bool($NewValue))
288 $NewValue = $NewValue ? 1 : 0;
291 # update the APUsers table
292 return parent::Set($FieldName, $NewValue);
295 # ---- PRIVATE INTERFACE -------------------------------------------------
308 "RealName",
"WebSite",
"AddressLineOne",
"AddressLineTwo",
"City",
309 "State",
"ZipCode",
"Country");
325 # couldn't get the factory or schema, which probably means CWIS hasn't
327 catch (Exception $Exception)
332 # the UserId field doesn't exist, which probably means CWIS hasn't been
334 if (!$Schema->FieldExists(
"UserId"))
339 # get matching resources, which should only be one
340 $Field = $Schema->GetFieldByName(
"UserId");
341 $ResourceIds = $Factory->GetItemIds(
"`".$Field->DBFieldName()
343 $ResourceIdCount = count($ResourceIds);
346 if ($ResourceIdCount < 1)
351 # too many resources found
352 if ($ResourceIdCount > 1)
357 # construct the associated resource and return it
358 return new Resource(array_shift($ResourceIds));
367 # there must be a user ID, which is what the User class assumes, and the
368 # resource must be set
369 return isset($this->UserId) && isset($this->
Resource);
Set($FieldName, $NewValue)
Set a value for the specified field.
$Resource
The user resource associated with the user or NULL if the user isn't logged in.
Privileges(PrivilegeSet $NewValue=NULL)
Get/set user privileges as a set.
ResourceId()
Get the ID of the user resource associated with the user.
Delete()
Delete the user and its associated user resource.
Set($FieldNameOrObject, $NewValue, $Reset=FALSE)
Set value using field name or field object.
Id()
Retrieve numerical resource ID.
FetchAssociatedResource($UserId)
Fetch the associated user resource based off of a user ID.
IsResourceObjectSet()
Determine if the resource object for this object is set.
HasPriv($Privilege, $Privileges=NULL)
Determine if a user has a speficifed prviliege.
Get($FieldName)
Get a value from the specified field.
Set of privileges used to access resource information or other parts of the system.
__construct($UserInfo=NULL)
Load user data from the given user info or from the session if available.
static EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
Adapter method to bridge between AxisPHP User class and ScoutLib Email class.
static SetEmailFunction($NewValue)
Set email function to use instead of mail().
Get($FieldNameOrObject, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field name or field object.
static $MigratedUserFields
Fields that were previously part of the APUsers table that have been migrated to the Resources table ...
Represents a "resource" in CWIS.
static GetDefaultUserFields()
Get the default user fields.
static GetCustomUserFields()
Get all custom user fields.
SetPrivList($NewPrivileges)
GetResource()
Get the associated user resource for this user.
Factory for Resource objects.
CWIS-specific user class.
Delete()
Remove resource (and accompanying associations) from database and delete any associated files...