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
|
2014-09-09 13:00:04 -05:00
|
|
|
*
|
|
|
|
* @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;
|
2014-09-09 13:00:04 -05:00
|
|
|
$this->_accounts = $accounts;
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_categories = $categories;
|
2014-09-09 13:00:04 -05:00
|
|
|
$this->_budgets = $budgets;
|
2014-07-14 23:58:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JSON list of all beneficiaries.
|
|
|
|
*/
|
|
|
|
public function beneficiaries()
|
|
|
|
{
|
2014-09-09 13:00:04 -05:00
|
|
|
$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()
|
|
|
|
{
|
2014-09-09 13:00:04 -05:00
|
|
|
$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
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|