diff --git a/public-legacy/profile.php b/public-legacy/profile.php index f7b7999..7101523 100644 --- a/public-legacy/profile.php +++ b/public-legacy/profile.php @@ -1,6 +1,7 @@ bind('user_id', $userInfo->getId())->fetch(); +// TODO: create user counters so these can be statically kept +$profileStats = new stdClass; +$profileStats->forum_topic_count = $forum->countTopics(userInfo: $userInfo, deleted: false); +$profileStats->forum_post_count = $forum->countPosts(userInfo: $userInfo, deleted: false); +$profileStats->comments_count = $msz->getComments()->countPosts(userInfo: $userInfo, deleted: false); if(!$viewingAsGuest) { Template::set('profile_warnings', $msz->getWarnings()->getWarningsWithDefaultBacklog($userInfo)); diff --git a/src/Comments/Comments.php b/src/Comments/Comments.php index 8d197b0..d84a1f1 100644 --- a/src/Comments/Comments.php +++ b/src/Comments/Comments.php @@ -218,6 +218,7 @@ class Comments { public function countPosts( CommentsCategoryInfo|string|null $categoryInfo = null, CommentsPostInfo|string|null $parentInfo = null, + UserInfo|string|null $userInfo = null, ?bool $replies = null, ?bool $deleted = null ): int { @@ -228,6 +229,7 @@ class Comments { $hasCategoryInfo = $categoryInfo !== null; $hasParentInfo = $parentInfo !== null; + $hasUserInfo = $userInfo !== null; $hasReplies = $replies !== null; $hasDeleted = $deleted !== null; @@ -244,6 +246,8 @@ class Comments { $query .= sprintf(' %s comment_reply_to %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $replies ? 'IS NOT' : 'IS'); if($hasDeleted) $query .= sprintf(' %s comment_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); + if($hasUserInfo) + $query .= sprintf(' %s user_id = ?', ++$args > 1 ? 'AND' : 'WHERE'); $args = 0; $stmt = $this->cache->get($query); @@ -251,6 +255,8 @@ class Comments { $stmt->addParameter(++$args, $parentInfo); elseif($hasCategoryInfo) $stmt->addParameter(++$args, $categoryInfo); + if($hasUserInfo) + $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->getId() : $userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -265,6 +271,7 @@ class Comments { public function getPosts( CommentsCategoryInfo|string|null $categoryInfo = null, CommentsPostInfo|string|null $parentInfo = null, + UserInfo|string|null $userInfo = null, ?bool $replies = null, ?bool $deleted = null, bool $includeRepliesCount = false, @@ -277,6 +284,7 @@ class Comments { $hasCategoryInfo = $categoryInfo !== null; $hasParentInfo = $parentInfo !== null; + $hasUserInfo = $userInfo !== null; $hasReplies = $replies !== null; $hasDeleted = $deleted !== null; @@ -301,6 +309,8 @@ class Comments { $query .= sprintf(' %s comment_reply_to %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $replies ? 'IS NOT' : 'IS'); if($hasDeleted) $query .= sprintf(' %s comment_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); + if($hasUserInfo) + $query .= sprintf(' %s user_id = ?', ++$args > 1 ? 'AND' : 'WHERE'); // this should really not be implicit like this if($hasParentInfo) @@ -316,6 +326,8 @@ class Comments { $stmt->addParameter(++$args, $parentInfo); elseif($hasCategoryInfo) $stmt->addParameter(++$args, $categoryInfo); + if($hasUserInfo) + $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->getId() : $userInfo); $stmt->execute(); $posts = []; diff --git a/templates/profile/master.twig b/templates/profile/master.twig index 3066372..7a896bb 100644 --- a/templates/profile/master.twig +++ b/templates/profile/master.twig @@ -33,10 +33,6 @@ 'title': 'Comments', 'value': profile_stats.comments_count, }, - { - 'title': 'Changes', - 'value': profile_stats.changelog_count, - }, ] %} {% else %} {% set image = url('user-avatar', {'user': 0, 'res': 240}) %}