1- <?php
2-
1+ <?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
32namespace BNETDocs \Controllers \User ;
43
54use \BNETDocs \Libraries \Credits ;
65use \BNETDocs \Libraries \Document ;
76use \BNETDocs \Libraries \Exceptions \UserNotFoundException ;
8- use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
97use \BNETDocs \Libraries \NewsPost ;
108use \BNETDocs \Libraries \Packet ;
119use \BNETDocs \Libraries \Server ;
12- use \BNETDocs \Libraries \User as UserLib ;
13- use \BNETDocs \Libraries \UserProfile ;
14-
10+ use \BNETDocs \Libraries \User ;
1511use \BNETDocs \Models \User \View as UserViewModel ;
16-
1712use \CarlBennett \MVC \Libraries \Common ;
1813use \CarlBennett \MVC \Libraries \Controller ;
1914use \CarlBennett \MVC \Libraries \Router ;
2015use \CarlBennett \MVC \Libraries \View as ViewLib ;
21-
2216use \DateTime ;
23- use \DateTimeZone ;
2417
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 ();
2823 $ model ->user_id = array_shift ($ args );
2924
3025 $ this ->getUserInfo ($ model );
@@ -34,73 +29,22 @@ public function &run(Router &$router, ViewLib &$view, array &$args) {
3429 return $ model ;
3530 }
3631
37- protected function getUserInfo (UserViewModel &$ model ) {
38-
32+ protected function getUserInfo (UserViewModel &$ model )
33+ {
3934 // 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+ {
4341 $ model ->user = null ;
4442 return ;
4543 }
4644
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-
9545 // 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 , ', ' )));
10448
10549 // Summary of contributions
10650 $ model ->sum_documents = Credits::getTotalDocumentsByUserId (
@@ -124,16 +68,16 @@ protected function getUserInfo(UserViewModel &$model) {
12468 $ model ->contributions += $ model ->sum_servers ;
12569
12670 // References to the contributions
127- $ model ->documents = ($ model ->sum_documents ?
71+ $ model ->documents = ($ model ->sum_documents ?
12872 Document::getDocumentsByUserId ($ model ->user_id ) : null
12973 );
13074 $ model ->news_posts = ($ model ->sum_news_posts ?
13175 NewsPost::getNewsPostsByUserId ($ model ->user_id ): null
13276 );
133- $ model ->packets = ($ model ->sum_packets ?
77+ $ model ->packets = ($ model ->sum_packets ?
13478 Packet::getPacketsByUserId ($ model ->user_id ) : null
13579 );
136- $ model ->servers = ($ model ->sum_servers ?
80+ $ model ->servers = ($ model ->sum_servers ?
13781 Server::getServersByUserId ($ model ->user_id ) : null
13882 );
13983
0 commit comments