1
- <?php
2
-
1
+ <?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
3
2
namespace BNETDocs \Controllers \User ;
4
3
5
4
use \BNETDocs \Libraries \Credits ;
6
5
use \BNETDocs \Libraries \Document ;
7
6
use \BNETDocs \Libraries \Exceptions \UserNotFoundException ;
8
- use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
9
7
use \BNETDocs \Libraries \NewsPost ;
10
8
use \BNETDocs \Libraries \Packet ;
11
9
use \BNETDocs \Libraries \Server ;
12
- use \BNETDocs \Libraries \User as UserLib ;
13
- use \BNETDocs \Libraries \UserProfile ;
14
-
10
+ use \BNETDocs \Libraries \User ;
15
11
use \BNETDocs \Models \User \View as UserViewModel ;
16
-
17
12
use \CarlBennett \MVC \Libraries \Common ;
18
13
use \CarlBennett \MVC \Libraries \Controller ;
19
14
use \CarlBennett \MVC \Libraries \Router ;
20
15
use \CarlBennett \MVC \Libraries \View as ViewLib ;
21
-
22
16
use \DateTime ;
23
- use \DateTimeZone ;
24
17
25
- class View extends Controller {
26
- public function &run (Router &$ router , ViewLib &$ view , array &$ args ) {
27
- $ model = new UserViewModel ();
18
+ class View extends Controller
19
+ {
20
+ public function &run (Router &$ router , ViewLib &$ view , array &$ args )
21
+ {
22
+ $ model = new UserViewModel ();
28
23
$ model ->user_id = array_shift ($ args );
29
24
30
25
$ this ->getUserInfo ($ model );
@@ -34,73 +29,22 @@ public function &run(Router &$router, ViewLib &$view, array &$args) {
34
29
return $ model ;
35
30
}
36
31
37
- protected function getUserInfo (UserViewModel &$ model ) {
38
-
32
+ protected function getUserInfo (UserViewModel &$ model )
33
+ {
39
34
// Try to get the user
40
- try {
41
- $ model ->user = new UserLib ($ model ->user_id );
42
- } catch (UserNotFoundException $ e ) {
35
+ try
36
+ {
37
+ $ model ->user = new User ($ model ->user_id );
38
+ }
39
+ catch (UserNotFoundException $ e )
40
+ {
43
41
$ model ->user = null ;
44
42
return ;
45
43
}
46
44
47
- // Try to get their user profile
48
- try {
49
-
50
- $ model ->user_profile = new UserProfile ($ model ->user_id );
51
-
52
- $ model ->biography = $ model ->user_profile ->getBiography ();
53
-
54
- $ model ->discord = $ model ->user_profile ->getDiscordUsername ();
55
-
56
- $ model ->facebook = $ model ->user_profile ->getFacebookUsername ();
57
- $ model ->facebook_uri = $ model ->user_profile ->getFacebookURI ();
58
-
59
- $ model ->github = $ model ->user_profile ->getGitHubUsername ();
60
- $ model ->github_uri = $ model ->user_profile ->getGitHubURI ();
61
-
62
- $ model ->instagram = $ model ->user_profile ->getInstagramUsername ();
63
- $ model ->instagram_uri = $ model ->user_profile ->getInstagramURI ();
64
-
65
- $ model ->phone = $ model ->user_profile ->getPhone ();
66
- $ model ->phone_uri = $ model ->user_profile ->getPhoneURI ();
67
-
68
- $ model ->reddit = $ model ->user_profile ->getRedditUsername ();
69
- $ model ->reddit_uri = $ model ->user_profile ->getRedditURI ();
70
-
71
- $ model ->skype = $ model ->user_profile ->getSkypeUsername ();
72
- $ model ->skype_uri = $ model ->user_profile ->getSkypeURI ();
73
-
74
- $ model ->steam_id = $ model ->user_profile ->getSteamId ();
75
- $ model ->steam_uri = $ model ->user_profile ->getSteamURI ();
76
-
77
- $ model ->twitter = $ model ->user_profile ->getTwitterUsername ();
78
- $ model ->twitter_uri = $ model ->user_profile ->getTwitterURI ();
79
-
80
- $ model ->website = $ model ->user_profile ->getWebsite ();
81
- $ model ->website_uri = $ model ->user_profile ->getWebsiteURI ();
82
-
83
- } catch (UserProfileNotFoundException $ e ) {
84
- // Not a problem
85
- }
86
-
87
- // Should we display profile data at all?
88
- $ model ->profiledata = (
89
- $ model ->discord || $ model ->facebook || $ model ->github ||
90
- $ model ->instagram || $ model ->phone || $ model ->reddit ||
91
- $ model ->skype || $ model ->steam_id || $ model ->twitter ||
92
- $ model ->website
93
- );
94
-
95
45
// How long have they been a member?
96
- $ model ->user_est = Common::intervalToString (
97
- $ model ->user ->getCreatedDateTime ()->diff (
98
- new DateTime ( 'now ' , new DateTimeZone ( 'Etc/UTC ' ))
99
- )
100
- );
101
- $ user_est_comma = strpos ($ model ->user_est , ', ' );
102
- if ($ user_est_comma !== false )
103
- $ model ->user_est = substr ($ model ->user_est , 0 , $ user_est_comma );
46
+ $ model ->user_est = Common::intervalToString ($ model ->user ->getCreatedDateTime ()->diff (new DateTime ('now ' )));
47
+ $ model ->user_est = substr ($ model ->user_est , 0 , min (strlen ($ model ->user_est ), strpos ($ model ->user_est , ', ' )));
104
48
105
49
// Summary of contributions
106
50
$ model ->sum_documents = Credits::getTotalDocumentsByUserId (
@@ -124,16 +68,16 @@ protected function getUserInfo(UserViewModel &$model) {
124
68
$ model ->contributions += $ model ->sum_servers ;
125
69
126
70
// References to the contributions
127
- $ model ->documents = ($ model ->sum_documents ?
71
+ $ model ->documents = ($ model ->sum_documents ?
128
72
Document::getDocumentsByUserId ($ model ->user_id ) : null
129
73
);
130
74
$ model ->news_posts = ($ model ->sum_news_posts ?
131
75
NewsPost::getNewsPostsByUserId ($ model ->user_id ): null
132
76
);
133
- $ model ->packets = ($ model ->sum_packets ?
77
+ $ model ->packets = ($ model ->sum_packets ?
134
78
Packet::getPacketsByUserId ($ model ->user_id ) : null
135
79
);
136
- $ model ->servers = ($ model ->sum_servers ?
80
+ $ model ->servers = ($ model ->sum_servers ?
137
81
Server::getServersByUserId ($ model ->user_id ) : null
138
82
);
139
83
0 commit comments