firefly-iii/app/Http/Controllers/Chart/PiggyBankController.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2015-05-16 02:41:14 -05:00
<?php
namespace FireflyIII\Http\Controllers\Chart;
2015-06-27 04:44:18 -05:00
use App;
2015-05-16 02:41:14 -05:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
2015-06-27 04:44:18 -05:00
use FireflyIII\Support\CacheProperties;
2015-05-16 02:41:14 -05:00
use Illuminate\Support\Collection;
use Response;
/**
* Class PiggyBankController
*
* @package FireflyIII\Http\Controllers\Chart
*/
class PiggyBankController extends Controller
{
2015-06-27 04:44:18 -05:00
/** @var \FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator */
protected $generator;
/**
*
*/
public function __construct()
{
parent::__construct();
// create chart generator:
$this->generator = App::make('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator');
}
2015-05-16 02:41:14 -05:00
/**
* Shows the piggy bank history.
*
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return \Symfony\Component\HttpFoundation\Response
*/
2015-06-27 04:44:18 -05:00
public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
2015-05-16 02:41:14 -05:00
{
2015-06-27 04:44:18 -05:00
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty('piggy-history');
$cache->addProperty($piggyBank->id);
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
2015-05-16 02:41:14 -05:00
}
2015-06-27 04:44:18 -05:00
/** @var Collection $set */
$set = new Collection($repository->getEventSummarySet($piggyBank));
$data = $this->generator->history($set);
$cache->store($data);
2015-05-16 02:41:14 -05:00
2015-06-27 04:44:18 -05:00
return Response::json($data);
2015-05-16 02:41:14 -05:00
}
2015-05-20 12:56:14 -05:00
}