Accounts: Fetch list of all accounts (optionally filtered by domain)
This commit is contained in:
parent
279f4492e8
commit
985f46c652
6 changed files with 145 additions and 9 deletions
35
src/Repositories/AccountRepository.php
Normal file
35
src/Repositories/AccountRepository.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Repositories;
|
||||
|
||||
use PDO;
|
||||
|
||||
class AccountRepository extends BaseRepository
|
||||
{
|
||||
public function fetchAccountList(string $filterByDomain = null): array
|
||||
{
|
||||
$queryWhere = '';
|
||||
$queryParams = [];
|
||||
if (!empty($filterByDomain)) {
|
||||
$queryWhere = 'WHERE REGEXP_REPLACE(username, "^.*@", "") LIKE :domain';
|
||||
$queryParams['domain'] = str_replace('*', '%', $filterByDomain);
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
mail_users.*,
|
||||
REGEXP_REPLACE(username, "^.*@", "") AS domain,
|
||||
COUNT(alias_id) AS alias_count
|
||||
FROM mail_users
|
||||
LEFT JOIN mail_aliases ON mail_users.user_id = mail_aliases.user_id
|
||||
' . $queryWhere . '
|
||||
GROUP BY username
|
||||
ORDER BY domain, username
|
||||
';
|
||||
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute($queryParams);
|
||||
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue