sadsd
All checks were successful
Deploy / deploy (push) Successful in 53s

This commit is contained in:
2026-08-17 00:39:46 +02:00
parent 0f57f90568
commit f7a6b34a97

View File

@@ -298,44 +298,68 @@ final class CommunityAccess
} }
$limit = max(1, min(50, $limit)); $limit = max(1, min(50, $limit));
$rowsById = [];
$tokens = array_values(array_filter(preg_split('/\s+/u', mb_strtolower($query)) ?: [], static fn(string $token): bool => $token !== '')); $tokens = array_values(array_filter(preg_split('/\s+/u', mb_strtolower($query)) ?: [], static fn(string $token): bool => $token !== ''));
if ($tokens === []) { if ($tokens !== []) {
return []; $conditions = [];
$params = [];
foreach ($tokens as $index => $token) {
$displayKey = ':display_' . $index;
$conditions[] = 'LOWER(COALESCE(up.display_name, "")) LIKE ' . $displayKey;
$params[$displayKey] = '%' . $token . '%';
}
$sql = '
SELECT u.id, u.email, u.status, up.display_name, up.first_name, up.last_name
FROM users u
LEFT JOIN user_profiles up ON up.user_id = u.id
WHERE ' . implode(' AND ', $conditions) . '
ORDER BY
CASE
WHEN LOWER(COALESCE(up.display_name, "")) = :exactDisplayQuery THEN 0
ELSE 1
END,
COALESCE(up.display_name, ""),
u.id DESC
LIMIT ' . $limit;
$params[':exactDisplayQuery'] = mb_strtolower($query);
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [] as $row) {
$rowsById[(int)($row['id'] ?? 0)] = $row;
}
} }
$conditions = []; if (str_contains($query, '@')) {
$params = []; $emailRow = $this->emailStore()->findUserByEmail($query, 'id, email, status');
foreach ($tokens as $index => $token) { if (is_array($emailRow)) {
$displayKey = ':display_' . $index; $profileStmt = $this->pdo->prepare('SELECT display_name, first_name, last_name FROM user_profiles WHERE user_id = :uid LIMIT 1');
$nameKey = ':name_' . $index; $profileStmt->execute(['uid' => (int)$emailRow['id']]);
$emailKey = ':email_' . $index; $profileRow = $profileStmt->fetch(\PDO::FETCH_ASSOC) ?: [];
$conditions[] = '(LOWER(COALESCE(up.display_name, "")) LIKE ' . $displayKey . ' OR LOWER(CONCAT_WS(" ", COALESCE(up.first_name, ""), COALESCE(up.last_name, ""))) LIKE ' . $nameKey . ' OR LOWER(COALESCE(u.email, "")) LIKE ' . $emailKey . ')'; $emailRow['display_name'] = (string)($profileRow['display_name'] ?? '');
$needle = '%' . $token . '%'; $emailRow['first_name'] = (string)($profileRow['first_name'] ?? '');
$params[$displayKey] = $needle; $emailRow['last_name'] = (string)($profileRow['last_name'] ?? '');
$params[$nameKey] = $needle; $rowsById[(int)$emailRow['id']] = $emailRow;
$params[$emailKey] = $needle; }
} }
$sql = ' $rows = array_values($rowsById);
SELECT u.id, u.email, u.status, up.display_name, up.first_name, up.last_name usort($rows, static function (array $left, array $right) use ($query): int {
FROM users u $leftDisplay = mb_strtolower((string)($left['display_name'] ?? ''));
LEFT JOIN user_profiles up ON up.user_id = u.id $rightDisplay = mb_strtolower((string)($right['display_name'] ?? ''));
WHERE ' . implode(' AND ', $conditions) . ' $needle = mb_strtolower($query);
ORDER BY $leftRank = $leftDisplay === $needle ? 0 : 1;
CASE $rightRank = $rightDisplay === $needle ? 0 : 1;
WHEN LOWER(COALESCE(up.display_name, "")) = :exactDisplayQuery THEN 0 if ($leftRank !== $rightRank) {
WHEN LOWER(COALESCE(u.email, "")) = :exactEmailQuery THEN 1 return $leftRank <=> $rightRank;
ELSE 2 }
END, return ((int)($right['id'] ?? 0)) <=> ((int)($left['id'] ?? 0));
COALESCE(up.display_name, ""), });
u.id DESC
LIMIT ' . $limit;
$params[':exactDisplayQuery'] = mb_strtolower($query);
$params[':exactEmailQuery'] = mb_strtolower($query);
$stmt = $this->pdo->prepare($sql); $rows = array_slice($rows, 0, $limit);
$stmt->execute($params); return $this->emailStore()->decryptRowEmails($rows, 'id');
return $this->emailStore()->decryptRowEmails($stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [], 'id');
} }
public function setRestriction(int $actingUserId, int $targetUserId, string $type, string $reason): void public function setRestriction(int $actingUserId, int $targetUserId, string $type, string $reason): void