CWIS Developer Documentation
CWUserFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: CWUserFactory.php
4 #
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/
8 #
9 
14 {
15  # ---- PUBLIC INTERFACE --------------------------------------------------
16 
20  public function __construct()
21  {
22  parent::UserFactory();
24  }
25 
34  function GetTopContributors($Limit = 5)
35  {
36  # assume no users will be found
37  $Users = array();
38 
39  # fetch the top contributors
40  $this->DB->Query("SELECT U.*"
41  ." FROM APUsers U, Resources R"
42  ." WHERE U.UserId = R.LastModifiedById"
43  ." GROUP BY R.LastModifiedById"
44  ." ORDER BY COUNT(*) DESC"
45  ." LIMIT ".intval($Limit));
46  $UserIds = $this->DB->FetchColumn("UserId");
47 
48  # for each user id found
49  foreach ($UserIds as $UserId)
50  {
51  $Users[$UserId] = new CWUser($UserId);
52  }
53 
54  # return the newest users
55  return $Users;
56  }
57 
66  function GetMostRecentContributors($Limit = 5)
67  {
68  # assume no users will be found
69  $Users = array();
70 
71  # fetch the top contributors
72  $this->DB->Query("SELECT U.*"
73  ." FROM APUsers U, Resources R"
74  ." WHERE U.UserId = R.LastModifiedById"
75  ." GROUP BY U.UserId"
76  ." ORDER BY MAX(R.DateLastModified) DESC"
77  ." LIMIT ".intval($Limit));
78  $UserIds = $this->DB->FetchColumn("UserId");
79 
80  # for each user id found
81  foreach ($UserIds as $UserId)
82  {
83  $Users[$UserId] = new CWUser($UserId);
84  }
85 
86  # return the newest users
87  return $Users;
88  }
89 
90  # ---- OVERRIDDEN METHODS ------------------------------------------------
91 
104  function CreateNewUser(
105  $UserName, $Password, $PasswordAgain, $EMail, $EMailAgain,
106  $IgnoreErrorCodes = NULL)
107  {
108  # add the user to the APUsers table
109  $User = parent::CreateNewUser(
110  $UserName,
111  $Password,
112  $PasswordAgain,
113  $EMail,
114  $EMailAgain,
115  $IgnoreErrorCodes);
116 
117  # user account creation did not succeed, so return the error codes
118  if (!($User instanceof User))
119  {
120  return $User;
121  }
122 
123  # create the user resource
125 
126  # set the user ID for the resource
127  $Resource->Set("UserId", $User->Id());
128 
130  $TimestampFields = $Schema->GetFields(MetadataSchema::MDFTYPE_TIMESTAMP);
131 
132  # update timestamps as required
133  foreach ($TimestampFields as $Field)
134  {
135  if ($Field->UpdateMethod()
137  {
138  $Resource->Set($Field, "now");
139  }
140  }
141 
142  # make the user resource permanent
143  $Resource->IsTempResource(FALSE);
144 
145  # get the CWUser object for the user
146  $CWUser = new CWUser(intval($User->Id()));
147 
148  # couldn't get the CWUser object
149  if ($CWUser->Status() != U_OKAY)
150  {
151  return array($CWUser->Status());
152  }
153 
154  # return new user object to caller
155  return $CWUser;
156  }
157 
158  # ---- PRIVATE INTERFACE -------------------------------------------------
159 
163  protected $ResourceFactory;
164 
165 }
$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...
Metadata schema (in effect a Factory class for MetadataField).
CWIS-specific user factory class.
const UPDATEMETHOD_ONRECORDEDIT
PHP
Definition: OAIClient.php:39
__construct()
Construct the user factory object.
CreateNewUser($UserName, $Password, $PasswordAgain, $EMail, $EMailAgain, $IgnoreErrorCodes=NULL)
Create a new user.
const U_OKAY
Definition: Axis--User.php:19
static Create($SchemaId)
Create a new resource.
Definition: Resource.php:59
Factory for Resource objects.
CWIS-specific user class.
Definition: CWUser.php:13