Browse Source

update user profile module dependencies

main
ghost 1 year ago
parent
commit
c05abad02f
  1. 104
      src/app/controller/index.php
  2. 38
      src/app/controller/module/profile.php
  3. 6
      src/app/controller/page.php
  4. 19
      src/app/model/database.php
  5. 20
      src/config/bootstrap.php

104
src/app/controller/index.php

@ -2,19 +2,103 @@
class AppControllerIndex class AppControllerIndex
{ {
private $_user; private $_database;
private $_validator;
private $_website;
private $_session;
public function __construct(
AppModelDatabase $database,
AppModelValidator $validator,
AppModelWebsite $website,
AppModelSession $session
)
{
$this->_database = $database;
$this->_validator = $validator;
$this->_website = $website;
$this->_session = $session;
}
private function _initUser(string $address)
{
$error = [];
if (!$this->_validator->host($address, $error))
{
$this->_response(
sprintf(
_('Error - %s'),
$this->_website->getName()
),
_('406'),
$error,
406
);
}
try
{
$this->_database->beginTransaction();
$user = $this->_database->getUser(
$this->_database->initUserId(
$address,
$this->_website->getDefaultUserStatus(),
$this->_website->getDefaultUserApproved(),
time()
)
);
$this->_database->commit();
}
catch (Exception $error)
{
$this->_database->rollback();
$this->_response(
sprintf(
_('Error - %s'),
$this->_website->getName()
),
_('500'),
$error,
500
);
}
public function __construct() // Access denied
if (!$user->status)
{ {
require_once __DIR__ . '/user.php'; $this->_response(
sprintf(
_('Error - %s'),
$this->_website->getName()
),
_('403'),
_('Access denied'),
403
);
}
$this->_user = new AppControllerUser( // Require account type selection
$_SERVER['REMOTE_ADDR'] if (is_null($user->public))
{
header(
sprintf(
'Location: %s/welcome',
trim($this->_website->getUrl(), '/')
)
); );
} }
}
public function render() public function render()
{ {
$user = $this->_initUser(
$this->_session->getAddress()
);
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1; $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = []; $pages = [];
@ -26,16 +110,16 @@ class AppControllerIndex
require_once __DIR__ . '/module/head.php'; require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead( $appControllerModuleHead = new AppControllerModuleHead(
Environment::config('website')->url, $this->_website->getUrl(),
$page > 1 ? $page > 1 ?
sprintf( sprintf(
_('Page %s - BitTorrent Registry for Yggdrasil - %s'), _('Page %s - BitTorrent Registry for Yggdrasil - %s'),
$page, $page,
Environment::config('website')->name $this->_website->getName()
) : ) :
sprintf( sprintf(
_('%s - BitTorrent Registry for Yggdrasil'), _('%s - BitTorrent Registry for Yggdrasil'),
Environment::config('website')->name $this->_website->getName()
), ),
[ [
[ [
@ -60,7 +144,9 @@ class AppControllerIndex
require_once __DIR__ . '/module/profile.php'; require_once __DIR__ . '/module/profile.php';
$appControllerModuleProfile = new AppControllerModuleProfile( $appControllerModuleProfile = new AppControllerModuleProfile(
$this->_user $this->_database,
$this->_website,
$this->_session
); );
require_once __DIR__ . '/module/header.php'; require_once __DIR__ . '/module/header.php';

38
src/app/controller/module/profile.php

@ -2,27 +2,43 @@
class AppControllerModuleProfile class AppControllerModuleProfile
{ {
private $_user; private $_database;
private $_website;
private $_session;
public function __construct(AppControllerUser $user) public function __construct(
AppModelDatabase $database,
AppModelWebsite $website,
AppModelSession $session)
{ {
$this->_user = $user; $this->_database = $database;
$this->_website = $website;
$this->_session = $session;
} }
public function render() public function render()
{ {
$route = isset($_GET['_route_']) ? (string) $_GET['_route_'] : ''; $route = isset($_GET['_route_']) ? (string) $_GET['_route_'] : '';
$stars = $this->_user->findUserPageStarsDistinctTotalByValue(true); $user = $this->_database->getUser(
$views = $this->_user->findUserPageViewsDistinctTotal(); $this->_database->initUserId(
$downloads = $this->_user->findUserPageDownloadsDistinctTotal(); $this->_session->getAddress(),
$comments = $this->_user->findUserPageCommentsDistinctTotal(); $this->_website->getDefaultUserStatus(),
$editions = $this->_user->findUserPageEditionsDistinctTotal(); $this->_website->getDefaultUserApproved(),
time()
)
);
$identicon = $this->_user->getIdenticon(24); $stars = $this->_database->findUserPageStarsDistinctTotalByValue($user->userId, true);
$views = $this->_database->findUserPageViewsDistinctTotal($user->userId);
$downloads = 0; // @TODO $this->_database->findUserPageDownloadsDistinctTotal($user->userId);
$comments = $this->_database->findUserPageCommentsDistinctTotal($user->userId);
$editions = 0; // @TODO $this->_database->findUserPageEditionsDistinctTotal($user->userId);
$public = $this->_user->getPublic(); $identicon = false; // @TODO $this->_database->getIdenticon(24);
$address = $this->_user->getAddress();
$public = $user->public;
$address = $user->address;
include __DIR__ . '../../../view/theme/default/module/profile.phtml'; include __DIR__ . '../../../view/theme/default/module/profile.phtml';
} }

6
src/app/controller/page.php

@ -13,7 +13,7 @@ class AppControllerPage
AppModelValidator $validator, AppModelValidator $validator,
AppModelLocale $locale, AppModelLocale $locale,
AppModelWebsite $website, AppModelWebsite $website,
AppModelSession $session, AppModelSession $session
) )
{ {
$this->_database = $database; $this->_database = $database;
@ -334,7 +334,9 @@ class AppControllerPage
require_once __DIR__ . '/module/profile.php'; require_once __DIR__ . '/module/profile.php';
$appControllerModuleProfile = new AppControllerModuleProfile( $appControllerModuleProfile = new AppControllerModuleProfile(
$user $this->_database,
$this->_website,
$this->_session
); );
require_once __DIR__ . '/module/header.php'; require_once __DIR__ . '/module/header.php';

19
src/app/model/database.php

@ -639,11 +639,11 @@ class AppModelDatabase
return $query->rowCount(); return $query->rowCount();
} }
public function findUserPageStarsDistinctTotal(int $userId, bool $value) : int { public function findUserPageStarsDistinctTotalByValue(int $userId, bool $value) : int {
$this->_debug->query->select->total++; $this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageStar` WHERE `userId` = ? AND `value` = ?'); $query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `pageStar` WHERE `userId` = ? AND `value` = ?');
$query->execute([$userId, (int) $value]); $query->execute([$userId, (int) $value]);
@ -654,18 +654,7 @@ class AppModelDatabase
$this->_debug->query->select->total++; $this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageView` WHERE `userId` = ?'); $query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `pageView` WHERE `userId` = ?');
$query->execute([$userId]);
return $query->fetch()->result;
}
public function findUserPageDownloadsDistinctTotal(int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageDownload` WHERE `userId` = ?');
$query->execute([$userId]); $query->execute([$userId]);
@ -676,7 +665,7 @@ class AppModelDatabase
$this->_debug->query->select->total++; $this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageComment` WHERE `userId` = ?'); $query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `pageComment` WHERE `userId` = ?');
$query->execute([$userId]); $query->execute([$userId]);

20
src/config/bootstrap.php

@ -156,9 +156,27 @@ if (isset($request['_route_']))
else else
{ {
require_once __DIR__ . '/../app/model/database.php';
require_once __DIR__ . '/../app/model/validator.php';
require_once __DIR__ . '/../app/model/website.php';
require_once __DIR__ . '/../app/model/session.php';
require_once __DIR__ . '/../app/controller/index.php'; require_once __DIR__ . '/../app/controller/index.php';
$appControllerIndex = new AppControllerIndex(); $appControllerIndex = new AppControllerIndex(
new AppModelDatabase(
Environment::config('database')
),
new AppModelValidator(
Environment::config('validator')
),
new AppModelWebsite(
Environment::config('website')
),
new AppModelSession(
$_SERVER['REMOTE_ADDR']
)
);
$appControllerIndex->render(); $appControllerIndex->render();
} }

Loading…
Cancel
Save