22
33namespace BNETDocs \Libraries ;
44
5+ use \BNETDocs \Libraries \Exceptions \QueryException ;
6+ use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
7+ use \BNETDocs \Libraries \User ;
58use \CarlBennett \MVC \Libraries \Common ;
69use \CarlBennett \MVC \Libraries \Database ;
710use \CarlBennett \MVC \Libraries \DatabaseDriver ;
8- use \BNETDocs \Libraries \Exceptions \QueryException ;
9- use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
1011use \InvalidArgumentException ;
1112use \PDO ;
1213use \PDOException ;
@@ -18,13 +19,13 @@ class UserProfile {
1819 protected $ discord_username ;
1920 protected $ facebook_username ;
2021 protected $ github_username ;
21- protected $ id ;
2222 protected $ instagram_username ;
2323 protected $ phone ;
2424 protected $ reddit_username ;
2525 protected $ skype_username ;
2626 protected $ steam_id ;
2727 protected $ twitter_username ;
28+ protected $ user_id ;
2829 protected $ website ;
2930
3031 public function __construct ($ data ) {
@@ -33,13 +34,13 @@ public function __construct($data) {
3334 $ this ->discord_username = null ;
3435 $ this ->facebook_username = null ;
3536 $ this ->github_username = null ;
36- $ this ->id = (int ) $ data ;
3737 $ this ->instagram_username = null ;
3838 $ this ->phone = null ;
3939 $ this ->reddit_username = null ;
4040 $ this ->skype_username = null ;
4141 $ this ->steam_id = null ;
4242 $ this ->twitter_username = null ;
43+ $ this ->user_id = (int ) $ data ;
4344 $ this ->website = null ;
4445 $ this ->refresh ();
4546 } else if ($ data instanceof StdClass) {
@@ -48,13 +49,13 @@ public function __construct($data) {
4849 $ this ->discord_username = $ data ->discord_username ;
4950 $ this ->facebook_username = $ data ->facebook_username ;
5051 $ this ->github_username = $ data ->github_username ;
51- $ this ->id = $ data ->id ;
5252 $ this ->instagram_username = $ data ->instagram_username ;
5353 $ this ->phone = $ data ->phone ;
5454 $ this ->reddit_username = $ data ->reddit_username ;
5555 $ this ->skype_username = $ data ->skype_username ;
5656 $ this ->steam_id = $ data ->steam_id ;
5757 $ this ->twitter_username = $ data ->twitter_username ;
58+ $ this ->user_id = $ data ->user_id ;
5859 $ this ->website = $ data ->website ;
5960 } else {
6061 throw new InvalidArgumentException ("Cannot use data argument " );
@@ -85,10 +86,6 @@ public function getGitHubUsername() {
8586 return $ this ->github_username ;
8687 }
8788
88- public function getId () {
89- return $ this ->id ;
90- }
91-
9289 public function getInstagramURI () {
9390 return "https://instagram.com/ " . $ this ->getInstagramUsername ();
9491 }
@@ -142,6 +139,14 @@ public function getTwitterUsername() {
142139 return $ this ->twitter_username ;
143140 }
144141
142+ public function getUser () {
143+ return new User ($ this ->user_id );
144+ }
145+
146+ public function getUserId () {
147+ return $ this ->user_id ;
148+ }
149+
145150 public function getWebsite ($ clean = true ) {
146151 if (!is_string ($ this ->website ) || !$ clean ) return $ this ->website ;
147152 $ value = strtolower ($ this ->website );
@@ -205,7 +210,7 @@ protected static function normalize(StdClass &$data) {
205210 }
206211
207212 public function refresh () {
208- $ cache_key = "bnetdocs-userprofile- " . $ this ->id ;
213+ $ cache_key = "bnetdocs-userprofile- " . $ this ->user_id ;
209214 $ cache_val = Common::$ cache ->get ($ cache_key );
210215 if ($ cache_val !== false ) {
211216 $ cache_val = unserialize ($ cache_val );
@@ -244,11 +249,11 @@ public function refresh() {
244249 WHERE `user_id` = :id
245250 LIMIT 1;
246251 " );
247- $ stmt ->bindParam (":id " , $ this ->id , PDO ::PARAM_INT );
252+ $ stmt ->bindParam (":id " , $ this ->user_id , PDO ::PARAM_INT );
248253 if (!$ stmt ->execute ()) {
249254 throw new QueryException ("Cannot refresh user profile " );
250255 } else if ($ stmt ->rowCount () == 0 ) {
251- throw new UserProfileNotFoundException ($ this ->id );
256+ throw new UserProfileNotFoundException ($ this ->user_id );
252257 }
253258 $ row = $ stmt ->fetch (PDO ::FETCH_OBJ );
254259 $ stmt ->closeCursor ();
@@ -322,14 +327,13 @@ public function save() {
322327 $ stmt ->bindParam (':discord ' , $ this ->discord_username , PDO ::PARAM_STR );
323328 $ stmt ->bindParam (':fb ' , $ this ->facebook_username , PDO ::PARAM_STR );
324329 $ stmt ->bindParam (':github ' , $ this ->github_username , PDO ::PARAM_STR );
325- $ stmt ->bindParam (':id ' , $ this ->id , PDO ::PARAM_INT );
326330 $ stmt ->bindParam (':ig ' , $ this ->instagram_username , PDO ::PARAM_STR );
327331 $ stmt ->bindParam (':ph ' , $ this ->phone , PDO ::PARAM_STR );
328332 $ stmt ->bindParam (':reddit ' , $ this ->reddit_username , PDO ::PARAM_STR );
329333 $ stmt ->bindParam (':skype ' , $ this ->skype_username , PDO ::PARAM_STR );
330334 $ stmt ->bindParam (':steam ' , $ this ->steam_id , PDO ::PARAM_STR );
331335 $ 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 );
333337 $ stmt ->bindParam (':website ' , $ this ->website , PDO ::PARAM_STR );
334338 if (!$ stmt ->execute ()) {
335339 throw new QueryException ('Cannot save user profile ' );
@@ -341,18 +345,18 @@ public function save() {
341345 $ object ->discord_username = $ this ->discord_username ;
342346 $ object ->facebook_username = $ this ->facebook_username ;
343347 $ object ->github_username = $ this ->github_username ;
344- $ object ->id = $ this ->id ;
345348 $ object ->instagram_username = $ this ->instagram_username ;
346349 $ object ->phone = $ this ->phone ;
347350 $ object ->reddit_username = $ this ->reddit_username ;
348351 $ object ->skype_username = $ this ->skype_username ;
349352 $ object ->steam_id = $ this ->steam_id ;
350353 $ object ->twitter_username = $ this ->twitter_username ;
354+ $ object ->user_id = $ this ->user_id ;
351355 $ object ->website = $ this ->website ;
352356
353357 self ::normalize ($ object );
354358
355- $ cache_key = 'bnetdocs-userprofile- ' . $ this ->id ;
359+ $ cache_key = 'bnetdocs-userprofile- ' . $ this ->user_id ;
356360 Common::$ cache ->set ($ cache_key , serialize ($ object ), 300 );
357361
358362 return true ;
0 commit comments