2014-06-28 02:41:44 -05:00
|
|
|
<?php
|
2014-07-06 08:18:11 -05:00
|
|
|
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
2014-06-30 00:26:38 -05:00
|
|
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
2014-07-06 14:07:52 -05:00
|
|
|
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
2014-06-30 00:26:38 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
protected $_accounts;
|
|
|
|
protected $_preferences;
|
|
|
|
protected $_journal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ARI $accounts
|
|
|
|
* @param PHI $preferences
|
|
|
|
* @param TJRI $journal
|
|
|
|
*/
|
|
|
|
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal)
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_accounts = $accounts;
|
|
|
|
$this->_preferences = $preferences;
|
|
|
|
$this->_journal = $journal;
|
2014-07-06 08:18:11 -05:00
|
|
|
View::share('menu', 'home');
|
2014-06-30 00:26:38 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
// get list setting:
|
2014-07-15 15:16:29 -05:00
|
|
|
$pref = $this->_preferences->get('frontpageAccounts', []);
|
2014-07-06 08:18:11 -05:00
|
|
|
|
|
|
|
// get the accounts to display on the home screen:
|
2014-07-15 15:16:29 -05:00
|
|
|
$count = $this->_accounts->count();
|
2014-07-06 08:18:11 -05:00
|
|
|
if ($pref->data == []) {
|
2014-07-15 15:16:29 -05:00
|
|
|
$list = $this->_accounts->getActiveDefault();
|
2014-07-06 08:18:11 -05:00
|
|
|
} else {
|
2014-07-15 15:16:29 -05:00
|
|
|
$list = $this->_accounts->getByIds($pref->data);
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-06 14:07:52 -05:00
|
|
|
// get transactions for each account:
|
|
|
|
foreach ($list as $account) {
|
2014-07-15 15:16:29 -05:00
|
|
|
$account->transactionList = $this->_journal->getByAccount($account, 10);
|
2014-07-06 14:07:52 -05:00
|
|
|
}
|
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
// build the home screen:
|
|
|
|
return View::make('index')->with('count', $count)->with('accounts', $list);
|
|
|
|
}
|
2014-07-04 04:39:21 -05:00
|
|
|
}
|