diff --git a/src/Api/StatsControllerProvider.php b/src/Api/StatsControllerProvider.php index 5b68c24..3c8c83d 100644 --- a/src/Api/StatsControllerProvider.php +++ b/src/Api/StatsControllerProvider.php @@ -29,14 +29,22 @@ class StatsControllerProvider implements ControllerProviderInterface $gameRepo = $this->_eh->getEm()->getRepository(Models\Game::class); $stats = [ - 'new_games' => [], - 'new_users' => [], + 'games' => [ + 'new' => [], + 'total' => null + ], + 'users' => [ + 'new' => [], + ], ]; for ($i=0; $i < 14; $i++) { $day = date('Y-m-d',strtotime("-$i days")); - $stats['new_games'][$day] = $gameRepo->getCreatedCountOnDate($day); + $stats['games']['new'][$day] = $gameRepo->getCreatedCountOnDate($day); } + + $stats['games']['total'] = $gameRepo->getCount(); + return new CustomJsonResponse($stats, function($data) use ($app){return $app['serializer']->serialize($data, 'json');}, 200); }); diff --git a/src/Models/GameRepository.php b/src/Models/GameRepository.php index ac5e3af..8635f09 100644 --- a/src/Models/GameRepository.php +++ b/src/Models/GameRepository.php @@ -57,4 +57,17 @@ class GameRepository extends EntityRepository ]); return (int) $query->getSingleScalarResult(); } + + /** + * @return int + */ + public function getCount($date) { + $query = $this->_em->createQuery( + "SELECT COUNT(g.id) FROM ".Game::class." g" + ) + ->setParameters([ + 'date'=> $date, + ]); + return (int) $query->getSingleScalarResult(); + } } \ No newline at end of file