Moar refactoring.
This commit is contained in:
parent
41c7e57524
commit
ac297dc0a2
|
@ -38,7 +38,7 @@ class UserController extends Controller
|
|||
public function topAction()
|
||||
{
|
||||
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(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,21 +25,4 @@ class SubscriptionRepository extends EntityRepository
|
|||
->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()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -57,4 +57,25 @@ class UserRepository extends EntityRepository
|
|||
->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()
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue