Add count display for account type tabs

- Add translations strings to AccountTypeTabs
This commit is contained in:
Hypolite Petovan 2018-11-17 08:52:23 -05:00
parent 651849b18e
commit 4dad98fa04
2 changed files with 26 additions and 11 deletions

View file

@ -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),

View file

@ -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
];
}