<?php
declare(strict_types=0);
/*
* WellCommerce Foundation
*
* This file is part of the WellCommerce package.
*
* (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace WellCommerce\Bundle\AppBundle\Controller\Admin;
use Doctrine\Common\Util\Debug;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use WellCommerce\Bundle\AppBundle\Entity\CustomReport;
use WellCommerce\Bundle\AppBundle\Repository\ClientRepository;
use WellCommerce\Bundle\CatalogBundle\Repository\ProductRepository;
use WellCommerce\Bundle\CatalogBundle\Repository\ReviewRepository;
use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController;
use WellCommerce\Bundle\OrderBundle\Manager\OrderManager;
use WellCommerce\Bundle\OrderBundle\Repository\OrderRepository;
/**
* Class DashboardController
*
* @author Adam Piotrowski <adam@wellcommerce.org>
*
* @Route("/dashboard", name="admin.dashboard.", options={"expose"="true"})
* @IsGranted("ROLE_ADMIN")
*/
class DashboardController extends AbstractAdminController
{
public function __construct(OrderManager $orderManager)
{
parent::__construct($orderManager);
}
/**
* @Route("/index", name="index")
*/
public function indexAction(ReviewRepository $reviews, OrderRepository $orders, ClientRepository $clients): Response
{
$this->denyAccessUnlessGranted($this->manager->getAlias() . '.index');
$reports = $this->getEntityManager()->getRepository(CustomReport::class)->findBy(['dashboard' => true]);
return $this->displayTemplate('index', [
'reviews' => $reviews->findLatestReviews(),
'orders' => $orders->findLatestOrders(),
'clients' => $clients->findLatestClients(),
'carts' => $orders->findLatestCarts(),
'reportBlocks' => array_chunk($reports, 2),
]);
}
/**
* @Route("/search", name="search")
*/
public function searchAction(
Request $request,
OrderRepository $orders,
ClientRepository $clients,
ProductRepository $products
): Response {
$this->denyAccessUnlessGranted($this->manager->getAlias() . '.index');
$phrase = $request->request->get('phrase');
$content = $this->renderView('WellCommerceAppBundle:Admin/Dashboard:search.html.twig', [
'phrase' => $phrase,
'orders' => $orders->searchOrders($phrase),
'clients' => $clients->searchClients($phrase),
'products' => $products->searchProducts($phrase),
]);
return $this->jsonResponse(['content' => $content]);
}
}