Files
firefly-iii/app/Http/Controllers/HomeController.php

82 lines
2.0 KiB
PHP
Raw Normal View History

2015-02-06 04:52:16 +01:00
<?php namespace FireflyIII\Http\Controllers;
2015-02-06 04:39:52 +01:00
2015-02-07 13:15:40 +01:00
use Cache;
2015-02-07 06:49:24 +01:00
use Carbon\Carbon;
2015-03-13 08:44:07 +01:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2015-03-02 13:19:13 +01:00
use Input;
2015-02-07 06:49:24 +01:00
use Preferences;
2015-02-06 21:23:14 +01:00
use Redirect;
use Session;
2015-03-10 17:26:31 +01:00
2015-02-06 21:23:14 +01:00
/**
* Class HomeController
*
* @package FireflyIII\Http\Controllers
*/
2015-02-06 07:23:26 +01:00
class HomeController extends Controller
{
2015-02-06 04:39:52 +01:00
2015-02-06 07:23:26 +01:00
/**
*
*/
public function __construct()
{
2015-02-07 13:15:40 +01:00
}
2015-03-02 13:19:13 +01:00
public function dateRange()
{
2015-03-02 12:35:14 +01:00
$start = new Carbon(Input::get('start'));
2015-03-02 13:19:13 +01:00
$end = new Carbon(Input::get('end'));
$diff = $start->diffInDays($end);
if ($diff > 50) {
Session::flash('warning', $diff . ' days of data may take a while to load.');
}
2015-03-02 12:35:14 +01:00
2015-03-02 13:19:13 +01:00
Session::put('start', $start);
Session::put('end', $end);
2015-03-02 12:35:14 +01:00
}
2015-02-07 13:15:40 +01:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush()
{
Cache::flush();
return Redirect::route('index');
2015-02-06 07:23:26 +01:00
}
2015-02-06 04:39:52 +01:00
2015-02-06 07:23:26 +01:00
/**
2015-02-06 21:23:14 +01:00
* @return \Illuminate\View\View
2015-02-06 07:23:26 +01:00
*/
2015-03-13 08:44:07 +01:00
public function index(AccountRepositoryInterface $repository)
2015-02-06 07:23:26 +01:00
{
2015-03-13 08:44:07 +01:00
$count = $repository->countAssetAccounts();
2015-02-06 07:23:26 +01:00
$title = 'Firefly';
$subTitle = 'What\'s playing?';
$mainTitleIcon = 'fa-fire';
2015-02-07 06:49:24 +01:00
$transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []);
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
2015-03-13 08:44:07 +01:00
$accounts = $repository->getFrontpageAccounts($frontPage);
2015-03-21 08:51:34 +01:00
$savings = $repository->getSavingsAccounts();
2015-02-07 06:49:24 +01:00
foreach ($accounts as $account) {
2015-03-13 08:44:07 +01:00
$set = $repository->getFrontpageTransactions($account, $start, $end);
2015-02-07 06:49:24 +01:00
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
2015-02-07 13:15:40 +01:00
// var_dump($transactions);
2015-02-07 06:49:24 +01:00
2015-03-21 08:51:34 +01:00
return view('index', compact('count', 'title','savings', 'subTitle', 'mainTitleIcon', 'transactions'));
2015-02-06 07:23:26 +01:00
}
2015-02-06 04:39:52 +01:00
2015-02-06 21:23:14 +01:00
2015-02-06 04:39:52 +01:00
}