/**
  * Shows the piggy bank history.
  *
  * @param PiggyBankRepositoryInterface $repository
  * @param PiggyBank                    $piggyBank
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('piggy-history');
     $cache->addProperty($piggyBank->id);
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     $set = $repository->getEvents($piggyBank);
     $set = $set->reverse();
     $collection = [];
     /** @var PiggyBankEvent $entry */
     foreach ($set as $entry) {
         $date = $entry->date->format('Y-m-d');
         $amount = $entry->amount;
         if (isset($collection[$date])) {
             $amount = bcadd($amount, $collection[$date]);
         }
         $collection[$date] = $amount;
     }
     $data = $this->generator->history(new Collection($collection));
     $cache->store($data);
     return Response::json($data);
 }
示例#2
0
 /**
  * Shows the piggy bank history.
  *
  * @param PiggyBankRepositoryInterface $repository
  * @param PiggyBank                    $piggyBank
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('piggy-history');
     $cache->addProperty($piggyBank->id);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     /** @var Collection $set */
     $set = new Collection($repository->getEventSummarySet($piggyBank));
     $data = $this->generator->history($set);
     $cache->store($data);
     return Response::json($data);
 }