Skip to content

Commit

Permalink
Convert user profile viewer to bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Jun 27, 2021
1 parent 016e253 commit d8d1f6d
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 513 deletions.
96 changes: 20 additions & 76 deletions src/controllers/User/View.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
<?php

<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
namespace BNETDocs\Controllers\User;

use \BNETDocs\Libraries\Credits;
use \BNETDocs\Libraries\Document;
use \BNETDocs\Libraries\Exceptions\UserNotFoundException;
use \BNETDocs\Libraries\Exceptions\UserProfileNotFoundException;
use \BNETDocs\Libraries\NewsPost;
use \BNETDocs\Libraries\Packet;
use \BNETDocs\Libraries\Server;
use \BNETDocs\Libraries\User as UserLib;
use \BNETDocs\Libraries\UserProfile;

use \BNETDocs\Libraries\User;
use \BNETDocs\Models\User\View as UserViewModel;

use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Controller;
use \CarlBennett\MVC\Libraries\Router;
use \CarlBennett\MVC\Libraries\View as ViewLib;

use \DateTime;
use \DateTimeZone;

class View extends Controller {
public function &run(Router &$router, ViewLib &$view, array &$args) {
$model = new UserViewModel();
class View extends Controller
{
public function &run(Router &$router, ViewLib &$view, array &$args)
{
$model = new UserViewModel();
$model->user_id = array_shift($args);

$this->getUserInfo($model);
Expand All @@ -34,73 +29,22 @@ public function &run(Router &$router, ViewLib &$view, array &$args) {
return $model;
}

protected function getUserInfo(UserViewModel &$model) {

protected function getUserInfo(UserViewModel &$model)
{
// Try to get the user
try {
$model->user = new UserLib($model->user_id);
} catch (UserNotFoundException $e) {
try
{
$model->user = new User($model->user_id);
}
catch (UserNotFoundException $e)
{
$model->user = null;
return;
}

// Try to get their user profile
try {

$model->user_profile = new UserProfile($model->user_id);

$model->biography = $model->user_profile->getBiography();

$model->discord = $model->user_profile->getDiscordUsername();

$model->facebook = $model->user_profile->getFacebookUsername();
$model->facebook_uri = $model->user_profile->getFacebookURI();

$model->github = $model->user_profile->getGitHubUsername();
$model->github_uri = $model->user_profile->getGitHubURI();

$model->instagram = $model->user_profile->getInstagramUsername();
$model->instagram_uri = $model->user_profile->getInstagramURI();

$model->phone = $model->user_profile->getPhone();
$model->phone_uri = $model->user_profile->getPhoneURI();

$model->reddit = $model->user_profile->getRedditUsername();
$model->reddit_uri = $model->user_profile->getRedditURI();

$model->skype = $model->user_profile->getSkypeUsername();
$model->skype_uri = $model->user_profile->getSkypeURI();

$model->steam_id = $model->user_profile->getSteamId();
$model->steam_uri = $model->user_profile->getSteamURI();

$model->twitter = $model->user_profile->getTwitterUsername();
$model->twitter_uri = $model->user_profile->getTwitterURI();

$model->website = $model->user_profile->getWebsite();
$model->website_uri = $model->user_profile->getWebsiteURI();

} catch (UserProfileNotFoundException $e) {
// Not a problem
}

// Should we display profile data at all?
$model->profiledata = (
$model->discord || $model->facebook || $model->github ||
$model->instagram || $model->phone || $model->reddit ||
$model->skype || $model->steam_id || $model->twitter ||
$model->website
);

// How long have they been a member?
$model->user_est = Common::intervalToString(
$model->user->getCreatedDateTime()->diff(
new DateTime( 'now', new DateTimeZone( 'Etc/UTC' ))
)
);
$user_est_comma = strpos($model->user_est, ',');
if ($user_est_comma !== false)
$model->user_est = substr($model->user_est, 0, $user_est_comma);
$model->user_est = Common::intervalToString($model->user->getCreatedDateTime()->diff(new DateTime('now')));
$model->user_est = substr($model->user_est, 0, min(strlen($model->user_est), strpos($model->user_est, ',')));

// Summary of contributions
$model->sum_documents = Credits::getTotalDocumentsByUserId(
Expand All @@ -124,16 +68,16 @@ protected function getUserInfo(UserViewModel &$model) {
$model->contributions += $model->sum_servers;

// References to the contributions
$model->documents = ($model->sum_documents ?
$model->documents = ($model->sum_documents ?
Document::getDocumentsByUserId($model->user_id) : null
);
$model->news_posts = ($model->sum_news_posts ?
NewsPost::getNewsPostsByUserId($model->user_id): null
);
$model->packets = ($model->sum_packets ?
$model->packets = ($model->sum_packets ?
Packet::getPacketsByUserId($model->user_id) : null
);
$model->servers = ($model->sum_servers ?
$model->servers = ($model->sum_servers ?
Server::getServersByUserId($model->user_id) : null
);

Expand Down
5 changes: 5 additions & 0 deletions src/libraries/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use \BNETDocs\Libraries\Credits;
use \BNETDocs\Libraries\Exceptions\QueryException;
use \BNETDocs\Libraries\Exceptions\UserNotFoundException;
use \BNETDocs\Libraries\UserProfile;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Database;
use \CarlBennett\MVC\Libraries\DatabaseDriver;
Expand Down Expand Up @@ -460,6 +461,10 @@ public function getUsername() {
return $this->username;
}

public function getUserProfile() {
return new UserProfile($this->id);
}

public function getVerifiedDateTime() {
if (is_null($this->verified_datetime)) {
return $this->verified_datetime;
Expand Down
Loading

0 comments on commit d8d1f6d

Please sign in to comment.