src/WellCommerce/Bundle/AppBundle/Controller/Admin/DashboardController.php line 49

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\Controller\Admin;
  14. use Doctrine\Common\Util\Debug;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use WellCommerce\Bundle\AppBundle\Entity\CustomReport;
  20. use WellCommerce\Bundle\AppBundle\Repository\ClientRepository;
  21. use WellCommerce\Bundle\CatalogBundle\Repository\ProductRepository;
  22. use WellCommerce\Bundle\CatalogBundle\Repository\ReviewRepository;
  23. use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController;
  24. use WellCommerce\Bundle\OrderBundle\Manager\OrderManager;
  25. use WellCommerce\Bundle\OrderBundle\Repository\OrderRepository;
  26. /**
  27.  * Class DashboardController
  28.  *
  29.  * @author  Adam Piotrowski <adam@wellcommerce.org>
  30.  *
  31.  * @Route("/dashboard", name="admin.dashboard.", options={"expose"="true"})
  32.  * @IsGranted("ROLE_ADMIN")
  33.  */
  34. class DashboardController extends AbstractAdminController
  35. {
  36.     public function __construct(OrderManager $orderManager)
  37.     {
  38.         parent::__construct($orderManager);
  39.     }
  40.     /**
  41.      * @Route("/index", name="index")
  42.      */
  43.     public function indexAction(ReviewRepository $reviewsOrderRepository $ordersClientRepository $clients): Response
  44.     {
  45.         $this->denyAccessUnlessGranted($this->manager->getAlias() . '.index');
  46.         $reports $this->getEntityManager()->getRepository(CustomReport::class)->findBy(['dashboard' => true]);
  47.         return $this->displayTemplate('index', [
  48.             'reviews'      => $reviews->findLatestReviews(),
  49.             'orders'       => $orders->findLatestOrders(),
  50.             'clients'      => $clients->findLatestClients(),
  51.             'carts'        => $orders->findLatestCarts(),
  52.             'reportBlocks' => array_chunk($reports2),
  53.         ]);
  54.     }
  55.     /**
  56.      * @Route("/search", name="search")
  57.      */
  58.     public function searchAction(
  59.         Request $request,
  60.         OrderRepository $orders,
  61.         ClientRepository $clients,
  62.         ProductRepository $products
  63.     ): Response {
  64.         $this->denyAccessUnlessGranted($this->manager->getAlias() . '.index');
  65.         $phrase  $request->request->get('phrase');
  66.         $content $this->renderView('WellCommerceAppBundle:Admin/Dashboard:search.html.twig', [
  67.             'phrase'   => $phrase,
  68.             'orders'   => $orders->searchOrders($phrase),
  69.             'clients'  => $clients->searchClients($phrase),
  70.             'products' => $products->searchProducts($phrase),
  71.         ]);
  72.         return $this->jsonResponse(['content' => $content]);
  73.     }
  74. }