firefly-iii/app/controllers/HomeController.php
2014-07-15 22:16:29 +02:00

53 lines
1.5 KiB
PHP

<?php
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
/**
* Class HomeController
*/
class HomeController extends BaseController
{
protected $_accounts;
protected $_preferences;
protected $_journal;
/**
* @param ARI $accounts
* @param PHI $preferences
* @param TJRI $journal
*/
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal)
{
$this->_accounts = $accounts;
$this->_preferences = $preferences;
$this->_journal = $journal;
View::share('menu', 'home');
}
/**
* @return $this|\Illuminate\View\View
*/
public function index()
{
// get list setting:
$pref = $this->_preferences->get('frontpageAccounts', []);
// get the accounts to display on the home screen:
$count = $this->_accounts->count();
if ($pref->data == []) {
$list = $this->_accounts->getActiveDefault();
} else {
$list = $this->_accounts->getByIds($pref->data);
}
// get transactions for each account:
foreach ($list as $account) {
$account->transactionList = $this->_journal->getByAccount($account, 10);
}
// build the home screen:
return View::make('index')->with('count', $count)->with('accounts', $list);
}
}