diff --git a/src/classes/Controllers/Web/Search.php b/src/classes/Controllers/Web/Search.php index 7f5d20a..250a21f 100644 --- a/src/classes/Controllers/Web/Search.php +++ b/src/classes/Controllers/Web/Search.php @@ -77,7 +77,11 @@ AGAINST (:query IN BOOLEAN MODE)"; $values = ['query' => $query]; + $account_type = $args['account_type'] ?? ''; + + $accountTypeTabs = $this->accountTypeTabs->render('search', $account_type, $sql_where, $values, ['q' => $originalQuery, 'field' => $field]); + if ($account_type) { $sql_where .= ' AND `account_type` = :account_type'; @@ -93,7 +97,7 @@ AND `account_type` = :account_type'; 'field' => $field, 'fieldName' => $fieldName, 'count' => $count, - 'accountTypeTabs' => $this->accountTypeTabs->render('search', $account_type, ['q' => $originalQuery, 'field' => $field]), + 'accountTypeTabs' => $accountTypeTabs, 'profiles' => $profiles, 'pager_full' => $pager->renderFull($count), 'pager_minimal' => $pager->renderMinimal($count), diff --git a/src/classes/Views/Widget/AccountTypeTabs.php b/src/classes/Views/Widget/AccountTypeTabs.php index ed5da41..9c46986 100644 --- a/src/classes/Views/Widget/AccountTypeTabs.php +++ b/src/classes/Views/Widget/AccountTypeTabs.php @@ -27,28 +27,39 @@ class AccountTypeTabs $this->router = $router; } - public function render(string $route_name, string $current_type = '', array $queryParams = []): string + public function render(string $route_name, string $current_type = '', $condition = '', $values = [], array $queryParams = []): string { - $stmt = ' -SELECT DISTINCT(`account_type`) AS `account_type` -FROM `profile` -WHERE `available` -AND NOT `hidden`'; - $account_types = $this->connection->fetchAll($stmt); + + $stmt = 'SELECT `account_type`, COUNT(*) AS `count` + FROM `profile` p + JOIN `server` s ON s.`id` = p.`server_id` AND s.`available` AND NOT s.`hidden` + WHERE p.`available` + AND NOT p.`hidden` + AND ' . $condition . ' + GROUP BY p.`account_type` + ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC'; + $account_types = $this->connection->fetchAll($stmt, $values); $tabs = [ [ - 'title' => 'All', + 'title' => $this->renderer->p__('account-type', 'All'), 'link' => $this->router->pathFor($route_name, [], $queryParams), 'active' => empty($current_type) ] ]; foreach ($account_types as $account_type) { + switch ($account_type['account_type']) { + case 'People': $title = $this->renderer->np__('account-type', 'People (%d)', 'People (%d)', $account_type['count']); break; + case 'Forum' : $title = $this->renderer->np__('account-type', 'Forum (%d)', 'Forums (%d)', $account_type['count']); break; + default: $title = $this->renderer->np__('account-type', $account_type['account_type']. ' (%d)', $account_type['account_type']. ' (%d)', $account_type['count']); + } + $tabs[] = [ - 'title' => $account_type['account_type'], + 'title' => $title, 'link' => $this->router->pathFor($route_name, ['account_type' => strtolower($account_type['account_type'])], $queryParams), - 'active' => strtolower($account_type['account_type']) == strtolower($current_type) + 'active' => strtolower($account_type['account_type']) == strtolower($current_type), + 'disabled' => $account_type['count'] == 0 ]; }