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/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 24 static $EmailWrapperSet = FALSE;
25 if (!$EmailWrapperSet)
28 $EmailWrapperSet = TRUE;
31 parent::__construct($UserInfo);
33 if ($this->Result !==
U_OKAY)
36 "Unable to load user information.");
39 # try to fetch the associated resource if the user was found 42 $Resource = $this->FetchAssociatedResource($this->UserId);
44 # the associated resource was successfully found 49 # there was a problem finding the resource 53 "Unable to load corresponding resource for user.");
70 public function Login($UserName, $Password, $IgnorePassword = FALSE)
72 parent::Login($UserName, $Password, $IgnorePassword);
74 if ($this->Result ==
U_OKAY)
76 $Resource = $this->FetchAssociatedResource($this->UserId);
78 # the associated resource was successfully found 83 # there was a problem finding the resource 87 "Unable to load corresponding resource for user.");
112 if ($NewValue !== NULL)
115 "Attempt to set user privileges with CWUser::Privileges(), " 116 .
"which is no longer supported");
154 public function HasPriv($Privilege, $Privileges = NULL)
158 if ($Privileges instanceof
Resource)
160 return $Privilege->MeetsRequirements($this, $Privileges);
164 return $Privilege->MeetsRequirements($this);
169 return call_user_func_array(
"parent::HasPriv", func_get_args() );
183 public static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
185 # extract "From" address from supplied headers if available 186 if (strlen($AdditionalHeaders))
188 $HeaderLines = explode(
"\n", $AdditionalHeaders);
190 foreach ($HeaderLines as $Line)
192 $HeaderLine = trim($Line);
193 if (preg_match(
"/^from:/i", $Line))
195 $From = preg_replace(
"/^from:/i",
"", $Line);
199 $Headers[] = $HeaderLine;
206 if (isset($From)) { $Msg->From($From); }
208 $Msg->Subject($Subject);
209 $Msg->AddHeaders($Headers);
210 $Msg->Body($Message);
213 # report success to caller 223 static $CustomFields;
225 if (!isset($CustomFields))
227 $CustomFields = array();
230 foreach ($Schema->GetFields() as $Field)
232 # they're custom if not owned by CWIS 233 if ($Field->Owner() !=
"CWISCore")
235 $CustomFields[$Field->Id()] = $Field;
240 return $CustomFields;
249 static $DefaultFields;
251 if (!isset($DefaultFields))
253 $DefaultFields = array();
256 foreach ($Schema->GetFields() as $Field)
258 # they're default if owned by CWIS 259 if ($Field->Owner() ==
"CWISCore")
261 $DefaultFields[$Field->Id()] = $Field;
266 return $DefaultFields;
269 # ---- OVERRIDDEN METHODS ------------------------------------------------ 278 # delete the associated user resource if set 285 return parent::Delete();
294 public function Get($FieldName)
296 # all values are NULL for anonymous users 302 if (in_array($FieldName, self::$FieldsOnlyInAPUsers))
304 return parent::Get($FieldName);
318 public function Set($Field, $NewValue)
323 "Attempt to set User field value when " 324 .
"no user is logged in.");
327 # make sure Field is a FieldName 330 $Field = $Field->Name();
333 # if this field is not among those that should only exists in 335 if (!in_array($Field, self::$FieldsOnlyInAPUsers))
337 # set it in our corresponding resource 341 # if the given field exists in the APUsers table, update that too 342 if ($this->DB->FieldExists(
"APUsers", $Field))
344 parent::Set($Field, $NewValue);
348 # indicate success for fields that don't have a column in APUsers 355 # ---- PRIVATE INTERFACE ------------------------------------------------- 363 # list of fields that exist in APUsers that are not mirrored as MetadataFields 364 private static $FieldsOnlyInAPUsers = [
365 # fields necessary to for user identification 366 "UserId",
"UserName",
"EMail",
"EMailNew",
368 # fields necessary for authentication 369 "UserPassword",
"RegistrationConfirmed",
371 # fields that can't be in a schema because they are updated by User 372 "LastLoginDate",
"LastActiveDate",
"LastIPAddress",
"LastLocation",
"LoggedIn",
375 "ActiveUI",
"BrowsingFieldId",
"RecordsPerPage",
"SearchSelections",
384 protected function FetchAssociatedResource(
$UserId)
386 if (self::$UserIdFieldId === NULL)
388 # get the user schema 391 # pull out the UserId field, which should only be one 392 $Field = $Schema->GetField(
"UserId");
394 # and get its FieldId 395 self::$UserIdFieldId = intval($Field->Id());
398 # find the matching Resources (should only be one) 400 "SELECT ResourceId FROM ResourceUserInts WHERE ".
401 "FieldId=".self::$UserIdFieldId.
402 " AND UserId=".intval(
$UserId) );
403 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
404 $ResourceIdCount = count($ResourceIds);
407 if ($ResourceIdCount < 1)
412 # too many resources found 413 if ($ResourceIdCount > 1)
416 "Multiple resources exist for a single user, " 417 .
"which should be impossible");
420 # construct the associated resource and return it 421 return new Resource(array_shift($ResourceIds));
425 # ---- MAINTAINED FOR BACKWARD COMPATIBILITY IN INTERFACES (BEGIN) 427 # ---- user interface preference mnemonics 428 # color avoidance flags 429 const UIPREF_AVOID_RED = 1;
430 const UIPREF_AVOID_REDGREEN = 2;
431 const UIPREF_AVOID_BLUEYELLOW = 4;
432 const UIPREF_AVOID_GREENYELLOW = 8;
433 const UIPREF_AVOID_ORANGE = 16;
434 const UIPREF_AVOID_REDBLACK = 32;
435 const UIPREF_AVOID_PURPLEGREY = 64;
436 const UIPREF_AVOID_USEMAXMONOCHR = 128;
438 # content display options 439 const UIPREF_CONTENTDENSITY_NOPREFERENCE = 0;
440 const UIPREF_CONTENTDENSITY_DETAILED = 1;
441 const UIPREF_CONTENTDENSITY_OVERVIEW = 2;
443 # content view options 444 const UIPREF_CONTENTVIEW_NOPREFERENCE = 0;
445 const UIPREF_CONTENTVIEW_TEXTINTENSIVE = 1;
446 const UIPREF_CONTENTVIEW_IMAGEINTENSIVE = 2;
448 # audio description options 449 const UIPREF_AUDIODESCRIPTION_NONE = 0;
450 const UIPREF_AUDIODESCRIPTION_STANDARD = 1;
451 const UIPREF_AUDIODESCRIPTION_EXPANDED = 2;
453 # caption type options 454 const UIPREF_CAPTIONTYPE_NONE = 0;
455 const UIPREF_CAPTIONTYPE_VERBATIM = 1;
456 const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL = 2;
460 # user interface / accessibility preferences 464 function PrefFontTypeFace($NewValue =
DB_NOVALUE)
467 function PrefFontColor($NewValue =
DB_NOVALUE)
470 function PrefBackgroundColor($NewValue =
DB_NOVALUE)
473 function PrefColorAvoidanceFlags($NewValue =
DB_NOVALUE)
476 function PrefContentDensity($NewValue =
DB_NOVALUE)
479 function PrefContentView($NewValue =
DB_NOVALUE)
482 function PrefAudioDescriptionLevel($NewValue =
DB_NOVALUE)
485 function PrefAudioDescriptionLanguage($NewValue =
DB_NOVALUE)
488 function PrefVisualDescriptionLanguage($NewValue =
DB_NOVALUE)
491 function PrefImageDescriptionLanguage($NewValue =
DB_NOVALUE)
494 function PrefUseGraphicAlternatives($NewValue =
DB_NOVALUE)
497 function PrefSignLanguage($NewValue =
DB_NOVALUE)
500 function PrefCaptionType($NewValue =
DB_NOVALUE)
503 function PrefCaptionRate($NewValue =
DB_NOVALUE)
507 # ---- MAINTAINED FOR BACKWARD COMPATIBILITY IN INTERFACES (END) 509 private static $UserIdFieldId = NULL;
$Resource
The user resource associated with the user or NULL if the user isn't logged in.
Privileges(PrivilegeSet $NewValue=NULL)
THIS FUNCTION HAS BEEN DEPRECATED This provides compatibility for interfaces written to use a version...
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.
HasPriv($Privilege, $Privileges=NULL)
Determine if a user has a given privilege, or satisfies the conditions specified by a given privilege...
Get($FieldName)
Get a value from the specified field.
Set($Field, $NewValue)
Set a value for the specified field.
Set of privileges used to access resource information or other parts of the system.
Login($UserName, $Password, $IgnorePassword=FALSE)
Log the specified user in and associate the underlying Resource with this CWUser. ...
Get($Field, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field name or field object.
__construct($UserInfo=NULL)
Load user data from the given user info or from the session if available.
IsAnonymous()
Report whether user is anonymous user.
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().
Compatibility layer allowing interfaces built against the privilege system from CWIS 3...
Represents a "resource" in CWIS.
static GetDefaultUserFields()
Get the default user fields.
static GetCustomUserFields()
Get all custom user fields.
Set($Field, $NewValue, $Reset=FALSE)
Set value using field name or field object.
GetResource()
Get the associated user resource for this user.
CWIS-specific user class.
Logout()
Log this user out and disassociate their underlying Resource from this CWUser.
Delete()
Remove resource (and accompanying associations) from database and delete any associated files...