Some refactoring.
This commit is contained in:
parent
f83d719299
commit
6384527720
|
@ -13,38 +13,10 @@ class MainController extends Controller
|
|||
/** @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)')
|
||||
->innerJoin('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,
|
||||
'users_count' => $em->getRepository('SkobkinPointToolsBundle:User')->getUsersCount(),
|
||||
'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')),
|
||||
'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(),
|
||||
'service_login' => $this->container->getParameter('point_login'),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
* @ORM\Table(name="subscriptions.subscriptions", uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="subscription_unique", columns={"author_id", "subscriber_id"})}
|
||||
* )
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionRepository")
|
||||
*/
|
||||
class Subscription
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
* @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}),
|
||||
* @ORM\Index(name="date_idx", columns={"date"})
|
||||
* })
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEventRepository")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class SubscriptionEvent
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class SubscriptionEventRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getLastDayEventsCount()
|
||||
{
|
||||
$qb = $this->createQueryBuilder('se');
|
||||
|
||||
$now = new \DateTime();
|
||||
|
||||
$eventsCount = $qb
|
||||
->select('COUNT(se)')
|
||||
->where('se.date > :time')
|
||||
->setParameter('time', $now->sub(new \DateInterval('PT24H')))
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class SubscriptionRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* @param integer $id
|
||||
* @return integer
|
||||
*/
|
||||
public function getUserSubscribersCountById($id)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('s');
|
||||
return $qb
|
||||
->select('COUNT(s)')
|
||||
->innerJoin('s.author', 'a')
|
||||
->where('a.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
* User
|
||||
*
|
||||
* @ORM\Table(name="users.users")
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\UserRepository")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class User
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class UserRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getUsersCount()
|
||||
{
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
|
||||
return $qb->select('COUNT(u)')->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue