CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
13 class CWUserFactory extends UserFactory
14 {
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
20 public function __construct()
21 {
22 parent::UserFactory();
23 $this->ResourceFactory = new ResourceFactory(MetadataSchema::SCHEMAID_USER);
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
124 $Resource = Resource::Create(MetadataSchema::SCHEMAID_USER);
125
126 # set the user ID for the resource
127 $Resource->Set("UserId", $User->Id());
128
129 $Schema = new MetadataSchema(MetadataSchema::SCHEMAID_USER);
130 $TimestampFields = $Schema->GetFields(MetadataSchema::MDFTYPE_TIMESTAMP);
131
132 # update timestamps as required
133 foreach ($TimestampFields as $Field)
134 {
135 if ($Field->UpdateMethod()
136 == MetadataField::UPDATEMETHOD_ONRECORDEDIT)
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 }
MetadataSchema\MDFTYPE_TIMESTAMP
const MDFTYPE_TIMESTAMP
Definition: MetadataSchema.php:24
CWUserFactory\$ResourceFactory
$ResourceFactory
The resource factory for user resources.
Definition: CWUserFactory.php:163
CWUserFactory\GetTopContributors
GetTopContributors($Limit=5)
Get a list of users sorted by how many resources they have added or edited, starting with those who h...
Definition: CWUserFactory.php:34
CWUserFactory\GetMostRecentContributors
GetMostRecentContributors($Limit=5)
Get the users sorted by when they last added or edited a resource starting with those who added/edite...
Definition: CWUserFactory.php:66
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
MetadataSchema\SCHEMAID_USER
const SCHEMAID_USER
Definition: MetadataSchema.php:53
User
Definition: Axis--User.php:43
CWUserFactory
CWIS-specific user factory class.
Definition: CWUserFactory.php:13
MetadataField\UPDATEMETHOD_ONRECORDEDIT
const UPDATEMETHOD_ONRECORDEDIT
Definition: MetadataField.php:21
CWUserFactory\__construct
__construct()
Construct the user factory object.
Definition: CWUserFactory.php:20
PHP
PHP
Definition: RSSClient--Test.php:12
UserFactory
Definition: Axis--UserFactory.php:18
CWUserFactory\CreateNewUser
CreateNewUser($UserName, $Password, $PasswordAgain, $EMail, $EMailAgain, $IgnoreErrorCodes=NULL)
Create a new user.
Definition: CWUserFactory.php:104
U_OKAY
const U_OKAY
Definition: Axis--User.php:19
Resource\Create
static Create($SchemaId)
Create a new resource.
Definition: Resource.php:60
ResourceFactory
Factory for Resource objects.
Definition: ResourceFactory.php:13
CWUser
CWIS-specific user class.
Definition: CWUser.php:13