src/Controller/AdminController.php line 32

Open in your IDE?
  1. <?php
  2. // src/Controller/UserController.php
  3. namespace App\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  10. use App\Service\MessageService;
  11. use App\Service\UserService;
  12. class AdminController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/admin", name="adminLocaleRedirect")
  16.      * @Route("/vendeur", name="admin")
  17.      * @Security("has_role('ROLE_ADMIN')")
  18.      * Redirect the user to the right entry point depending of it's current locale
  19.      */
  20.     public function adminEntryLocaleRedirect(Request $requestUrlGeneratorInterface $routerUserService $userService){
  21.         $locale $request->getSession()->get('_locale');
  22.         if(empty($locale))
  23.             $locale 'fr';
  24.         if(count($userService->getUser()->getCompanies()) > 0){
  25.             $cId $userService->getUser()->getCompanies()->first()->getId();
  26.             $newRoute $router->generate'dashboardCompany', array ('_locale' => $locale'id' => $cId));
  27.         }else
  28.             return $this->redirectToRoute('home');
  29.         header("Location: ".$newRoute);
  30.         die();
  31.     }
  32.     /**
  33.      * @Route("/pull/json/updateInterface/admin",
  34.      *      options = { "expose" = true },
  35.      *      name = "getUpdatesForAdminInterface"
  36.      * )
  37.      */
  38.     public function updateAdminInterface(UserService $userServMessageService $messageServ){
  39.         $return = array();
  40.         $response = new JsonResponse();
  41.         if(!$userServ->getUser()){
  42.             return $response;
  43.         }
  44.         if(!$userServ->getUser())
  45.             return new JsonResponse(array());
  46.         //Début des messages
  47.         $notif $userServ->getUser()->getNotifications();
  48.         $notifContent = array();
  49.         $isThereNewNotif false;
  50.         foreach ($notif as $n){
  51.             if(!$n->getViewed()){
  52.                 $notifContent[] = array(
  53.                     'id' => $n->getId(),
  54.                     'title' => $n->getTitle(),
  55.                     'icon' => $n->getIcon(),
  56.                     'iconColor' => $n->getIconColor(),
  57.                     'text' => $n->getText(),
  58.                     'dateSince' => $n->getDateSince()
  59.                 );
  60.             }
  61.         }
  62.         if(count($notifContent) > 0){
  63.             $isThereNewNotif true;
  64.         }
  65.         $return['notifications'] = array(
  66.             'new' => $isThereNewNotif,
  67.             'amount' => count($notifContent),
  68.             'content' => $notifContent
  69.         );
  70.         //Fin des notifications
  71.         
  72.         //Debut des messages
  73.         $messages $messageServ->getNewMessagesIn('inbox');
  74.         $isThereNewMessages false;
  75.         $messagesContent = array();
  76.         foreach($messages as $message){
  77.             $messagesContent[] = array(
  78.                 'id' => $message->getId(),
  79.                 'from' => $message->getUserFrom()->getDisplayName(),
  80.                 'fromId' => $message->getUserFrom()->getId(),
  81.                 'subject' => $message->getSubject(),
  82.                 'message' => $message->getCleanMessage(),
  83.                 'dateSent' => $message->getDateSent()->format("j/m/y \\à\\ g:ia")
  84.             );
  85.         }
  86.         if(count($messagesContent) > 0){
  87.             $isThereNewMessages true;
  88.         }
  89.         $return['messages'] = array(
  90.             'new' => $isThereNewMessages,
  91.             'amount' => count($messagesContent),
  92.             'content' => $messagesContent
  93.         );
  94.         
  95.         //Fin des messages
  96.         $response->setData($return);
  97.         return $response;
  98.     }
  99. }