Implement Account model; small style changes; Twig debug setting
This commit is contained in:
parent
7859ef77ee
commit
32add30c9d
10 changed files with 263 additions and 56 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
namespace MailAccountAdmin\Repositories;
|
||||
|
||||
use MailAccountAdmin\Exceptions\AccountNotFoundException;
|
||||
use MailAccountAdmin\Models\Account;
|
||||
use PDO;
|
||||
|
||||
class AccountRepository extends BaseRepository
|
||||
|
|
@ -31,10 +32,17 @@ class AccountRepository extends BaseRepository
|
|||
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute($queryParams);
|
||||
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Create Account models from rows
|
||||
$accountList = [];
|
||||
foreach ($rows as $row) {
|
||||
$accountList[] = Account::createFromArray($row);
|
||||
}
|
||||
return $accountList;
|
||||
}
|
||||
|
||||
public function fetchAccountById(int $accountId): array
|
||||
public function fetchAccountById(int $accountId): Account
|
||||
{
|
||||
$statement = $this->pdo->prepare('SELECT * FROM mail_users WHERE user_id = :user_id LIMIT 1');
|
||||
$statement->execute(['user_id' => $accountId]);
|
||||
|
|
@ -43,6 +51,7 @@ class AccountRepository extends BaseRepository
|
|||
throw new AccountNotFoundException("Account with user ID '$accountId' was not found.");
|
||||
}
|
||||
|
||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||
$row = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
return Account::createFromArray($row);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue