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
113 public static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
115 # extract "From" address from supplied headers if available
116 if (strlen($AdditionalHeaders))
118 $HeaderLines = explode(
"\n", $AdditionalHeaders);
120 foreach ($HeaderLines as $Line)
122 $HeaderLine = trim($Line);
123 if (preg_match(
"/^from:/i", $Line))
125 $From = preg_replace(
"/^from:/i",
"", $Line);
129 $Headers[] = $HeaderLine;
136 if (isset($From)) { $Msg->From($From); }
138 $Msg->Subject($Subject);
139 $Msg->AddHeaders($Headers);
140 $Msg->Body($Message);
143 # report success to caller
153 static $CustomFields;
155 if (!isset($CustomFields))
157 $CustomFields = array();
160 foreach ($Schema->GetFields() as $Field)
162 # they're custom if not owned by CWIS
163 if ($Field->Owner() !=
"CWISCore")
165 $CustomFields[$Field->Id()] = $Field;
170 return $CustomFields;
179 static $DefaultFields;
181 if (!isset($DefaultFields))
183 $DefaultFields = array();
186 foreach ($Schema->GetFields() as $Field)
188 # they're default if owned by CWIS
189 if ($Field->Owner() !=
"CWISCore")
191 $DefaultFields[$Field->Id()] = $Field;
196 return $DefaultFields;
199 # ---- OVERRIDDEN METHODS ------------------------------------------------
208 # delete the associated user resource if set
215 return parent::Delete();
224 public function Get($FieldName)
226 # provide backwards-compatibility for data migrated to users fields as
228 if (in_array($FieldName, self::$MigratedUserFields))
230 # return NULL if the resource object isn't set
236 # return the value from the associated resource
240 # otherwise, get it from the APUsers table
241 return parent::Get($FieldName);
250 public function Set($FieldName, $NewValue)
252 # provide backwards-compatibility for data migrated to users fields as
254 if (in_array($FieldName, self::$MigratedUserFields))
256 # set the value only if the resource object is set
264 # transform boolean values to 1 or 0 because that's what the User
266 if (is_bool($NewValue))
268 $NewValue = $NewValue ? 1 : 0;
271 # update the APUsers table
272 return parent::Set($FieldName, $NewValue);
275 # ---- PRIVATE INTERFACE -------------------------------------------------
288 "RealName",
"WebSite",
"AddressLineOne",
"AddressLineTwo",
"City",
289 "State",
"ZipCode",
"Country");
305 # couldn't get the factory or schema, which probably means CWIS hasn't
307 catch (Exception $Exception)
312 # the UserId field doesn't exist, which probably means CWIS hasn't been
314 if (!$Schema->FieldExists(
"UserId"))
319 # get matching resources, which should only be one
320 $Field = $Schema->GetFieldByName(
"UserId");
321 $ResourceIds = $Factory->GetItemIds(
"`".$Field->DBFieldName()
323 $ResourceIdCount = count($ResourceIds);
326 if ($ResourceIdCount < 1)
331 # too many resources found
332 if ($ResourceIdCount > 1)
337 # construct the associated resource and return it
338 return new Resource(array_shift($ResourceIds));
347 # there must be a user ID, which is what the User class assumes, and the
348 # resource must be set
349 return isset($this->UserId) && isset($this->
Resource);
Set($FieldNameOrObject, $NewValue)
Set value using field name or field object.
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.
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.
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...