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 @@ @@ -2,19 +2,103 @@
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(
$_SERVER['REMOTE_ADDR']
// Require account type selection
if (is_null($user->public))
{
header(
sprintf(
'Location: %s/welcome',
trim($this->_website->getUrl(), '/')
)
);
}
}
public function render()
{
$user = $this->_initUser(
$this->_session->getAddress()
);
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = [];
@ -26,16 +110,16 @@ class AppControllerIndex @@ -26,16 +110,16 @@ class AppControllerIndex
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
Environment::config('website')->url,
$this->_website->getUrl(),
$page > 1 ?
sprintf(
_('Page %s - BitTorrent Registry for Yggdrasil - %s'),
$page,
Environment::config('website')->name
$this->_website->getName()
) :
sprintf(
_('%s - BitTorrent Registry for Yggdrasil'),
Environment::config('website')->name
$this->_website->getName()
),
[
[
@ -60,7 +144,9 @@ class AppControllerIndex @@ -60,7 +144,9 @@ class AppControllerIndex
require_once __DIR__ . '/module/profile.php';
$appControllerModuleProfile = new AppControllerModuleProfile(
$this->_user
$this->_database,
$this->_website,
$this->_session
);
require_once __DIR__ . '/module/header.php';

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

@ -2,27 +2,43 @@ @@ -2,27 +2,43 @@
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()
{
$route = isset($_GET['_route_']) ? (string) $_GET['_route_'] : '';
$stars = $this->_user->findUserPageStarsDistinctTotalByValue(true);
$views = $this->_user->findUserPageViewsDistinctTotal();
$downloads = $this->_user->findUserPageDownloadsDistinctTotal();
$comments = $this->_user->findUserPageCommentsDistinctTotal();
$editions = $this->_user->findUserPageEditionsDistinctTotal();
$user = $this->_database->getUser(
$this->_database->initUserId(
$this->_session->getAddress(),
$this->_website->getDefaultUserStatus(),
$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();
$address = $this->_user->getAddress();
$identicon = false; // @TODO $this->_database->getIdenticon(24);
$public = $user->public;
$address = $user->address;
include __DIR__ . '../../../view/theme/default/module/profile.phtml';
}

6
src/app/controller/page.php

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

19
src/app/model/database.php

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

20
src/config/bootstrap.php

@ -156,9 +156,27 @@ if (isset($request['_route_'])) @@ -156,9 +156,27 @@ if (isset($request['_route_']))
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';
$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();
}

Loading…
Cancel
Save