Stats per day
This commit is contained in:
parent
851849f2a8
commit
098ddae13c
2 changed files with 24 additions and 3 deletions
|
@ -29,14 +29,22 @@ class StatsControllerProvider implements ControllerProviderInterface
|
||||||
$gameRepo = $this->_eh->getEm()->getRepository(Models\Game::class);
|
$gameRepo = $this->_eh->getEm()->getRepository(Models\Game::class);
|
||||||
|
|
||||||
$stats = [
|
$stats = [
|
||||||
'new_games' => [],
|
'games' => [
|
||||||
'new_users' => [],
|
'new' => [],
|
||||||
|
'total' => null
|
||||||
|
],
|
||||||
|
'users' => [
|
||||||
|
'new' => [],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
for ($i=0; $i < 14; $i++) {
|
for ($i=0; $i < 14; $i++) {
|
||||||
$day = date('Y-m-d',strtotime("-$i days"));
|
$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);
|
return new CustomJsonResponse($stats, function($data) use ($app){return $app['serializer']->serialize($data, 'json');}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -57,4 +57,17 @@ class GameRepository extends EntityRepository
|
||||||
]);
|
]);
|
||||||
return (int) $query->getSingleScalarResult();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue