3 # FILE: CWUserFactory.php 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 -------------------------------------------------- 22 parent::__construct();
36 # assume no users will be found 40 $LastModField = $Schema->GetFieldByName(
"Last Modified By Id");
42 # fetch the top contributors 44 "SELECT UserId FROM ResourceUserInts " 45 .
" WHERE FieldId = ".$LastModField->Id()
47 .
" ORDER BY COUNT(*) DESC" 48 .
" LIMIT ".intval($Limit));
49 $UserIds = $this->DB->FetchColumn(
"UserId");
51 # for each user id found 52 foreach ($UserIds as $UserId)
54 $Users[$UserId] =
new CWUser($UserId);
57 # return the newest users 71 # assume no users will be found 75 $LastModField = $Schema->GetFieldByName(
"Last Modified By Id");
77 # fetch the top contributors 79 "SELECT UserId FROM ResourceUserInts RU, Resources R " 80 .
" WHERE RU.FieldId = ".$LastModField->Id()
81 .
" AND R.ResourceId = RU.ResourceId " 82 .
" GROUP BY RU.UserId" 83 .
" ORDER BY MAX(R.DateLastModified) DESC" 84 .
" LIMIT ".intval($Limit));
85 $UserIds = $this->DB->FetchColumn(
"UserId");
87 # for each user id found 88 foreach ($UserIds as $UserId)
90 $Users[$UserId] =
new CWUser($UserId);
93 # return the newest users 104 $TrialName = explode(
'@', $Email);
105 $TrialName = array_shift($TrialName);
106 $TrialName = preg_replace(
"/[^A-Za-z0-9]/",
"", $TrialName);
107 $TrialName = strtolower($TrialName);
109 # if this email address is very short, we'll pad it with some random 111 if (strlen($TrialName) < 2)
113 $TrialName .= GetRandomCharacters(2,
"/[^a-hj-np-z0-9]/");
116 # see if the specified name exists 119 $Name = self::AppendSuffix($TrialName,
'');
121 while ($UFactory->UserNameExists($Name))
123 $Name = self::AppendSuffix(
124 $TrialName, GetRandomCharacters(2) );
130 # ---- OVERRIDDEN METHODS ------------------------------------------------ 145 $UserName, $Password, $PasswordAgain, $EMail, $EMailAgain,
146 $IgnoreErrorCodes = NULL)
148 # add the user to the APUsers table 149 $User = parent::CreateNewUser(
157 # user account creation did not succeed, so return the error codes 158 if (!($User instanceof
User))
163 # create the user resource 166 # set the user ID for the resource 167 $Resource->Set(
"UserId", $User->Id());
172 # update timestamps as required 173 foreach ($TimestampFields as $Field)
175 if ($Field->UpdateMethod()
178 $Resource->Set($Field,
"now");
182 # make the user resource permanent 183 $Resource->IsTempResource(FALSE);
185 # get the CWUser object for the user 186 $CWUser =
new CWUser(intval($User->Id()));
188 # couldn't get the CWUser object 189 if ($CWUser->Status() !=
U_OKAY)
191 return array($CWUser->Status());
194 # set up initial UI setting 195 $CWUser->Set(
"ActiveUI",
196 $GLOBALS[
"G_SysConfig"]->DefaultActiveUI());
198 # set up initial privileges 199 foreach ($GLOBALS[
"G_SysConfig"]->DefaultUserPrivs() as $Privilege)
201 $CWUser->GivePriv($Privilege);
204 # return new user object to caller 208 # ---- PRIVATE INTERFACE ------------------------------------------------- 219 private static function AppendSuffix($TrialName, $Suffix, $MaxLength=24)
221 if (strlen($TrialName.$Suffix)>$MaxLength)
224 $TrialName, 0, $MaxLength - strlen($Suffix));
227 return $TrialName.$Suffix;
$ResourceFactory
The resource factory for user resources.
GetTopContributors($Limit=5)
Get a list of users sorted by how many resources they have added or edited, starting with those who h...
GetMostRecentContributors($Limit=5)
Get the users sorted by when they last added or edited a resource starting with those who added/edite...
CWIS-specific user factory class.
__construct()
Construct the user factory object.
CreateNewUser($UserName, $Password, $PasswordAgain, $EMail, $EMailAgain, $IgnoreErrorCodes=NULL)
Create a new user.
static GenerateUniqueUsernameFromEmail($Email)
Derive a unique username from an email address.
static Create($SchemaId)
Create a new resource.
Factory for Resource objects.
CWIS-specific user class.