firefly-iii/app/controllers/LimitController.php
2014-07-20 20:46:10 +02:00

49 lines
1.3 KiB
PHP

<?php
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
use Firefly\Storage\Limit\LimitRepositoryInterface as LRI;
class LimitController extends BaseController
{
protected $_budgets;
protected $_limits;
public function __construct(BRI $budgets, LRI $limits)
{
$this->_budgets = $budgets;
$this->_limits = $limits;
View::share('menu', 'budgets');
}
public function create($budgetId = null)
{
$periods = [
'weekly' => 'A week',
'monthly' => 'A month',
'quarterly' => 'A quarter',
'half-year' => 'Six months',
'yearly' => 'A year',
];
$budget = $this->_budgets->find($budgetId);
$budget_id = is_null($budget) ? null : $budget->id;
$budgets = $this->_budgets->getAsSelectList();
return View::make('limits.create')->with('budgets', $budgets)->with('budget_id', $budget_id)->with(
'periods', $periods
);
}
public function store()
{
// find a limit with these properties, as we might already have one:
$limit = $this->_limits->store(Input::all());
if ($limit->id) {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.limits.create')->withInput();
}
}
}