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
104 public function HasPriv($Privilege, $Privileges = NULL)
109 return $UserPrivs->IsGreaterThan($Privilege);
113 return call_user_func_array(
"parent::HasPriv", func_get_args() );
127 public static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
129 # extract "From" address from supplied headers if available
130 if (strlen($AdditionalHeaders))
132 $HeaderLines = explode(
"\n", $AdditionalHeaders);
134 foreach ($HeaderLines as $Line)
136 $HeaderLine = trim($Line);
137 if (preg_match(
"/^from:/i", $Line))
139 $From = preg_replace(
"/^from:/i",
"", $Line);
143 $Headers[] = $HeaderLine;
150 if (isset($From)) { $Msg->From($From); }
152 $Msg->Subject($Subject);
153 $Msg->AddHeaders($Headers);
154 $Msg->Body($Message);
157 # report success to caller
167 static $CustomFields;
169 if (!isset($CustomFields))
171 $CustomFields = array();
174 foreach ($Schema->GetFields() as $Field)
176 # they're custom if not owned by CWIS
177 if ($Field->Owner() !=
"CWISCore")
179 $CustomFields[$Field->Id()] = $Field;
184 return $CustomFields;
193 static $DefaultFields;
195 if (!isset($DefaultFields))
197 $DefaultFields = array();
200 foreach ($Schema->GetFields() as $Field)
202 # they're default if owned by CWIS
203 if ($Field->Owner() !=
"CWISCore")
205 $DefaultFields[$Field->Id()] = $Field;
210 return $DefaultFields;
213 # ---- OVERRIDDEN METHODS ------------------------------------------------
222 # delete the associated user resource if set
229 return parent::Delete();
238 public function Get($FieldName)
240 # provide backwards-compatibility for data migrated to users fields as
242 if (in_array($FieldName, self::$MigratedUserFields))
244 # return NULL if the resource object isn't set
250 # return the value from the associated resource
254 # otherwise, get it from the APUsers table
255 return parent::Get($FieldName);
264 public function Set($FieldName, $NewValue)
266 # provide backwards-compatibility for data migrated to users fields as
268 if (in_array($FieldName, self::$MigratedUserFields))
270 # set the value only if the resource object is set
278 # transform boolean values to 1 or 0 because that's what the User
280 if (is_bool($NewValue))
282 $NewValue = $NewValue ? 1 : 0;
285 # update the APUsers table
286 return parent::Set($FieldName, $NewValue);
289 # ---- PRIVATE INTERFACE -------------------------------------------------
302 "RealName",
"WebSite",
"AddressLineOne",
"AddressLineTwo",
"City",
303 "State",
"ZipCode",
"Country");
319 # couldn't get the factory or schema, which probably means CWIS hasn't
321 catch (Exception $Exception)
326 # the UserId field doesn't exist, which probably means CWIS hasn't been
328 if (!$Schema->FieldExists(
"UserId"))
333 # get matching resources, which should only be one
334 $Field = $Schema->GetFieldByName(
"UserId");
335 $ResourceIds = $Factory->GetItemIds(
"`".$Field->DBFieldName()
337 $ResourceIdCount = count($ResourceIds);
340 if ($ResourceIdCount < 1)
345 # too many resources found
346 if ($ResourceIdCount > 1)
351 # construct the associated resource and return it
352 return new Resource(array_shift($ResourceIds));
361 # there must be a user ID, which is what the User class assumes, and the
362 # resource must be set
363 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.
HasPriv($Privilege, $Privileges=NULL)
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...