77use \BNETDocs \Libraries \Credits ;
88use \BNETDocs \Libraries \Document ;
99use \BNETDocs \Libraries \Exceptions \UnspecifiedViewException ;
10+ use \BNETDocs \Libraries \Exceptions \UserNotFoundException ;
1011use \BNETDocs \Libraries \Exceptions \UserProfileNotFoundException ;
1112use \BNETDocs \Libraries \Router ;
1213use \BNETDocs \Libraries \User as UserLib ;
@@ -39,7 +40,7 @@ public function run(Router &$router) {
3940 $ this ->getUserInfo ($ model );
4041 ob_start ();
4142 $ view ->render ($ model );
42- $ router ->setResponseCode (200 );
43+ $ router ->setResponseCode (( $ model -> user ? 200 : 404 ) );
4344 $ router ->setResponseTTL (0 );
4445 $ router ->setResponseHeader ("Content-Type " , $ view ->getMimeType ());
4546 $ router ->setResponseContent (ob_get_contents ());
@@ -49,6 +50,46 @@ public function run(Router &$router) {
4950 protected function getUserInfo (UserViewModel &$ model ) {
5051 $ model ->user_id = $ this ->user_id ;
5152
53+ // Try to get the user
54+ try {
55+ $ model ->user = new UserLib ($ this ->user_id );
56+ } catch (UserNotFoundException $ e ) {
57+ $ model ->user = null ;
58+ return ;
59+ }
60+
61+ // Try to get their user profile
62+ try {
63+ $ model ->user_profile = new UserProfile ($ this ->user_id );
64+ $ model ->biography = $ model ->user_profile ->getBiography ();
65+ $ model ->github = $ model ->user_profile ->getGitHubUsername ();
66+ $ model ->facebook = $ model ->user_profile ->getFacebookUsername ();
67+ $ model ->twitter = $ model ->user_profile ->getTwitterUsername ();
68+ $ model ->instagram = $ model ->user_profile ->getInstagramUsername ();
69+ $ model ->skype = $ model ->user_profile ->getSkypeUsername ();
70+ $ model ->website = $ model ->user_profile ->getWebsite ();
71+ } catch (UserProfileNotFoundException $ e ) {
72+ // Not a problem
73+ }
74+
75+ // Should we display profile data at all?
76+ $ model ->profiledata = (
77+ $ model ->github || $ model ->facebook ||
78+ $ model ->twitter || $ model ->instagram ||
79+ $ model ->skype || $ model ->website
80+ );
81+
82+ // How long have they been a member?
83+ $ model ->user_est = Common::intervalToString (
84+ $ model ->user ->getCreatedDateTime ()->diff (
85+ new DateTime ("now " , new DateTimeZone ("UTC " ))
86+ )
87+ );
88+ $ user_est_comma = strpos ($ model ->user_est , ", " );
89+ if ($ user_est_comma !== false )
90+ $ model ->user_est = substr ($ model ->user_est , 0 , $ user_est_comma );
91+
92+ // Summary of contributions
5293 $ model ->sum_documents = Credits::getTotalDocumentsByUserId (
5394 $ this ->user_id
5495 );
@@ -62,19 +103,22 @@ protected function getUserInfo(UserViewModel &$model) {
62103 $ this ->user_id
63104 );
64105
106+ // Total number of contributions
65107 $ model ->contributions = 0 ;
66108 $ model ->contributions += $ model ->sum_documents ;
67109 $ model ->contributions += $ model ->sum_news_posts ;
68110 $ model ->contributions += $ model ->sum_packets ;
69111 $ model ->contributions += $ model ->sum_servers ;
70112
113+ // References to the contributions
71114 $ model ->documents = ($ model ->sum_documents ?
72115 Document::getDocumentsByUserId ($ this ->user_id ) : null
73116 );
74117 $ model ->news_posts = ($ model ->sum_news_posts ? true : null );
75118 $ model ->packets = ($ model ->sum_packets ? true : null );
76119 $ model ->servers = ($ model ->sum_servers ? true : null );
77120
121+ // Process documents
78122 if ($ model ->documents ) {
79123 // Alphabetically sort the documents
80124 usort ($ model ->documents , function ($ a , $ b ){
@@ -94,43 +138,6 @@ protected function getUserInfo(UserViewModel &$model) {
94138 --$ i ;
95139 }
96140 }
97-
98- $ model ->user = new UserLib ($ this ->user_id );
99-
100- $ model ->user_est = Common::intervalToString (
101- $ model ->user ->getCreatedDateTime ()->diff (
102- new DateTime ("now " , new DateTimeZone ("UTC " ))
103- )
104- );
105- $ user_est_comma = strpos ($ model ->user_est , ", " );
106- if ($ user_est_comma !== false )
107- $ model ->user_est = substr ($ model ->user_est , 0 , $ user_est_comma );
108-
109- try {
110- $ model ->user_profile = new UserProfile ($ this ->user_id );
111- $ model ->biography = $ model ->user_profile ->getBiography ();
112- $ model ->github = $ model ->user_profile ->getGitHubUsername ();
113- $ model ->facebook = $ model ->user_profile ->getFacebookUsername ();
114- $ model ->twitter = $ model ->user_profile ->getTwitterUsername ();
115- $ model ->instagram = $ model ->user_profile ->getInstagramUsername ();
116- $ model ->skype = $ model ->user_profile ->getSkypeUsername ();
117- $ model ->website = $ model ->user_profile ->getWebsite ();
118- } catch (UserProfileNotFoundException $ e ) {
119- $ model ->user_profile = null ;
120- $ model ->biography = null ;
121- $ model ->github = null ;
122- $ model ->facebook = null ;
123- $ model ->twitter = null ;
124- $ model ->instagram = null ;
125- $ model ->skype = null ;
126- $ model ->website = null ;
127- }
128-
129- $ model ->profiledata = (
130- $ model ->github || $ model ->facebook ||
131- $ model ->twitter || $ model ->instagram ||
132- $ model ->skype || $ model ->website
133- );
134141 }
135142
136143}
0 commit comments