firefly-iii/app/controllers/JsonController.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2014-07-14 23:58:08 -05:00
<?php
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
2014-07-15 00:08:13 -05:00
use Firefly\Storage\Budget\BudgetRepositoryInterface as Bud;
use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;
2014-07-14 23:58:08 -05:00
use Firefly\Storage\Component\ComponentRepositoryInterface as CRI;
2014-07-15 15:16:29 -05:00
/**
* Class JsonController
*
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
2014-07-15 15:16:29 -05:00
*/
2014-07-14 23:58:08 -05:00
class JsonController extends BaseController
{
2014-07-15 15:16:29 -05:00
protected $_accounts;
protected $_components;
protected $_categories;
protected $_budgets;
2014-07-14 23:58:08 -05:00
2014-07-15 15:16:29 -05:00
/**
* @param ARI $accounts
* @param CRI $components
* @param Cat $categories
* @param Bud $budgets
*/
2014-07-15 00:08:13 -05:00
public function __construct(ARI $accounts, CRI $components, Cat $categories, Bud $budgets)
2014-07-14 23:58:08 -05:00
{
2014-07-15 15:16:29 -05:00
$this->_components = $components;
$this->_accounts = $accounts;
2014-07-15 15:16:29 -05:00
$this->_categories = $categories;
$this->_budgets = $budgets;
2014-07-14 23:58:08 -05:00
}
/**
* Returns a JSON list of all beneficiaries.
*/
public function beneficiaries()
{
$list = $this->_accounts->getBeneficiaries();
2014-07-14 23:58:08 -05:00
$return = [];
foreach ($list as $entry) {
$return[] = $entry->name;
}
return Response::json($return);
}
/**
* Responds some JSON for typeahead fields.
*/
public function categories()
{
$list = $this->_categories->get();
2014-07-15 00:08:13 -05:00
$return = [];
foreach ($list as $entry) {
$return[] = $entry->name;
}
return Response::json($return);
2014-07-14 23:58:08 -05:00
}
}