User stats
This commit is contained in:
parent
d4537fdac2
commit
48bbd3772f
2 changed files with 26 additions and 0 deletions
|
@ -27,6 +27,7 @@ class StatsControllerProvider implements ControllerProviderInterface
|
||||||
|
|
||||||
$controllers->get('/', function (Application $app) {
|
$controllers->get('/', function (Application $app) {
|
||||||
$gameRepo = $this->_eh->getEm()->getRepository(Models\Game::class);
|
$gameRepo = $this->_eh->getEm()->getRepository(Models\Game::class);
|
||||||
|
$userRepo = $this->_eh->getEm()->getRepository(Models\User::class);
|
||||||
|
|
||||||
$stats = [
|
$stats = [
|
||||||
'games' => [
|
'games' => [
|
||||||
|
@ -41,6 +42,7 @@ class StatsControllerProvider implements ControllerProviderInterface
|
||||||
for ($i=0; $i < 61; $i++) {
|
for ($i=0; $i < 61; $i++) {
|
||||||
$day = date('Y-m-d',strtotime("-$i days"));
|
$day = date('Y-m-d',strtotime("-$i days"));
|
||||||
$stats['games']['new'][$day] = $gameRepo->getCreatedCountOnDate($day);
|
$stats['games']['new'][$day] = $gameRepo->getCreatedCountOnDate($day);
|
||||||
|
$stats['users']['new'][$day] = $userRepo->getCreatedCountOnDate($day);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stats['games']['total'] = $gameRepo->getCount();
|
$stats['games']['total'] = $gameRepo->getCount();
|
||||||
|
|
|
@ -91,4 +91,28 @@ class UserRepository extends EntityRepository implements UserProviderInterface
|
||||||
]);
|
]);
|
||||||
return (int) $query->getSingleScalarResult();
|
return (int) $query->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getCreatedCountOnDate($date) {
|
||||||
|
$query = $this->_em->createQuery(
|
||||||
|
"SELECT COUNT(u.id) FROM ".User::class." u WHERE DATE(u.createdAt) = :date"
|
||||||
|
)
|
||||||
|
->setParameters([
|
||||||
|
'date'=> $date,
|
||||||
|
]);
|
||||||
|
return (int) $query->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getCount() {
|
||||||
|
$query = $this->_em->createQuery(
|
||||||
|
"SELECT COUNT(u.id) FROM ".User::class." u"
|
||||||
|
);
|
||||||
|
return (int) $query->getSingleScalarResult();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue