Added profile topic listing (wip).
This commit is contained in:
parent
724bd29965
commit
c6826bd4f1
8 changed files with 211 additions and 8 deletions
|
@ -289,7 +289,7 @@ switch ($mode) {
|
|||
|
||||
tpl_vars([
|
||||
'title' => 'flash / following',
|
||||
'canonical_url' => url('user-profile-following', ['user' => $profile['user_id']]),
|
||||
'canonical_url' => url('user-profile-following', ['user' => $userId]),
|
||||
'profile_users' => $following,
|
||||
'profile_relation_pagination' => $followingPagination,
|
||||
]);
|
||||
|
@ -310,10 +310,45 @@ switch ($mode) {
|
|||
|
||||
tpl_vars([
|
||||
'title' => 'flash / followers',
|
||||
'canonical_url' => url('user-profile-followers', ['user' => $profile['user_id']]),
|
||||
'canonical_url' => url('user-profile-followers', ['user' => $userId]),
|
||||
'profile_users' => $followers,
|
||||
'profile_relation_pagination' => $followerPagination,
|
||||
]);
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'forum-topics':
|
||||
$template = 'profile.topics';
|
||||
$topicsCount = forum_topic_count_user($userId, $currentUserId);
|
||||
$topicsPagination = pagination_create($topicsCount, 20);
|
||||
$topicsOffset = pagination_offset($topicsPagination, pagination_param());
|
||||
|
||||
if (!pagination_is_valid_offset($topicsOffset)) {
|
||||
echo render_error(404);
|
||||
return;
|
||||
}
|
||||
|
||||
$topics = forum_topic_listing_user($userId, $currentUserId, $topicsOffset, $topicsPagination['range']);
|
||||
|
||||
tpl_vars([
|
||||
'title' => 'flash / topics',
|
||||
'canonical_url' => url('user-profile-forum-topics', ['user' => $userId]),
|
||||
'profile_topics' => $topics,
|
||||
'profile_topics_pagination' => $topicsPagination,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'forum-posts':
|
||||
$template = 'profile.posts';
|
||||
$postsCount = forum_post_count_user($userId);
|
||||
$postsPagination = pagination_create($postsCount, 20);
|
||||
$postsOffset = pagination_offset($postsPagination, pagination_param());
|
||||
|
||||
if (!pagination_is_valid_offset($postsOffset)) {
|
||||
echo render_error(404);
|
||||
return;
|
||||
}
|
||||
|
||||
$posts = forum_post_listing($userId, $postsOffset, $postsPagination['range'], false, true);
|
||||
break;
|
||||
|
||||
case '':
|
||||
|
|
|
@ -129,7 +129,23 @@ function forum_post_get(int $postId, bool $allowDeleted = false): array
|
|||
return db_fetch($getPost);
|
||||
}
|
||||
|
||||
function forum_post_listing(int $topicId, int $offset = 0, int $take = 0, bool $showDeleted = false): array
|
||||
function forum_post_count_user(int $userId, bool $showDeleted = false): int
|
||||
{
|
||||
$getPosts = db_prepare(sprintf(
|
||||
'
|
||||
SELECT COUNT(p.`post_id`)
|
||||
FROM `msz_forum_posts` AS p
|
||||
WHERE `user_id` = :user_id
|
||||
%1$s
|
||||
',
|
||||
$showDeleted ? '' : 'AND `post_deleted` IS NULL'
|
||||
));
|
||||
$getPosts->bindValue('user_id', $userId);
|
||||
|
||||
return (int)($getPosts->execute() ? $getPosts->fetchColumn() : 0);
|
||||
}
|
||||
|
||||
function forum_post_listing(int $topicId, int $offset = 0, int $take = 0, bool $showDeleted = false, bool $selectAuthor = false): array
|
||||
{
|
||||
$hasPagination = $offset >= 0 && $take > 0;
|
||||
$getPosts = db_prepare(sprintf(
|
||||
|
@ -166,13 +182,14 @@ function forum_post_listing(int $topicId, int $offset = 0, int $take = 0, bool $
|
|||
ON u.`user_id` = p.`user_id`
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
WHERE `topic_id` = :topic_id
|
||||
WHERE `%3$s` = :topic_id
|
||||
%1$s
|
||||
ORDER BY `post_id`
|
||||
%2$s
|
||||
',
|
||||
$showDeleted ? '' : 'AND `post_deleted` IS NULL',
|
||||
$hasPagination ? 'LIMIT :offset, :take' : ''
|
||||
$hasPagination ? 'LIMIT :offset, :take' : '',
|
||||
$selectAuthor ? 'topic_id' : 'user_id'
|
||||
));
|
||||
$getPosts->bindValue('topic_id', $topicId);
|
||||
|
||||
|
|
|
@ -270,6 +270,115 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
return db_fetch_all($getTopics);
|
||||
}
|
||||
|
||||
function forum_topic_count_user(int $authorId, int $userId, bool $showDeleted = false): int
|
||||
{
|
||||
$getTopics = db_prepare(sprintf(
|
||||
'
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics` AS t
|
||||
WHERE t.`user_id` = :author_id
|
||||
%1$s
|
||||
',
|
||||
$showDeleted ? '' : 'AND t.`topic_deleted` IS NULL'
|
||||
));
|
||||
$getTopics->bindValue('author_id', $authorId);
|
||||
//$getTopics->bindValue('user_id', $userId);
|
||||
|
||||
return (int)($getTopics->execute() ? $getTopics->fetchColumn() : 0);
|
||||
}
|
||||
|
||||
// Remove unneccesary stuff from the sql stmt
|
||||
function forum_topic_listing_user(int $authorId, int $userId, int $offset = 0, int $take = 0, bool $showDeleted = false): array
|
||||
{
|
||||
$hasPagination = $offset >= 0 && $take > 0;
|
||||
$getTopics = db_prepare(sprintf(
|
||||
'
|
||||
SELECT
|
||||
:user_id AS `target_user_id`,
|
||||
t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`,
|
||||
t.`topic_bumped`, t.`topic_deleted`, t.`topic_count_views`,
|
||||
au.`user_id` AS `author_id`, au.`username` AS `author_name`,
|
||||
COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`,
|
||||
lp.`post_id` AS `response_id`,
|
||||
lp.`post_created` AS `response_created`,
|
||||
lu.`user_id` AS `respondent_id`,
|
||||
lu.`username` AS `respondent_name`,
|
||||
COALESCE(lu.`user_colour`, lr.`role_colour`) AS `respondent_colour`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
%5$s
|
||||
) AS `topic_count_posts`,
|
||||
(
|
||||
SELECT CEIL(COUNT(`post_id`) / %6$d)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
%5$s
|
||||
) AS `topic_pages`,
|
||||
(
|
||||
SELECT
|
||||
`target_user_id` > 0
|
||||
AND
|
||||
t.`topic_bumped` > NOW() - INTERVAL 1 MONTH
|
||||
AND (
|
||||
SELECT COUNT(ti.`topic_id`) < 1
|
||||
FROM `msz_forum_topics_track` AS tt
|
||||
RIGHT JOIN `msz_forum_topics` AS ti
|
||||
ON ti.`topic_id` = tt.`topic_id`
|
||||
WHERE ti.`topic_id` = t.`topic_id`
|
||||
AND tt.`user_id` = `target_user_id`
|
||||
AND `track_last_read` >= `topic_bumped`
|
||||
)
|
||||
) AS `topic_unread`,
|
||||
(
|
||||
SELECT COUNT(`post_id`) > 0
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
AND `user_id` = `target_user_id`
|
||||
LIMIT 1
|
||||
) AS `topic_participated`
|
||||
FROM `msz_forum_topics` AS t
|
||||
LEFT JOIN `msz_users` AS au
|
||||
ON t.`user_id` = au.`user_id`
|
||||
LEFT JOIN `msz_roles` AS ar
|
||||
ON ar.`role_id` = au.`display_role`
|
||||
LEFT JOIN `msz_forum_posts` AS lp
|
||||
ON lp.`post_id` = (
|
||||
SELECT `post_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
%5$s
|
||||
ORDER BY `post_id` DESC
|
||||
LIMIT 1
|
||||
)
|
||||
LEFT JOIN `msz_users` AS lu
|
||||
ON lu.`user_id` = lp.`user_id`
|
||||
LEFT JOIN `msz_roles` AS lr
|
||||
ON lr.`role_id` = lu.`display_role`
|
||||
WHERE au.`user_id` = :author_id
|
||||
%1$s
|
||||
ORDER BY FIELD(t.`topic_type`, %4$s) DESC, t.`topic_bumped` DESC
|
||||
%2$s
|
||||
',
|
||||
$showDeleted ? '' : 'AND t.`topic_deleted` IS NULL',
|
||||
$hasPagination ? 'LIMIT :offset, :take' : '',
|
||||
MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT,
|
||||
implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)),
|
||||
$showDeleted ? '' : 'AND `post_deleted` IS NULL',
|
||||
MSZ_FORUM_POSTS_PER_PAGE
|
||||
));
|
||||
$getTopics->bindValue('author_id', $authorId);
|
||||
$getTopics->bindValue('user_id', $userId);
|
||||
|
||||
if ($hasPagination) {
|
||||
$getTopics->bindValue('offset', $offset);
|
||||
$getTopics->bindValue('take', $take);
|
||||
}
|
||||
|
||||
return db_fetch_all($getTopics);
|
||||
}
|
||||
|
||||
function forum_topic_lock(int $topicId): bool
|
||||
{
|
||||
if ($topicId < 1) {
|
||||
|
|
|
@ -58,6 +58,8 @@ define('MSZ_URLS', [
|
|||
'user-profile' => ['/profile.php', ['u' => '<user>']],
|
||||
'user-profile-following' => ['/profile.php', ['u' => '<user>', 'm' => 'following']],
|
||||
'user-profile-followers' => ['/profile.php', ['u' => '<user>', 'm' => 'followers']],
|
||||
'user-profile-forum-topics' => ['/profile.php', ['u' => '<user>', 'm' => 'forum-topics']],
|
||||
'user-profile-forum-posts' => ['/profile.php', ['u' => '<user>', 'm' => 'forum-posts']],
|
||||
'user-profile-edit' => ['/profile.php', ['u' => '<user>', 'edit' => '1']],
|
||||
'user-account-standing' => ['/profile.php', ['u' => '<user>'], 'account-standing'],
|
||||
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
{
|
||||
'title': 'Topics',
|
||||
'value': profile.forum_topic_count,
|
||||
'url': url('user-profile-forum-topics', {'user': profile.user_id}),
|
||||
},
|
||||
{
|
||||
'title': 'Posts',
|
||||
'value': profile.forum_post_count,
|
||||
'url': url('user-profile-forum-posts', {'user': profile.user_id}),
|
||||
},
|
||||
{
|
||||
'title': 'Comments',
|
||||
|
|
15
templates/profile/posts.twig
Normal file
15
templates/profile/posts.twig
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% extends 'profile/master.twig' %}
|
||||
{% from 'macros.twig' import pagination %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing %}
|
||||
|
||||
{% block content %}
|
||||
<div class="profile">
|
||||
{% include 'profile/_layout/header.twig' %}
|
||||
|
||||
{# if profile_relation_pagination.pages > 1 %}
|
||||
<div class="container profile__pagination">
|
||||
{{ pagination(profile_relation_pagination, canonical_url) }}
|
||||
</div>
|
||||
{% endif #}
|
||||
</div>
|
||||
{% endblock %}
|
23
templates/profile/topics.twig
Normal file
23
templates/profile/topics.twig
Normal file
|
@ -0,0 +1,23 @@
|
|||
{% extends 'profile/master.twig' %}
|
||||
{% from 'macros.twig' import pagination %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing %}
|
||||
|
||||
{% block content %}
|
||||
<div class="profile">
|
||||
{% include 'profile/_layout/header.twig' %}
|
||||
|
||||
{% set sp = profile_topics_pagination.pages > 1
|
||||
? '<div class="container profile__pagination">' ~ pagination(profile_topics_pagination, canonical_url) ~ '</div>'
|
||||
: '' %}
|
||||
|
||||
{% if sp is not empty %}
|
||||
{{ sp|raw }}
|
||||
{% endif %}
|
||||
|
||||
{{ forum_topic_listing(profile_topics) }}
|
||||
|
||||
{% if sp is not empty %}
|
||||
{{ sp|raw }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -58,7 +58,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if user.user_count_topics|default(0) > 0 %}
|
||||
<a class="usercard__stat">
|
||||
<a class="usercard__stat" href="{{ url('user-profile-forum-topics', {'user': user.user_id}) }}">
|
||||
<div class="usercard__stat__name">
|
||||
Topics
|
||||
</div>
|
||||
|
@ -69,7 +69,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if user.user_count_posts|default(0) > 0 %}
|
||||
<a class="usercard__stat">
|
||||
<a class="usercard__stat" href="{{ url('user-profile-forum-posts', {'user': user.user_id}) }}">
|
||||
<div class="usercard__stat__name">
|
||||
Posts
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue