src/Controller/Application/DefaultController.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Application;
  3. use App\Library\Symfony\Controller,
  4.     App\Library\Symfony\Annotation\Breadcrumb,
  5.     App\Library\Symfony\Annotation\Lang;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request,
  8.     Symfony\Component\Routing\Annotation\Route;
  9. use App\Entity\Quotation\Quote,
  10.     App\Entity\Inventory\Purchase,
  11.     App\Entity\Application\Message;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  15. /**
  16.  *  @Lang(domain="application", default_key="dashboard")
  17.  */
  18. class DefaultController extends Controller
  19. {
  20.     /**
  21.     * @var TranslatorInterface
  22.     */
  23.     protected $translator
  24.     
  25.     /**
  26.     * @var ManagerRegistry
  27.     */
  28.     protected $doctrine
  29.     public function __construct(
  30.         TranslatorInterface $translator null
  31.         ManagerRegistry $doctrine null )
  32.     {
  33.         parent::__construct($translator$doctrine);
  34.     }
  35.     /**
  36.      * @Route("/", name="home")
  37.      * @Breadcrumb(parent=false)
  38.      */
  39.     public function home(Request $request)
  40.     {
  41.         $user $this->getUser();
  42.         $isNewMessage false;
  43.         $message $this->doctrine
  44.           ->getRepository(Message::class)
  45.           ->getList(1,1);
  46.         $message $message $message[0] : [];
  47.         if($request->isMethod('POST')) {
  48.           $messageInput $request->request->get('home-message');
  49.           $isNewMessage true;
  50.           $em $this->doctrine->getManager();
  51.           $newMessage = new Message();
  52.           $newMessage->setMessage($messageInput);
  53.           if(!$message){
  54.             $em->persist($newMessage);
  55.             $em->flush();
  56.           } else if($messageInput != $message->getMessage()){
  57.             $em->persist($newMessage);
  58.             $em->flush();
  59.           }
  60.         }
  61.         $notifications $this->getNotifications();
  62.         $unseenNotifications = [];
  63.         foreach ($notifications as $notification) {
  64.           if(!$notification['isSeen']){
  65.             $unseenNotifications[] = $notification;
  66.           }
  67.         }
  68.         $parameters['notifications'] = $notifications;
  69.         $parameters['unseenNotifications'] = $unseenNotifications;
  70.         return $this->render('application/home.html.twig', array(
  71.             'user' => $this->getUser(),
  72.             'notifications' => $notifications,
  73.             'unseenNotifications' => $unseenNotifications,
  74.             'message' => $isNewMessage $messageInput : ($message $message->getMessage() : ""),
  75.         ));
  76.     }
  77.     /**
  78.      * @Route("/ajax/get/recent", name="ajax_get_recent")
  79.      */
  80.     public function ajaxGetRecent(Request $request){
  81.         $type $request->request->get('type');
  82.         $item $request->request->get('item');
  83.         $maxResults $this->data('application.dashboard.config.list.items_shown');
  84.         $userParam $type === "mine" ? ["user" => $this->getUser()] : [] ;
  85.         if($item === "project" || $item === "quote"){
  86.             $quoteRepository $this->doctrine->getRepository(Quote::class);
  87.             $items $quoteRepository->{$item === "project" "getProjectsList" "getQuotesList"}(1$maxResults, [], $userParam'updatedAt');
  88.         }
  89.         else if($item === "purchase" || $item === "rental"){
  90.             $inventoryRepository $this->doctrine->getRepository(Purchase::class);
  91.             $items $inventoryRepository->getList(1$maxResults, [], $item === "purchase" "purchase" "rental"$userParam'updatedAt');
  92.         }
  93.         else{
  94.             $items = [];
  95.         }
  96.         return $this->renderHtml('application/home-items.html.twig', [
  97.             "items" => $items,
  98.             "itemType" => $item,
  99.         ]);
  100.     }
  101.     /**
  102.      * @Route("/ajax/notifications/clear", name="clear_notifications")
  103.      */
  104.     public function clearNotifications($module ""$id null){
  105.         parent::clearNotifications($module$id);
  106.     }
  107. }