diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index a8583c2..cacbeda 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -25,7 +25,7 @@ {% block header_navbar_menus %} {% endblock %} diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php index d6b893c..e394c28 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php @@ -2,9 +2,10 @@ namespace Skobkin\Bundle\PointToolsBundle\Controller; -use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\EntityManager; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; +use Skobkin\Bundle\PointToolsBundle\Entity\TopUserDTO; use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Service\UserApi; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -12,7 +13,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; class UserController extends Controller { /** - * @param + * @param User $user * @ParamConverter("user", class="SkobkinPointToolsBundle:User", options={"login" = "login"}) */ public function showAction(User $user) @@ -20,19 +21,30 @@ class UserController extends Controller $userApi = $this->container->get('skobkin_point_tools.api_user'); /** @var QueryBuilder $qb */ + $qb = $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:User')->createQueryBuilder('u'); + + $subscribers = $qb + ->select('u') + ->innerJoin('u.subscriptions', 's') + ->where('s.author = :author') + ->setParameter('author', $user->getId()) + ->getQuery()->getResult() + ; + $qb = $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createQueryBuilder('se'); $subscriptionsEvents = $qb ->select() ->where('se.author = :author') ->orderBy('se.date', 'desc') - ->setMaxResults(30) + ->setMaxResults(10) ->setParameter('author', $user) ->getQuery()->getResult() ; return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [ 'user' => $user, + 'subscribers' => $subscribers, 'log' => $subscriptionsEvents, 'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE), ]); @@ -44,8 +56,20 @@ class UserController extends Controller $em = $this->getDoctrine()->getManager(); /** @var QueryBuilder $qb */ - $qb = $em->getRepository('SkobkinPointToolsBundle:Subscription')->createQueryBuilder('us'); + $qb = $em->getRepository('SkobkinPointToolsBundle:Subscription')->createQueryBuilder('s'); + /** @var TopUserDTO[] $topUsers */ + $topUsers = $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() + ; + return $this->render('@SkobkinPointTools/User/top.html.twig', [ + 'top_users' => $topUsers + ]); } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/TopUserDTO.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/TopUserDTO.php new file mode 100644 index 0000000..5e2545c --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/TopUserDTO.php @@ -0,0 +1,25 @@ +login = $login; + $this->subscribersCount = $subscribersCount; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig index f2fbdd9..6d3f344 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig @@ -21,8 +21,8 @@
diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig new file mode 100644 index 0000000..8d9903c --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig @@ -0,0 +1,24 @@ +{% extends "::base.html.twig" %} + +{% block header_title %}Top @ Point Tools{% endblock %} + +{% block content %} +

{{ 'Top users'|trans }}

+ + + + + + + + + + {% for user in top_users %} + + + + + {% endfor %} + +
{{ 'User'|trans }}{{ 'Subscribers count'|trans }}
@{{ user.login }}{{ user.subscribersCount }}
+{% endblock %}