Cleanup and added todo's

This commit is contained in:
James Cole 2014-12-12 16:22:16 +01:00
parent 136adbe723
commit 7350b1da1b
2 changed files with 66 additions and 70 deletions

View File

@ -6,6 +6,10 @@ use FireflyIII\Shared\Preferences\PreferencesInterface as Pref;
/**
* Class BudgetController
*
* TODO move AJAX methods to their own BudgetAjaxControlle
* TODO Find out what constitutes proper camelCase
* TODO How is object coupling counted?
*
* @SuppressWarnings("CamelCase")
* @SuppressWarnings("TooManyMethods")
* @SuppressWarnings("CouplingBetweenObjects")

View File

@ -1,9 +1,13 @@
<?php
use FireflyIII\Database\Category as CategoryRepository;
use FireflyIII\Exception\FireflyException;
use Illuminate\Support\MessageBag;
/**
*
* TODO Find out what constitutes proper camelCase
*
* @SuppressWarnings("CamelCase")
*
* Class CategoryController
*/
class CategoryController extends BaseController
@ -94,44 +98,37 @@ class CategoryController extends BaseController
*/
public function store()
{
$data = Input::all();
/** @var \FireflyIII\Database\Category $repos */
$repos = App::make('FireflyIII\Database\Category');
$data = Input::except('_token');
switch ($data['post_submit_action']) {
default:
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
break;
case 'create_another':
case 'store':
$messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
// always validate:
$messages = $this->_repository->validate($data);
// flash messages:
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save category: ' . $messages['errors']->first());
return Redirect::route('categories.create')->withInput()->withErrors($messages['errors']);
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store category: ' . $messages['errors']->first());
}
// store!
$repos->store($data);
Session::flash('success', 'New category stored!');
if ($data['post_submit_action'] == 'create_another') {
// return to create screen:
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
return Redirect::route('categories.create')->withInput();
} else {
}
// store:
$this->_repository->store($data);
Session::flash('success', 'Category "' . e($data['name']) . '" stored.');
if ($data['post_submit_action'] == 'store') {
return Redirect::route('categories.index');
}
break;
case 'validate_only':
$messageBags = $repos->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
// create another.
if ($data['post_submit_action'] == 'create_another') {
return Redirect::route('categories.create')->withInput();
break;
}
return Redirect::route('categories.index');
}
/**
@ -142,44 +139,39 @@ class CategoryController extends BaseController
*/
public function update(Category $category)
{
/** @var \FireflyIII\Database\Category $repos */
$repos = App::make('FireflyIII\Database\Category');
$data = Input::except('_token');
switch (Input::get('post_submit_action')) {
default:
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break;
case 'return_to_edit':
case 'update':
$messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
// always validate:
$messages = $this->_repository->validate($data);
// flash messages:
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save category: ' . $messages['errors']->first());
return Redirect::route('categories.edit', $category->id)->withInput()->withErrors($messages['errors']);
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update category: ' . $messages['errors']->first());
}
// store!
$repos->update($category, $data);
Session::flash('success', 'Category updated!');
if ($data['post_submit_action'] == 'return_to_edit') {
return Redirect::route('categories.edit', $category->id);
} else {
// return to update screen:
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
return Redirect::route('categories.edit', $category->id)->withInput();
}
// update
$this->_repository->update($category, $data);
Session::flash('success', 'Category "' . e($data['name']) . '" updated.');
// go back to list
if ($data['post_submit_action'] == 'update') {
return Redirect::route('categories.index');
}
case 'validate_only':
$messageBags = $repos->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
return Redirect::route('categories.edit', $category->id)->withInput();
break;
}
// go back to update screen.
if ($data['post_submit_action'] == 'return_to_edit') {
return Redirect::route('categories.edit', $category->id)->withInput(['post_submit_action' => 'return_to_edit']);
}
return Redirect::route('categories.index');
}