2
2
3
3
namespace BNETDocs \Libraries ;
4
4
5
+ use \BNETDocs \Libraries \Exceptions \QueryException ;
6
+ use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
7
+ use \BNETDocs \Libraries \User ;
5
8
use \CarlBennett \MVC \Libraries \Common ;
6
9
use \CarlBennett \MVC \Libraries \Database ;
7
10
use \CarlBennett \MVC \Libraries \DatabaseDriver ;
8
- use \BNETDocs \Libraries \Exceptions \QueryException ;
9
- use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
10
11
use \InvalidArgumentException ;
11
12
use \PDO ;
12
13
use \PDOException ;
@@ -18,13 +19,13 @@ class UserProfile {
18
19
protected $ discord_username ;
19
20
protected $ facebook_username ;
20
21
protected $ github_username ;
21
- protected $ id ;
22
22
protected $ instagram_username ;
23
23
protected $ phone ;
24
24
protected $ reddit_username ;
25
25
protected $ skype_username ;
26
26
protected $ steam_id ;
27
27
protected $ twitter_username ;
28
+ protected $ user_id ;
28
29
protected $ website ;
29
30
30
31
public function __construct ($ data ) {
@@ -33,13 +34,13 @@ public function __construct($data) {
33
34
$ this ->discord_username = null ;
34
35
$ this ->facebook_username = null ;
35
36
$ this ->github_username = null ;
36
- $ this ->id = (int ) $ data ;
37
37
$ this ->instagram_username = null ;
38
38
$ this ->phone = null ;
39
39
$ this ->reddit_username = null ;
40
40
$ this ->skype_username = null ;
41
41
$ this ->steam_id = null ;
42
42
$ this ->twitter_username = null ;
43
+ $ this ->user_id = (int ) $ data ;
43
44
$ this ->website = null ;
44
45
$ this ->refresh ();
45
46
} else if ($ data instanceof StdClass) {
@@ -48,13 +49,13 @@ public function __construct($data) {
48
49
$ this ->discord_username = $ data ->discord_username ;
49
50
$ this ->facebook_username = $ data ->facebook_username ;
50
51
$ this ->github_username = $ data ->github_username ;
51
- $ this ->id = $ data ->id ;
52
52
$ this ->instagram_username = $ data ->instagram_username ;
53
53
$ this ->phone = $ data ->phone ;
54
54
$ this ->reddit_username = $ data ->reddit_username ;
55
55
$ this ->skype_username = $ data ->skype_username ;
56
56
$ this ->steam_id = $ data ->steam_id ;
57
57
$ this ->twitter_username = $ data ->twitter_username ;
58
+ $ this ->user_id = $ data ->user_id ;
58
59
$ this ->website = $ data ->website ;
59
60
} else {
60
61
throw new InvalidArgumentException ("Cannot use data argument " );
@@ -85,10 +86,6 @@ public function getGitHubUsername() {
85
86
return $ this ->github_username ;
86
87
}
87
88
88
- public function getId () {
89
- return $ this ->id ;
90
- }
91
-
92
89
public function getInstagramURI () {
93
90
return "https://instagram.com/ " . $ this ->getInstagramUsername ();
94
91
}
@@ -142,6 +139,14 @@ public function getTwitterUsername() {
142
139
return $ this ->twitter_username ;
143
140
}
144
141
142
+ public function getUser () {
143
+ return new User ($ this ->user_id );
144
+ }
145
+
146
+ public function getUserId () {
147
+ return $ this ->user_id ;
148
+ }
149
+
145
150
public function getWebsite ($ clean = true ) {
146
151
if (!is_string ($ this ->website ) || !$ clean ) return $ this ->website ;
147
152
$ value = strtolower ($ this ->website );
@@ -205,7 +210,7 @@ protected static function normalize(StdClass &$data) {
205
210
}
206
211
207
212
public function refresh () {
208
- $ cache_key = "bnetdocs-userprofile- " . $ this ->id ;
213
+ $ cache_key = "bnetdocs-userprofile- " . $ this ->user_id ;
209
214
$ cache_val = Common::$ cache ->get ($ cache_key );
210
215
if ($ cache_val !== false ) {
211
216
$ cache_val = unserialize ($ cache_val );
@@ -244,11 +249,11 @@ public function refresh() {
244
249
WHERE `user_id` = :id
245
250
LIMIT 1;
246
251
" );
247
- $ stmt ->bindParam (":id " , $ this ->id , PDO ::PARAM_INT );
252
+ $ stmt ->bindParam (":id " , $ this ->user_id , PDO ::PARAM_INT );
248
253
if (!$ stmt ->execute ()) {
249
254
throw new QueryException ("Cannot refresh user profile " );
250
255
} else if ($ stmt ->rowCount () == 0 ) {
251
- throw new UserProfileNotFoundException ($ this ->id );
256
+ throw new UserProfileNotFoundException ($ this ->user_id );
252
257
}
253
258
$ row = $ stmt ->fetch (PDO ::FETCH_OBJ );
254
259
$ stmt ->closeCursor ();
@@ -322,14 +327,13 @@ public function save() {
322
327
$ stmt ->bindParam (':discord ' , $ this ->discord_username , PDO ::PARAM_STR );
323
328
$ stmt ->bindParam (':fb ' , $ this ->facebook_username , PDO ::PARAM_STR );
324
329
$ stmt ->bindParam (':github ' , $ this ->github_username , PDO ::PARAM_STR );
325
- $ stmt ->bindParam (':id ' , $ this ->id , PDO ::PARAM_INT );
326
330
$ stmt ->bindParam (':ig ' , $ this ->instagram_username , PDO ::PARAM_STR );
327
331
$ stmt ->bindParam (':ph ' , $ this ->phone , PDO ::PARAM_STR );
328
332
$ stmt ->bindParam (':reddit ' , $ this ->reddit_username , PDO ::PARAM_STR );
329
333
$ stmt ->bindParam (':skype ' , $ this ->skype_username , PDO ::PARAM_STR );
330
334
$ stmt ->bindParam (':steam ' , $ this ->steam_id , PDO ::PARAM_STR );
331
335
$ stmt ->bindParam (':twitter ' , $ this ->twitter_username , PDO ::PARAM_STR );
332
- $ stmt ->bindParam (':user_id ' , $ this ->id , PDO ::PARAM_INT );
336
+ $ stmt ->bindParam (':user_id ' , $ this ->user_id , PDO ::PARAM_INT );
333
337
$ stmt ->bindParam (':website ' , $ this ->website , PDO ::PARAM_STR );
334
338
if (!$ stmt ->execute ()) {
335
339
throw new QueryException ('Cannot save user profile ' );
@@ -341,18 +345,18 @@ public function save() {
341
345
$ object ->discord_username = $ this ->discord_username ;
342
346
$ object ->facebook_username = $ this ->facebook_username ;
343
347
$ object ->github_username = $ this ->github_username ;
344
- $ object ->id = $ this ->id ;
345
348
$ object ->instagram_username = $ this ->instagram_username ;
346
349
$ object ->phone = $ this ->phone ;
347
350
$ object ->reddit_username = $ this ->reddit_username ;
348
351
$ object ->skype_username = $ this ->skype_username ;
349
352
$ object ->steam_id = $ this ->steam_id ;
350
353
$ object ->twitter_username = $ this ->twitter_username ;
354
+ $ object ->user_id = $ this ->user_id ;
351
355
$ object ->website = $ this ->website ;
352
356
353
357
self ::normalize ($ object );
354
358
355
- $ cache_key = 'bnetdocs-userprofile- ' . $ this ->id ;
359
+ $ cache_key = 'bnetdocs-userprofile- ' . $ this ->user_id ;
356
360
Common::$ cache ->set ($ cache_key , serialize ($ object ), 300 );
357
361
358
362
return true ;
0 commit comments