firefly-iii/app/controllers/HomeController.php

80 lines
2.3 KiB
PHP
Raw Normal View History

2014-06-28 02:41:44 -05:00
<?php
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
2014-07-23 09:44:20 -05:00
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
2014-07-15 15:16:29 -05:00
/**
* Class HomeController
*/
class HomeController extends BaseController
{
2014-07-15 15:16:29 -05:00
protected $_accounts;
protected $_preferences;
protected $_journal;
2014-07-23 09:44:20 -05:00
protected $_budgets;
2014-07-15 15:16:29 -05:00
/**
2014-08-10 04:30:14 -05:00
* @param ARI $accounts
* @param PHI $preferences
* @param TJRI $journal
* @param BRI $budgets
2014-07-15 15:16:29 -05:00
*/
2014-08-09 01:18:07 -05:00
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, BRI $budgets)
{
2014-07-15 15:16:29 -05:00
$this->_accounts = $accounts;
$this->_preferences = $preferences;
$this->_journal = $journal;
2014-07-23 09:44:20 -05:00
$this->_budgets = $budgets;
}
2014-08-09 01:18:07 -05:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush()
{
Cache::flush();
return Redirect::route('index');
}
2014-07-15 15:16:29 -05:00
/**
* @return $this|\Illuminate\View\View
*/
public function index()
{
2014-07-23 09:44:20 -05:00
// count, maybe we need some introducing text to show:
2014-07-15 15:16:29 -05:00
$count = $this->_accounts->count();
2014-08-09 01:18:07 -05:00
$start = Session::get('start');
$end = Session::get('end');
// get the preference for the home accounts to show:
$frontpage = $this->_preferences->get('frontpageAccounts', []);
2014-07-23 09:44:20 -05:00
if ($frontpage->data == []) {
2014-07-21 00:40:38 -05:00
$accounts = $this->_accounts->getActiveDefault();
} else {
$accounts = $this->_accounts->getByIds($frontpage->data);
}
$transactions = [];
2014-07-23 09:44:20 -05:00
foreach ($accounts as $account) {
$set = $this->_journal->getByAccountInDateRange($account, 15, $start, $end);
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
2014-07-23 09:44:20 -05:00
if (count($transactions) % 2 == 0) {
$transactions = array_chunk($transactions, 2);
2014-07-23 09:44:20 -05:00
} elseif (count($transactions) == 1) {
$transactions = array_chunk($transactions, 3);
} else {
$transactions = array_chunk($transactions, 3);
}
2014-07-28 14:33:32 -05:00
// build the home screen:
return View::make('index')->with('count', $count)->with('transactions', $transactions);
}
2014-07-04 04:39:21 -05:00
}