Added shitty search hack to users class.
This commit is contained in:
parent
40558ceb39
commit
4d6fb64f3a
3 changed files with 65 additions and 40 deletions
|
@ -129,7 +129,7 @@ if(!empty($searchQuery)) {
|
||||||
} catch(RuntimeException $ex) {}
|
} catch(RuntimeException $ex) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
$forumPostInfos = $forum->getPosts(categoryInfo: $forumCategoryIds, deleted: false, searchQuery: $searchQueryEvaluated);
|
$forumPostInfos = $forum->getPosts(categoryInfo: $forumCategoryIds, searchQuery: $searchQueryEvaluated);
|
||||||
$forumPosts = [];
|
$forumPosts = [];
|
||||||
|
|
||||||
foreach($forumPostInfos as $postInfo) {
|
foreach($forumPostInfos as $postInfo) {
|
||||||
|
@ -194,34 +194,20 @@ if(!empty($searchQuery)) {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($searchQueryEvaluated['type']) || $searchQueryEvaluated['type'] === 'member') {
|
$members = [];
|
||||||
$findUsers = DB::prepare('
|
$memberInfos = $users->getUsers(searchQuery: $searchQueryEvaluated);
|
||||||
SELECT u.`user_id`, u.`username`, u.`user_country`,
|
|
||||||
u.`user_created`, u.`user_active`, r.`role_id`,
|
foreach($memberInfos as $memberInfo) {
|
||||||
COALESCE(u.`user_title`, r.`role_title`) AS `user_title`,
|
$members[] = $member = new stdClass;
|
||||||
COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`,
|
$member->info = $memberInfo;
|
||||||
(
|
|
||||||
SELECT COUNT(`topic_id`)
|
$memberId = $memberInfo->getId();
|
||||||
FROM `msz_forum_topics`
|
if(!array_key_exists($memberId, $userColours))
|
||||||
WHERE `user_id` = u.`user_id`
|
$userColours[$memberId] = $users->getUserColour($memberId);
|
||||||
AND `topic_deleted` IS NULL
|
|
||||||
) AS `user_count_topics`,
|
$member->colour = $userColours[$memberId];
|
||||||
(
|
$member->ftopics = $forum->countTopics(userInfo: $memberInfo, deleted: false);
|
||||||
SELECT COUNT(`post_Id`)
|
$member->fposts = $forum->countPosts(userInfo: $memberInfo, deleted: false);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +215,6 @@ Template::render('home.search', [
|
||||||
'search_query' => $searchQuery,
|
'search_query' => $searchQuery,
|
||||||
'forum_topics' => $forumTopics ?? [],
|
'forum_topics' => $forumTopics ?? [],
|
||||||
'forum_posts' => $forumPosts ?? [],
|
'forum_posts' => $forumPosts ?? [],
|
||||||
'users' => $userList ?? [],
|
'members' => $members ?? [],
|
||||||
'news_posts' => $newsPosts ?? [],
|
'news_posts' => $newsPosts ?? [],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -110,8 +110,35 @@ class Users {
|
||||||
?bool $deleted = null,
|
?bool $deleted = null,
|
||||||
?string $orderBy = null,
|
?string $orderBy = null,
|
||||||
?bool $reverseOrder = null,
|
?bool $reverseOrder = null,
|
||||||
|
?array $searchQuery = null,
|
||||||
?Pagination $pagination = null
|
?Pagination $pagination = null
|
||||||
): array {
|
): 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)
|
if($roleInfo instanceof RoleInfo)
|
||||||
$roleInfo = $roleInfo->getId();
|
$roleInfo = $roleInfo->getId();
|
||||||
if($after instanceof UserInfo)
|
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');
|
$query .= sprintf(' %s user_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS');
|
||||||
if($hasBirthdate)
|
if($hasBirthdate)
|
||||||
$query .= sprintf(' %s user_birthdate LIKE ?', ++$args > 1 ? 'AND' : 'WHERE');
|
$query .= sprintf(' %s user_birthdate LIKE ?', ++$args > 1 ? 'AND' : 'WHERE');
|
||||||
|
if($hasSearchQuery)
|
||||||
|
$query .= sprintf(' %s username LIKE CONCAT("%%", ?, "%%")', ++$args > 1 ? 'AND' : 'WHERE');
|
||||||
if($hasOrderBy) {
|
if($hasOrderBy) {
|
||||||
$query .= sprintf(' ORDER BY %s', $orderBy[0]);
|
$query .= sprintf(' ORDER BY %s', $orderBy[0]);
|
||||||
if($orderBy[1] !== null)
|
if($orderBy[1] !== null)
|
||||||
$query .= ' ' . ($orderBy[1] ? 'DESC' : 'ASC');
|
$query .= ' ' . ($orderBy[1] ? 'DESC' : 'ASC');
|
||||||
}
|
}
|
||||||
if($hasPagination)
|
if($searchLimitResults)
|
||||||
|
$query .= ' LIMIT 20';
|
||||||
|
elseif($hasPagination)
|
||||||
$query .= ' LIMIT ? OFFSET ?';
|
$query .= ' LIMIT ? OFFSET ?';
|
||||||
|
|
||||||
$args = 0;
|
$args = 0;
|
||||||
|
@ -172,6 +203,8 @@ class Users {
|
||||||
$stmt->addParameter(++$args, $newerThanDays);
|
$stmt->addParameter(++$args, $newerThanDays);
|
||||||
if($hasBirthdate)
|
if($hasBirthdate)
|
||||||
$stmt->addParameter(++$args, $birthdate->format('%-m-d'));
|
$stmt->addParameter(++$args, $birthdate->format('%-m-d'));
|
||||||
|
if($hasSearchQuery)
|
||||||
|
$stmt->addParameter(++$args, $searchQuery);
|
||||||
if($hasPagination) {
|
if($hasPagination) {
|
||||||
$stmt->addParameter(++$args, $pagination->getRange());
|
$stmt->addParameter(++$args, $pagination->getRange());
|
||||||
$stmt->addParameter(++$args, $pagination->getOffset());
|
$stmt->addParameter(++$args, $pagination->getOffset());
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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">
|
<div class="search__categories">
|
||||||
{% if forum_topics|length > 0 %}
|
{% if forum_topics|length > 0 %}
|
||||||
<a href="#topics" class="search__category">
|
<a href="#topics" class="search__category">
|
||||||
|
@ -38,8 +38,8 @@
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if users|length > 0 %}
|
{% if members|length > 0 %}
|
||||||
<a href="#users" class="search__category">
|
<a href="#members" class="search__category">
|
||||||
<div class="search__category__background"></div>
|
<div class="search__category__background"></div>
|
||||||
<div class="search__category__content">
|
<div class="search__category__content">
|
||||||
Members
|
Members
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if search_query is not empty and not (
|
{% 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="container search__container search__none">
|
||||||
<div class="search__none__icon">
|
<div class="search__none__icon">
|
||||||
|
@ -100,18 +100,24 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if users|length > 0 %}
|
{% if members|length > 0 %}
|
||||||
<div class="search__anchor" id="users"></div>
|
<div class="search__anchor" id="members"></div>
|
||||||
<div class="container search__container">
|
<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">
|
<div class="userlist userlist--search">
|
||||||
{% for user in users %}
|
{% for member in members %}
|
||||||
<div class="userlist__item">
|
<div class="userlist__item">
|
||||||
{{ user_card(user) }}
|
{{ user_card(member) }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue