Moar refactoring.

This commit is contained in:
Alexey Skobkin 2015-06-23 13:41:29 +03:00
parent 41c7e57524
commit ac297dc0a2
3 changed files with 22 additions and 18 deletions

View file

@ -38,7 +38,7 @@ class UserController extends Controller
public function topAction() public function topAction()
{ {
return $this->render('@SkobkinPointTools/User/top.html.twig', [ return $this->render('@SkobkinPointTools/User/top.html.twig', [
'top_users' => $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:Subscription')->getTopUsers(), 'top_users' => $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:User')->getTopUsers(),
]); ]);
} }

View file

@ -25,21 +25,4 @@ class SubscriptionRepository extends EntityRepository
->getQuery()->getSingleScalarResult() ->getQuery()->getSingleScalarResult()
; ;
} }
/**
* @return TopUserDTO[]
*/
public function getTopUsers()
{
$qb = $this->createQueryBuilder('s');
return $qb
->select(['COUNT(s.subscriber) as cnt', 'NEW SkobkinPointToolsBundle:TopUserDTO(a.login, COUNT(s.subscriber))'])
->innerJoin('s.author', 'a')
->orderBy('cnt', 'desc')
->groupBy('a.id')
->setMaxResults(30)
->getQuery()->getResult()
;
}
} }

View file

@ -57,4 +57,25 @@ class UserRepository extends EntityRepository
->getQuery()->getResult() ->getQuery()->getResult()
; ;
} }
/**
* @return TopUserDTO[]
*/
public function getTopUsers($limit = 30)
{
if (!is_int($limit)) {
throw new \InvalidArgumentException('$limit must be an integer');
}
$qb = $this->createQueryBuilder('s');
return $qb
->select(['COUNT(s.subscriber) as cnt', 'NEW SkobkinPointToolsBundle:TopUserDTO(a.login, COUNT(s.subscriber))'])
->innerJoin('s.author', 'a')
->orderBy('cnt', 'desc')
->groupBy('a.id')
->setMaxResults($limit)
->getQuery()->getResult()
;
}
} }