/** * Show this month's category overview. * * @param CategoryRepositoryInterface $repository * * @return \Symfony\Component\HttpFoundation\Response */ public function frontpage(CategoryRepositoryInterface $repository) { $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('category'); $cache->addProperty('frontpage'); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $array = $repository->getCategoriesAndExpensesCorrected($start, $end); // sort by callback: uasort($array, function ($left, $right) { if ($left['sum'] == $right['sum']) { return 0; } return $left['sum'] < $right['sum'] ? 1 : -1; }); $set = new Collection($array); $data = $this->generator->frontpage($set); return Response::json($data); }