Update topic look on search page.
This commit is contained in:
parent
2298617ee3
commit
9704bd3b54
4 changed files with 90 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
.search__anchor {
|
||||
position: absolute;
|
||||
top: -100px;
|
||||
position: relative;
|
||||
top: -94px;
|
||||
}
|
||||
|
|
|
@ -4,14 +4,7 @@ require_once '../misuzu.php';
|
|||
$searchQuery = !empty($_GET['q']) && is_string($_GET['q']) ? $_GET['q'] : '';
|
||||
|
||||
if (!empty($searchQuery)) {
|
||||
$findForumTopics = db_prepare('
|
||||
SELECT `topic_id`, `topic_title`
|
||||
FROM `msz_forum_topics`
|
||||
WHERE MATCH(`topic_title`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE);
|
||||
');
|
||||
$findForumTopics->bindValue('query', $searchQuery);
|
||||
$forumTopics = db_fetch_all($findForumTopics);
|
||||
$forumTopics = forum_topic_listing_search($searchQuery, user_session_current('user_id', 0));
|
||||
|
||||
$findForumPosts = db_prepare('
|
||||
SELECT fp.`post_id`, fp.`post_text`, ft.`topic_title`, u.`username`
|
||||
|
|
|
@ -383,6 +383,87 @@ function forum_topic_listing_user(int $authorId, int $userId, int $offset = 0, i
|
|||
return db_fetch_all($getTopics);
|
||||
}
|
||||
|
||||
function forum_topic_listing_search(string $query, int $userId): array
|
||||
{
|
||||
$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`
|
||||
AND `post_deleted` IS NULL
|
||||
) AS `topic_count_posts`,
|
||||
(
|
||||
SELECT CEIL(COUNT(`post_id`) / %2$d)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
AND `post_deleted` IS NULL
|
||||
) 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`
|
||||
AND `post_deleted` IS NULL
|
||||
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 MATCH(`topic_title`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE)
|
||||
AND t.`topic_deleted` IS NULL
|
||||
ORDER BY FIELD(t.`topic_type`, %1$s) DESC, t.`topic_bumped` DESC
|
||||
',
|
||||
implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)),
|
||||
MSZ_FORUM_POSTS_PER_PAGE
|
||||
));
|
||||
$getTopics->bindValue('query', $query);
|
||||
$getTopics->bindValue('user_id', $userId);
|
||||
|
||||
return db_fetch_all($getTopics);
|
||||
}
|
||||
|
||||
function forum_topic_lock(int $topicId): bool
|
||||
{
|
||||
if ($topicId < 1) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
{% from 'macros.twig' import container_title %}
|
||||
{% from '_layout/input.twig' import input_text %}
|
||||
{% from 'user/macros.twig' import user_card %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing %}
|
||||
|
||||
{% set title = search_query|length < 1 ? 'Search' : 'Looking for ' ~ search_query %}
|
||||
{% set canonical_url = url('search-query', {'query': search_query}) %}
|
||||
|
@ -68,20 +69,13 @@
|
|||
{% endif %}
|
||||
|
||||
{% if forum_topics|length > 0 %}
|
||||
<div class="container search__container">
|
||||
<div class="search__anchor" id="topics"></div>
|
||||
{{ container_title('<i class="fas fa-comments fa-fw"></i> Topics (%s)'|format(forum_topics|length|number_format)) }}
|
||||
{% for topic in forum_topics %}
|
||||
<a href="{{ url('forum-topic', {'topic': topic.topic_id}) }}" class="link">
|
||||
{{ topic.topic_title }}
|
||||
</a><br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="search__anchor" id="topics"></div>
|
||||
{{ forum_topic_listing(forum_topics) }}
|
||||
{% endif %}
|
||||
|
||||
{% if forum_posts|length > 0 %}
|
||||
<div class="search__anchor" id="posts"></div>
|
||||
<div class="container search__container">
|
||||
<div class="search__anchor" id="posts"></div>
|
||||
{{ container_title('<i class="fas fa-comment fa-fw"></i> Posts (%s)'|format(forum_posts|length|number_format)) }}
|
||||
|
||||
{% for post in forum_posts %}
|
||||
|
@ -93,8 +87,8 @@
|
|||
{% endif %}
|
||||
|
||||
{% if users|length > 0 %}
|
||||
<div class="search__anchor" id="users"></div>
|
||||
<div class="container search__container">
|
||||
<div class="search__anchor" id="users"></div>
|
||||
{{ container_title('<i class="fas fa-users fa-fw"></i> Users (%s)'|format(users|length|number_format)) }}
|
||||
|
||||
<div class="userlist">
|
||||
|
@ -108,8 +102,8 @@
|
|||
{% endif %}
|
||||
|
||||
{% if news_posts|length > 0 %}
|
||||
<div class="search__anchor" id="news"></div>
|
||||
<div class="container search__container">
|
||||
<div class="search__anchor" id="news"></div>
|
||||
{{ container_title('<i class="fas fa-newspaper fa-fw"></i> News (%s)'|format(news_posts|length|number_format)) }}
|
||||
{% for post in news_posts %}
|
||||
<a href="{{ url('news-post', {'post': post.post_id}) }}" class="link">
|
||||
|
|
Loading…
Add table
Reference in a new issue