Exemplo n.º 1
0
 /**
  * @param CategoryRepositoryInterface $repository
  * @param Category                    $category
  *
  * @param                             $date
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
 {
     $carbon = new Carbon($date);
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod($carbon, $range);
     $end = Navigation::endOfPeriod($carbon, $range);
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty($category->id);
     $cache->addProperty('category');
     $cache->addProperty('specificPeriod');
     $cache->addProperty($date);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $entries = new Collection();
     while ($start <= $end) {
         $spent = $repository->spentOnDaySum($category, $start);
         $earned = $repository->earnedOnDaySum($category, $start);
         $theDate = Navigation::periodShow($start, '1D');
         $entries->push([clone $start, $theDate, $spent, $earned]);
         $start->addDay();
     }
     $data = $this->generator->period($entries);
     $cache->store($data);
     return Response::json($data);
 }