Make method smaller.

This commit is contained in:
James Cole 2020-03-16 19:40:48 +01:00
parent 4334928fbd
commit a7fffa5868
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 24 additions and 48 deletions

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionGroup;
@ -84,11 +83,11 @@ class ShowController extends Controller
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
$splits = $transactionGroup->transactionJournals()->count();
if(null === $first) {
if (null === $first) {
throw new FireflyException('This transaction is broken :(.');
}
$type = (string)trans(sprintf('firefly.%s',$first->transactionType->type));
$type = (string) trans(sprintf('firefly.%s', $first->transactionType->type));
$title = 1 === $splits ? $first->description : $transactionGroup->title;
$subTitle = sprintf('%s: "%s"', $type, $title);
@ -113,10 +112,19 @@ class ShowController extends Controller
$links = $this->repository->getLinks($transactionGroup);
return view(
'transactions.show', compact(
'transactionGroup', 'amounts', 'first', 'type', 'subTitle', 'splits', 'groupArray',
'events', 'attachments', 'links'
)
'transactions.show',
compact(
'transactionGroup',
'amounts',
'first',
'type',
'subTitle',
'splits',
'groupArray',
'events',
'attachments',
'links'
)
);
}

View File

@ -378,52 +378,20 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
{
$array = $journal->toArray();
$array['transactions'] = [];
$array['meta'] = [];
$array['tags'] = [];
$array['categories'] = [];
$array['budgets'] = [];
$array['notes'] = [];
$array['locations'] = [];
$array['attachments'] = [];
$array['links'] = [];
$array['piggy_bank_events'] = [];
$array['meta'] = $journal->transactionJournalMeta->toArray();
$array['tags'] = $journal->tags->toArray();
$array['categories'] = $journal->categories->toArray();
$array['budgets'] = $journal->budgets->toArray();
$array['notes'] = $journal->notes->toArray();
$array['locations'] = []; // todo
$array['attachments'] = $journal->attachments->toArray();
$array['links'] = []; // todo
$array['piggy_bank_events'] = $journal->piggyBankEvents->toArray();
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$array['transactions'][] = $this->expandTransaction($transaction);
}
foreach ($journal->transactionJournalMeta as $meta) {
$array['meta'][] = $meta->toArray();
}
foreach ($journal->tags as $tag) {
$array['tags'][] = $tag->toArray();
}
foreach ($journal->categories as $category) {
$array['categories'][] = $category->toArray();
}
foreach ($journal->budgets as $budget) {
$array['budgets'][] = $budget->toArray();
}
foreach ($journal->notes as $note) {
$array['notes'][] = $note->toArray();
}
foreach ($journal->attachments as $attachment) {
$array['attachments'][] = $attachment->toArray();
}
// TODO apparantly this doesnt work.
foreach ($journal->sourceJournalLinks as $link) {
$array['links'][] = $link->toArray();
}
foreach ($journal->destJournalLinks as $link) {
$array['links'][] = $link->toArray();
}
foreach ($journal->piggyBankEvents as $event) {
$array['piggy_bank_events'][] = $event->toArray();
}
return $array;
}