Stats per day

This commit is contained in:
Ruben 2017-03-31 12:39:36 +02:00
parent 851849f2a8
commit 098ddae13c
2 changed files with 24 additions and 3 deletions

View File

@ -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);
});

View File

@ -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();
}
}