firefly-iii/app/controllers/CategoryController.php

140 lines
3.5 KiB
PHP
Raw Normal View History

<?php
use Firefly\Helper\Controllers\CategoryInterface as CI;
use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
2014-07-30 00:14:00 -05:00
/**
* Class CategoryController
*/
class CategoryController extends BaseController
{
2014-07-30 00:14:00 -05:00
protected $_repository;
2014-08-02 08:54:39 -05:00
protected $_category;
2014-07-30 00:14:00 -05:00
2014-08-10 08:01:46 -05:00
/**
* @param CRI $repository
* @param CI $category
*/
public function __construct(CRI $repository, CI $category)
2014-07-30 00:14:00 -05:00
{
$this->_repository = $repository;
$this->_category = $category;
2014-07-30 00:14:00 -05:00
}
2014-08-10 08:01:46 -05:00
/**
* @return \Illuminate\View\View
*/
public function create()
{
return View::make('categories.create');
}
2014-08-10 08:01:46 -05:00
/**
* @param Category $category
*
* @return $this
*/
2014-07-30 00:14:00 -05:00
public function delete(Category $category)
{
return View::make('categories.delete')->with('category', $category);
}
2014-08-10 08:01:46 -05:00
/**
* @param Category $category
*
* @return \Illuminate\Http\RedirectResponse
*/
2014-08-02 08:54:39 -05:00
public function destroy(Category $category)
{
2014-08-02 08:54:39 -05:00
$result = $this->_repository->destroy($category);
if ($result === true) {
Session::flash('success', 'The category was deleted.');
} else {
Session::flash('error', 'Could not delete the category. Check the logs to be sure.');
}
return Redirect::route('categories.index');
}
2014-08-10 08:01:46 -05:00
/**
* @param Category $category
*
* @return $this
*/
2014-07-30 00:14:00 -05:00
public function edit(Category $category)
{
return View::make('categories.edit')->with('category', $category);
}
2014-08-10 08:01:46 -05:00
/**
* @return $this
*/
public function index()
{
2014-07-30 00:14:00 -05:00
$categories = $this->_repository->get();
return View::make('categories.index')->with('categories', $categories);
}
2014-08-10 08:01:46 -05:00
/**
* @param Category $category
*
* @return $this
*/
2014-07-30 00:14:00 -05:00
public function show(Category $category)
{
$start = \Session::get('start');
$end = \Session::get('end');
$journals = $this->_category->journalsInRange($category, $start, $end);
return View::make('categories.show')->with('category', $category)->with('journals', $journals)->with(
'highlight', Input::get('highlight')
);
}
2014-08-10 08:01:46 -05:00
/**
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store()
{
$category = $this->_repository->store(Input::all());
2014-08-10 04:30:14 -05:00
if ($category->validate()) {
Session::flash('success', 'Category "' . $category->name . '" created!');
if (Input::get('create') == '1') {
return Redirect::route('categories.create');
}
return Redirect::route('categories.index');
} else {
Session::flash('error', 'Could not save the new category!');
return Redirect::route('categories.create')->withInput();
}
}
2014-08-10 08:01:46 -05:00
/**
* @param Category $category
*
* @return $this|\Illuminate\Http\RedirectResponse
*/
2014-08-02 08:54:39 -05:00
public function update(Category $category)
{
2014-08-02 08:54:39 -05:00
$category = $this->_repository->update($category, Input::all());
if ($category->validate()) {
2014-08-02 08:54:39 -05:00
Session::flash('success', 'Category "' . $category->name . '" updated.');
2014-08-02 08:54:39 -05:00
return Redirect::route('categories.index');
} else {
Session::flash('success', 'Could not update category "' . $category->name . '".');
2014-08-02 08:54:39 -05:00
return Redirect::route('categories.edit')->withErrors($category->errors())->withInput();
}
}
}