src/Controller/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SysUsers;
  4. use App\Service\EntityManagerFactory;
  5. use App\Service\SysUsersService;
  6. use Illuminate\Contracts\Container\Container;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Bundle\FrameworkBundle\Controller;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  14. use App\Service\StatisticsService;
  15. class DefaultController extends BaseController
  16. {
  17.     /**
  18.      * @Route("/", name="homepage")
  19.      * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
  20.      * @param ContainerInterface $container
  21.      * @return \Symfony\Component\HttpFoundation\Response
  22.      */
  23.     public function homepageAction(Request $requestContainerInterface $containerEntityManagerFactory $emf)
  24.     {
  25.         /** @var SysUsers $user */
  26.         $user $this->getUser();
  27.         $router $this->container->get('router');
  28.         $allowedIp $container->getParameter("ip_allowed");
  29.         $actualIp SysUsersService::getRealIpAddr();
  30.         if (false === in_array($actualIp$allowedIp) && false === $user->getExternalIp()) {
  31.             return new RedirectResponse($router->generate('fos_user_security_logout'), 307);
  32.         }
  33.         $authChecker $this->container->get('security.authorization_checker');
  34.         if ($authChecker->isGranted('ROLE_CLIENT')) {
  35.             return new RedirectResponse($router->generate('clientOrderList'), 307);
  36.         }
  37.         // Compte les nouvelles commandes en lignes
  38.         $emf->getCurrentRaffinManager()->getFilters()->disable("disabledClientFilter");
  39.         $em $emf->getCurrentRaffinManager();
  40.         $q  ' SELECT e.id FROM App:CommandeSpeciale e';
  41.         $q .= ' INNER JOIN e.details AS d WITH d.acomptePrisSur IS NULL ';
  42.         $q .= ' WHERE e.company = :company ';
  43.         $q .= ' AND d.status <> 2 AND exists (select csd.id from App:CommandeSpecialeDetail csd where csd.acomptePrisSur is null) ';
  44.         $q .= ' AND e.commandeEnLigneType is not null ';
  45.         $q .= ' GROUP BY e.id ';
  46.         $query $em->createQuery($q);
  47.         $query->setParameter('company'$this->getCurrentCompany());
  48.         $onlineOrdersCount count($query->execute());
  49.         $emf->getCurrentRaffinManager()->getFilters()->enable("disabledClientFilter");
  50.         return $this->render('default/index.html.twig', [
  51.             'resetCookieCaissier' => $this->getCurrentUser()->getCodeCaissier(),
  52.             'onlineOrdersCount'   => $onlineOrdersCount,
  53.         ]);
  54.     }
  55. }