From 55e4875662d210d2455c65b0623e51f09064b343 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 4 Feb 2016 08:53:15 +0100 Subject: [PATCH] New method to collect a users accounts by the given ids. --- app/Repositories/Account/AccountRepository.php | 16 +++++++++++++--- .../Account/AccountRepositoryInterface.php | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index ea19ac2dc2..38bf2f0caa 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -72,6 +72,18 @@ class AccountRepository implements AccountRepositoryInterface return Auth::user()->accounts()->findOrNew($accountId); } + /** + * Gets all the accounts by ID, for a given set. + * + * @param array $ids + * + * @return Collection + */ + public function get(array $ids) + { + return Auth::user()->accounts()->whereIn('id', $ids)->get(['accounts.*']); + } + /** * @param array $types * @@ -464,9 +476,7 @@ class AccountRepository implements AccountRepositoryInterface if (!$existingAccount) { Log::error('Account create error: ' . $newAccount->getErrors()->toJson()); abort(500); - // @codeCoverageIgnoreStart } - // @codeCoverageIgnoreEnd $newAccount = $existingAccount; } @@ -554,7 +564,7 @@ class AccountRepository implements AccountRepositoryInterface { $journal->date = $data['openingBalanceDate']; $journal->save(); - + /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { if ($account->id == $transaction->account_id) { diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 628aca2d15..9b10c383c7 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -17,6 +17,7 @@ use Illuminate\Support\Collection; */ interface AccountRepositoryInterface { + /** * @param array $types * @@ -41,6 +42,15 @@ interface AccountRepositoryInterface */ public function find($accountId); + /** + * Gets all the accounts by ID, for a given set. + * + * @param array $ids + * + * @return Collection + */ + public function get(array $ids); + /** * @param array $types *