From 1f22cb57e92c32eadcd319974ff7d2cce4071c28 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 11 Sep 2023 19:42:40 +0300 Subject: [PATCH] update totals block --- src/library/database.php | 46 ++++++++++++++++++- src/public/node.php | 97 +++++++++++++++++++++++++++++++--------- 2 files changed, 120 insertions(+), 23 deletions(-) diff --git a/src/library/database.php b/src/library/database.php index bb0c218..86c263c 100644 --- a/src/library/database.php +++ b/src/library/database.php @@ -494,7 +494,7 @@ class Database { return $query->fetch(); } - public function getUsersTotal() { + public function getUsersTotal() : int { $this->_debug->query->select->total++; @@ -505,6 +505,24 @@ class Database { return $query->fetch()->result; } + public function getUsersTotalByPublic(mixed $public) : int { + + $this->_debug->query->select->total++; + + if (is_null($public)) + { + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `user` WHERE `public` IS NULL'); + $query->execute(); + } + else + { + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `user` WHERE `public` = ?'); + $query->execute([(int) $public]); + } + + return $query->fetch()->result; + } + public function findUserByAddress(string $address) { $this->_debug->query->select->total++; @@ -632,6 +650,19 @@ class Database { return $query->fetch()->result; } + public function getMagnetsTotalByUsersPublic(bool $public) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnet` + JOIN `user` ON (`user`.`userId` = `magnet`.`userId`) + WHERE `user`.`public` = ?'); + + $query->execute([(int) $public]); + + return $query->fetch()->result; + } + public function updateMagnetDn(int $magnetId, string $dn, int $timeUpdated) : int { $this->_debug->query->update->total++; @@ -1246,6 +1277,19 @@ class Database { return $query->fetch()->result; } + public function getMagnetCommentsTotalByUsersPublic(bool $public) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment` + JOIN `user` ON (`user`.`userId` = `magnetComment`.`userId`) + WHERE `user`.`public` = ?'); + + $query->execute([(int) $public]); + + return $query->fetch()->result; + } + public function getMagnetComments(int $magnetId, mixed $magnetCommentIdParent = null) { $this->_debug->query->select->total++; diff --git a/src/public/node.php b/src/public/node.php index 6eb9e60..edba7c8 100644 --- a/src/public/node.php +++ b/src/public/node.php @@ -117,6 +117,20 @@ else if (is_null($user->public)) timeUpdated) ?> + @@ -137,38 +151,77 @@ else if (is_null($user->public)) - getUsersTotal() ?> + + getUsersTotal() ?> + getUsersTotalByPublic(true)) { ?> + / + + + + + getUsersTotalByPublic(false)) { ?> + / + + + + + + + + + + - + getMagnetsTotal() ?> - / - - getMagnetsTotalByUserId($user->userId) ?> - - - - - - + getMagnetsTotalByUsersPublic(true)) { ?> + / + + + + + getMagnetsTotalByUsersPublic(false)) { ?> + / + + + + + + + + + - + getMagnetCommentsTotal() ?> - getMagnetCommentsTotalByUserId($user->userId)) { ?> - / - - - - - - - - + getMagnetCommentsTotalByUsersPublic(true)) { ?> + / + + + + getMagnetCommentsTotalByUsersPublic(false)) { ?> + / + + + + + + + + +