2014-06-28 02:41:44 -05:00
|
|
|
<?php
|
2014-12-13 06:07:32 -06:00
|
|
|
use Carbon\Carbon;
|
2014-06-30 00:26:38 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
2014-09-09 13:00:04 -05:00
|
|
|
*
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
2015-01-02 15:44:25 -06:00
|
|
|
|
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
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-09-09 13:00:04 -05:00
|
|
|
// count, maybe Firefly needs some introducing text to show:
|
2014-12-13 15:54:52 -06:00
|
|
|
/** @var \FireflyIII\Database\Account\Account $acct */
|
|
|
|
$acct = App::make('FireflyIII\Database\Account\Account');
|
2014-11-11 11:16:59 -06:00
|
|
|
|
2014-12-25 01:07:17 -06:00
|
|
|
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journalRepository */
|
|
|
|
$journalRepository = App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
2014-11-11 11:16:59 -06:00
|
|
|
|
2014-11-12 07:38:32 -06:00
|
|
|
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
|
|
|
|
2015-01-17 00:25:44 -06:00
|
|
|
$count = $acct->countAccountsByType(['Default account', 'Asset account']);
|
2014-11-11 11:16:59 -06:00
|
|
|
|
2014-12-13 06:07:32 -06:00
|
|
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
|
|
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-20 11:24:27 -05:00
|
|
|
|
|
|
|
// get the preference for the home accounts to show:
|
2014-12-25 01:07:17 -06:00
|
|
|
$frontPage = $preferences->get('frontPageAccounts', []);
|
|
|
|
if ($frontPage->data == []) {
|
2015-01-17 00:25:44 -06:00
|
|
|
$accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
|
2014-07-21 00:40:38 -05:00
|
|
|
} else {
|
2014-12-25 01:07:17 -06:00
|
|
|
$accounts = $acct->getByIds($frontPage->data);
|
2014-07-21 00:40:38 -05:00
|
|
|
}
|
|
|
|
|
2014-07-20 11:24:27 -05:00
|
|
|
$transactions = [];
|
2014-07-23 09:44:20 -05:00
|
|
|
foreach ($accounts as $account) {
|
2014-12-25 01:07:17 -06:00
|
|
|
$set = $journalRepository->getInDateRangeAccount($account, $start, $end, 10);
|
2014-07-24 15:16:42 -05:00
|
|
|
if (count($set) > 0) {
|
|
|
|
$transactions[] = [$set, $account];
|
|
|
|
}
|
2014-07-20 11:24:27 -05:00
|
|
|
}
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
// build the home screen:
|
2014-11-12 15:36:02 -06:00
|
|
|
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')->with('subTitle', 'What\'s playing?')
|
|
|
|
->with('mainTitleIcon', 'fa-fire');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $range
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function rangeJump($range)
|
|
|
|
{
|
|
|
|
|
|
|
|
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
|
|
|
|
|
|
|
|
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
|
|
|
|
|
|
|
if (in_array($range, $valid)) {
|
|
|
|
$preferences->set('viewRange', $range);
|
|
|
|
Session::forget('range');
|
|
|
|
}
|
2015-01-25 01:28:59 -06:00
|
|
|
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {
|
|
|
|
return Redirect::back();
|
|
|
|
} else {
|
|
|
|
return Redirect::intended();
|
|
|
|
}
|
2014-11-12 15:36:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function sessionNext()
|
|
|
|
{
|
2014-11-21 04:12:22 -06:00
|
|
|
Navigation::next();
|
2015-01-28 22:11:00 -06:00
|
|
|
$strPosition = strpos($_SERVER['HTTP_REFERER'], Config::get('app.url'));
|
|
|
|
Log::debug('HTTP_REFERER is: ' . $_SERVER['HTTP_REFERER']);
|
|
|
|
Log::debug('App.url = ' . Config::get('app.url'));
|
|
|
|
Log::debug('strpos() = ' . Steam::boolString($strPosition));
|
|
|
|
|
|
|
|
if (isset($_SERVER['HTTP_REFERER']) && $strPosition === 0) {
|
|
|
|
Log::debug('Redirect back');
|
2015-01-25 01:28:59 -06:00
|
|
|
return Redirect::back();
|
|
|
|
} else {
|
2015-01-28 22:11:00 -06:00
|
|
|
Log::debug('Redirect intended');
|
2015-01-25 01:28:59 -06:00
|
|
|
return Redirect::intended();
|
|
|
|
}
|
2014-11-12 15:36:02 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function sessionPrev()
|
|
|
|
{
|
2014-11-21 04:12:22 -06:00
|
|
|
Navigation::prev();
|
2015-01-28 22:11:00 -06:00
|
|
|
$strPosition = strpos($_SERVER['HTTP_REFERER'], Config::get('app.url'));
|
|
|
|
Log::debug('HTTP_REFERER is: ' . $_SERVER['HTTP_REFERER']);
|
|
|
|
Log::debug('App.url = ' . Config::get('app.url'));
|
|
|
|
Log::debug('strpos() = ' . Steam::boolString($strPosition));
|
2014-11-12 15:36:02 -06:00
|
|
|
|
2015-01-28 22:11:00 -06:00
|
|
|
|
|
|
|
if (isset($_SERVER['HTTP_REFERER']) && $strPosition === 0) {
|
|
|
|
Log::debug('Redirect back');
|
2015-01-25 01:28:59 -06:00
|
|
|
return Redirect::back();
|
|
|
|
} else {
|
2015-01-28 22:11:00 -06:00
|
|
|
Log::debug('Redirect intended');
|
2015-01-25 01:28:59 -06:00
|
|
|
return Redirect::intended();
|
|
|
|
}
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2015-01-01 23:16:49 -06:00
|
|
|
}
|