Statistics for main page.
This commit is contained in:
parent
20c44371c9
commit
097488446a
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
class MainController extends Controller
|
||||||
|
{
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
/** @var EntityManager $em */
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
/** @var QueryBuilder $qb */
|
||||||
|
$qb = $em->getRepository('SkobkinPointToolsBundle:User')->createQueryBuilder('u');
|
||||||
|
|
||||||
|
// All users in the system count
|
||||||
|
$usersCount = $qb->select('COUNT(u)')->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
$qb = $em->getRepository('SkobkinPointToolsBundle:Subscription')->createQueryBuilder('s');
|
||||||
|
|
||||||
|
// Service subscribers count
|
||||||
|
$subscribersCount = $qb
|
||||||
|
->select('COUNT(s)')
|
||||||
|
->join('s.author', 'a')
|
||||||
|
->where('a.login = :login')
|
||||||
|
->setParameter('login', $this->container->getParameter('point_login'))
|
||||||
|
->getQuery()->getSingleScalarResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
$qb = $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createQueryBuilder('se');
|
||||||
|
|
||||||
|
$now = new \DateTime();
|
||||||
|
|
||||||
|
$eventsCount = $qb
|
||||||
|
->select('COUNT(se)')
|
||||||
|
->where('se.date > :time')
|
||||||
|
->setParameter('time', $now->sub(new \DateInterval('PT24H')))
|
||||||
|
->getQuery()->getSingleScalarResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
return $this->render('SkobkinPointToolsBundle:Main:index.html.twig', [
|
||||||
|
'users_count' => $usersCount,
|
||||||
|
'subscribers_count' => $subscribersCount,
|
||||||
|
'events_count' => $eventsCount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
#skobkin_point_tools_homepage:
|
index:
|
||||||
# path: /hello/{name}
|
path: /
|
||||||
# defaults: { _controller: SkobkinPointToolsBundle:Default:index }
|
defaults: { _controller: SkobkinPointToolsBundle:Main:index }
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "::base.html.twig" %}
|
||||||
|
|
||||||
|
{% block title %}SkobkinPointToolsBundle:Main:index{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>{{ users_count }}</h1>
|
||||||
|
<h1>{{ subscribers_count }}</h1>
|
||||||
|
<h1>{{ events_count }}</h1>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class MainControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
|
||||||
|
$crawler = $client->request('GET', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue