Added shitty search hack to users class.

This commit is contained in:
flash 2023-08-31 00:19:20 +00:00
parent 40558ceb39
commit 4d6fb64f3a
3 changed files with 65 additions and 40 deletions

View file

@ -129,7 +129,7 @@ if(!empty($searchQuery)) {
} catch(RuntimeException $ex) {}
}
$forumPostInfos = $forum->getPosts(categoryInfo: $forumCategoryIds, deleted: false, searchQuery: $searchQueryEvaluated);
$forumPostInfos = $forum->getPosts(categoryInfo: $forumCategoryIds, searchQuery: $searchQueryEvaluated);
$forumPosts = [];
foreach($forumPostInfos as $postInfo) {
@ -194,34 +194,20 @@ if(!empty($searchQuery)) {
];
}
if(empty($searchQueryEvaluated['type']) || $searchQueryEvaluated['type'] === 'member') {
$findUsers = DB::prepare('
SELECT u.`user_id`, u.`username`, u.`user_country`,
u.`user_created`, u.`user_active`, r.`role_id`,
COALESCE(u.`user_title`, r.`role_title`) AS `user_title`,
COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`,
(
SELECT COUNT(`topic_id`)
FROM `msz_forum_topics`
WHERE `user_id` = u.`user_id`
AND `topic_deleted` IS NULL
) AS `user_count_topics`,
(
SELECT COUNT(`post_Id`)
FROM `msz_forum_posts`
WHERE `user_id` = u.`user_id`
AND `post_deleted` IS NULL
) AS `user_count_posts`
FROM `msz_users` AS u
LEFT JOIN `msz_roles` AS r
ON r.`role_id` = u.`display_role`
LEFT JOIN `msz_users_roles` AS ur
ON ur.`user_id` = u.`user_id`
WHERE u.`username` LIKE CONCAT("%%", :query, "%%")
GROUP BY u.`user_id`
');
$findUsers->bind('query', $searchQuery);
$userList = $findUsers->fetchAll();
$members = [];
$memberInfos = $users->getUsers(searchQuery: $searchQueryEvaluated);
foreach($memberInfos as $memberInfo) {
$members[] = $member = new stdClass;
$member->info = $memberInfo;
$memberId = $memberInfo->getId();
if(!array_key_exists($memberId, $userColours))
$userColours[$memberId] = $users->getUserColour($memberId);
$member->colour = $userColours[$memberId];
$member->ftopics = $forum->countTopics(userInfo: $memberInfo, deleted: false);
$member->fposts = $forum->countPosts(userInfo: $memberInfo, deleted: false);
}
}
@ -229,6 +215,6 @@ Template::render('home.search', [
'search_query' => $searchQuery,
'forum_topics' => $forumTopics ?? [],
'forum_posts' => $forumPosts ?? [],
'users' => $userList ?? [],
'members' => $members ?? [],
'news_posts' => $newsPosts ?? [],
]);

View file

@ -110,8 +110,35 @@ class Users {
?bool $deleted = null,
?string $orderBy = null,
?bool $reverseOrder = null,
?array $searchQuery = null,
?Pagination $pagination = null
): array {
// remove this hack when search server
$hasSearchQuery = $searchQuery !== null;
$searchLimitResults = false;
if($hasSearchQuery) {
if(!empty($searchQuery['type'])
&& $searchQuery['type'] !== 'member')
return [];
$roleInfo = null;
$after = null;
$lastActiveInMinutes = null;
$newerThanDays = null;
$birthdate = null;
$deleted = false;
$orderBy = 'id';
$reverseOrder = false;
$pagination = null;
$searchLimitResults = true;
if(!empty($searchQuery['after']))
$after = $searchQuery['after'];
$searchQuery = $searchQuery['query_string'];
$hasSearchQuery = !empty($searchQuery);
}
if($roleInfo instanceof RoleInfo)
$roleInfo = $roleInfo->getId();
if($after instanceof UserInfo)
@ -152,12 +179,16 @@ class Users {
$query .= sprintf(' %s user_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS');
if($hasBirthdate)
$query .= sprintf(' %s user_birthdate LIKE ?', ++$args > 1 ? 'AND' : 'WHERE');
if($hasSearchQuery)
$query .= sprintf(' %s username LIKE CONCAT("%%", ?, "%%")', ++$args > 1 ? 'AND' : 'WHERE');
if($hasOrderBy) {
$query .= sprintf(' ORDER BY %s', $orderBy[0]);
if($orderBy[1] !== null)
$query .= ' ' . ($orderBy[1] ? 'DESC' : 'ASC');
}
if($hasPagination)
if($searchLimitResults)
$query .= ' LIMIT 20';
elseif($hasPagination)
$query .= ' LIMIT ? OFFSET ?';
$args = 0;
@ -172,6 +203,8 @@ class Users {
$stmt->addParameter(++$args, $newerThanDays);
if($hasBirthdate)
$stmt->addParameter(++$args, $birthdate->format('%-m-d'));
if($hasSearchQuery)
$stmt->addParameter(++$args, $searchQuery);
if($hasPagination) {
$stmt->addParameter(++$args, $pagination->getRange());
$stmt->addParameter(++$args, $pagination->getOffset());

View file

@ -18,7 +18,7 @@
</div>
</form>
{% if forum_topics|length > 0 or forum_posts|length > 0 or users|length > 0 or news_posts|length > 0 %}
{% if forum_topics|length > 0 or forum_posts|length > 0 or members|length > 0 or news_posts|length > 0 %}
<div class="search__categories">
{% if forum_topics|length > 0 %}
<a href="#topics" class="search__category">
@ -38,8 +38,8 @@
</a>
{% endif %}
{% if users|length > 0 %}
<a href="#users" class="search__category">
{% if members|length > 0 %}
<a href="#members" class="search__category">
<div class="search__category__background"></div>
<div class="search__category__content">
Members
@ -60,7 +60,7 @@
</div>
{% if search_query is not empty and not (
forum_topics|length > 0 or forum_posts|length > 0 or users|length > 0 or news_posts|length > 0
forum_topics|length > 0 or forum_posts|length > 0 or members|length > 0 or news_posts|length > 0
) %}
<div class="container search__container search__none">
<div class="search__none__icon">
@ -100,18 +100,24 @@
{% endif %}
{% endif %}
{% if users|length > 0 %}
<div class="search__anchor" id="users"></div>
{% if members|length > 0 %}
<div class="search__anchor" id="members"></div>
<div class="container search__container">
{{ container_title('<i class="fas fa-users fa-fw"></i> Members (%s)'|format(users|length|number_format)) }}
{{ container_title('<i class="fas fa-users fa-fw"></i> Members (%s)'|format(members|length|number_format)) }}
<div class="userlist userlist--search">
{% for user in users %}
{% for member in members %}
<div class="userlist__item">
{{ user_card(user) }}
{{ user_card(member) }}
</div>
{% endfor %}
</div>
{% if members|length >= 20 %}
<div style="text-align: center; padding: 10px;">
<a href="{{ url('search-query', {'section': 'posts', 'query': search_merge_query({'type': 'member', 'after': members|last.info.id})}) }}" class="input__button">Load next 20 posts...</a>
</div>
{% endif %}
</div>
{% endif %}