src/Controller/adminController/NotificationController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller\adminController;
  3. use App\Controller\basisController\AllgemeineFunktionenController;
  4. use App\Controller\basisController\UserBasisController;
  5. use App\Entity\CampusOnlineStatistik;
  6. use App\Entity\CampusSeitenStatistik;
  7. use App\Repository\BuchungenRepository;
  8. use App\Repository\CampusOnlineStatistikRepository;
  9. use App\Repository\CampusSeitenStatistikRepository;
  10. use App\Repository\ChatRepository;
  11. use App\Repository\FirmenGruppenRepository;
  12. use App\Repository\FirmenMitgliederanfrageRepository;
  13. use App\Repository\FirmenProjekteAufgabenUserRepository;
  14. use App\Repository\FirmenProjekteAufgabenUserStundenRepository;
  15. use App\Repository\UserFavoritenRepository;
  16. use App\Repository\UserNotificationRepository;
  17. use App\Repository\UserRepository;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\RequestStack;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. class NotificationController extends AbstractController
  26. {
  27.     #[Route('/notification/message'name'notification_message')]
  28.     public function index(UserNotificationRepository        $notificationRepository,
  29.                           FirmenMitgliederanfrageRepository $firmenMitgliederanfrageRepository,
  30.                           UserBasisController               $userBasisController,
  31.                           BuchungenRepository               $buchungenRepository,
  32.                           UserRepository                    $userRepository,
  33.                           EntityManagerInterface            $entityManager): Response
  34.     {
  35.         $userId $this->getUser()?->getId();
  36.         $notifications null;
  37.         $buchungsanfragen null;
  38.         $notificationsNeueMitglieder null;
  39.         if ($userId != null) {
  40.             $notifications $notificationRepository->findBy(['user' => $userId], ['datum' => 'DESC']);
  41.             $notificationsNeueMitglieder $firmenMitgliederanfrageRepository->findBy(['firma' => $this->getUser()->getFirmenProfil()]);
  42.         }
  43.         if (in_array("ROLE_FIRMA_ADMIN_SCHULUNG_ANFRAGEN"$this->getUser()->getRoles())) {
  44.             $buchungsanfragen $buchungenRepository->findBy(['bezahlstatus' => 9'firma' => $this->getUser()->getFirmenProfil()]);
  45.         }
  46.         $user $userRepository->findOneBy(['id' => $userId]);
  47.         if (!$this->isGranted('IS_IMPERSONATOR')) {
  48.             $user->setLetzterLogin(new \DateTime('now', new \DateTimeZone('Europe/Berlin')));
  49.         }
  50.         $entityManager->persist($user);
  51.         $entityManager->flush();
  52.         return $this->render('nav/admin_topbar_notification.html.twig', [
  53.             'lable' => $userBasisController->getLableInternerBereich(),
  54.             'buchungsanfragen' => $buchungsanfragen,
  55.             'notifications' => $notifications,
  56.             'notificationsNeueMitglieder' => $notificationsNeueMitglieder,
  57.         ]);
  58.     }
  59.     #[Route('/notification/message/user'name'notification_message_user')]
  60.     public function notification_message_user(Request                         $request,
  61.                                               UserNotificationRepository      $notificationRepository,
  62.                                               UserRepository                  $userRepository,
  63.                                               UserBasisController             $userBasisController,
  64.                                               UserFavoritenRepository         $userFavoritenRepository,
  65.                                               CampusSeitenStatistikRepository $campusSeitenStatistikRepository,
  66.                                               FirmenProjekteAufgabenUserRepository $firmenProjekteAufgabenUserRepository,
  67.                                               FirmenProjekteAufgabenUserStundenRepository $firmenProjekteAufgabenUserStundenRepository,
  68.                                               EntityManagerInterface          $entityManager): Response
  69.     {
  70.         $datum = new \DateTime('now', new \DateTimeZone('Europe/Berlin'));
  71.         $userId $this->getUser()?->getId();
  72.         $firmaId $this->getUser()?->getFirmenProfil()?->getId();
  73.         $notifications null;
  74.         $favoritenanzahl 0;
  75.         $notificationProjekte = [];
  76.         $notificationProjekteTimer null;
  77.         if ($userId != null) {
  78.             $notifications $notificationRepository->findBy(['user' => $userId], ['datum' => 'DESC']);
  79.             $favoritenanzahl count($userFavoritenRepository->findBy(['user_id' => $userId]));
  80.             $user $userRepository->findOneBy(['id' => $userId]);
  81.             if (!$this->isGranted('IS_IMPERSONATOR')) {
  82.                 $user->setLetzterLogin($datum);
  83.             }
  84.             $entityManager->persist($user);
  85.             $entityManager->flush();
  86.             $url $request->get('url');
  87.             $domain $_ENV["WEBSITE_URL"];
  88.             /*
  89.             $domain = 'https://campus.test';
  90.             */
  91.             // TODO: Seitenstatistik zur Zeit abgeschalten
  92.             if ($userId == 0) {
  93.                 if (!$this->isGranted('IS_IMPERSONATOR') && !in_array("ROLE_CELSEO_MASTERADMIN"$this->getUser()->getRoles())) {
  94.                     if (strlen($url) > && str_contains($url$domain)) {
  95.                         $speichern true;
  96.                         $letzteStatistik $campusSeitenStatistikRepository->findOneBy(['user_id' => $userId], ['datum' => 'DESC']);
  97.                         if ($letzteStatistik == null || $letzteStatistik->getUrl() != $url) {
  98.                             if ($url == $domain '/' || $url == $domain '/login') {
  99.                                 $speichern false;
  100.                             }
  101.                             if ($url == $domain '/user/konfigurator/auswahl' || $url == $domain '/user/firma/startseite/0/info') {
  102.                                 $speichern false;
  103.                             }
  104.                             if ($url == $domain '/user/profil/mein_profil/info/bearbeiten' || $url == $domain '/user/firma/startseite/0/info') {
  105.                                 $speichern false;
  106.                             }
  107.                             if ($speichern) {
  108.                                 $campusStatistik = new CampusSeitenStatistik();
  109.                                 $campusStatistik->setUserId($userId);
  110.                                 $campusStatistik->setFirmaId($firmaId);
  111.                                 $campusStatistik->setUrl($request->get('url'));
  112.                                 $campusStatistik->setDatum($datum);
  113.                                 if ($request->getSession()->get('appUser')) {
  114.                                     $campusStatistik->setOberflaeche('App');
  115.                                 } else {
  116.                                     $campusStatistik->setOberflaeche('Browser');
  117.                                 }
  118.                                 $entityManager->persist($campusStatistik);
  119.                                 $entityManager->flush();
  120.                             }
  121.                         }
  122.                     }
  123.                 }
  124.             }
  125.             // Campus Online Statistik
  126.            /* $this->session = $requestStack->getSession();
  127.             $this->session->start();
  128.             if ($this->session->get('online_datum') == null || $this->session->get('online_datum') != $datum->format('Y-m-d') . '-' . $userId) {
  129.                 $onlineStatistik = $campusOnlineStatistikRepository->findOneBy(['datum' => $datum]);
  130.                 if ($onlineStatistik == null) {
  131.                     $onlineStatistik = new CampusOnlineStatistik();
  132.                     $onlineStatistik->setDatum($datum);
  133.                     $onlineStatistik->setUsers('[' . $userId . ']');
  134.                 } else {
  135.                     $alleUser = json_decode($onlineStatistik->getUsers(),true);
  136.                     if (!in_array($userId, $alleUser)) {
  137.                         $alleUser[] = $userId;
  138.                     }
  139.                     $onlineStatistik->setUsers(json_encode($alleUser));
  140.                 }
  141.                 $entityManager->persist($onlineStatistik);
  142.                 $entityManager->flush();
  143.                 $this->session->set('online_datum',  $datum->format('Y-m-d') . '-' . $userId);
  144.             }*/
  145.             //$allgemeineFunktionenController->getOnlineStatistik();
  146.             $notificationProjekte $firmenProjekteAufgabenUserRepository->findAlleUngelesenenStellen($userId$firmaId);
  147.             $notificationProjekteTimer $firmenProjekteAufgabenUserStundenRepository->findArbeitsstundenOffenerTimer($this->getUser()->getId());
  148.         }
  149.         return $this->render('nav/user_navigation_notification.html.twig', [
  150.             'lable' => $userBasisController->getLableInternerBereich(),
  151.             'notifications' => $notifications,
  152.             'anzahlNotificationProjekte' => count($notificationProjekte),
  153.             'notificationProjekteTimer' => $notificationProjekteTimer,
  154.             'favoritenanzahl' => $favoritenanzahl,
  155.         ]);
  156.     }
  157.     #[Route('/notification/chat/loeschen'name'notification_chat_loeschen')]
  158.     public function notificationChatLoeschen(Request $request,
  159.                                              ChatRepository $chatRepository,
  160.                                              UserNotificationRepository $notificationRepository,
  161.                                              EntityManagerInterface $entityManager): Response
  162.     {
  163.         $sender $request->get('sender');
  164.         $gruppenID $request->get('gruppenID');
  165.         $userId $this->getUser()?->getId();
  166.             $notifications $notificationRepository->findBy(['user' => $userId'type' => 2'von_user_id' => $sender'link' => $gruppenID]);
  167.             foreach ($notifications as $notification) {
  168.                 $entityManager->remove($notification);
  169.                 $entityManager->flush();
  170.             }
  171.             if ($gruppenID == -1) {
  172.             $chatMessages $chatRepository->findBy(['user_id' => $sender'chatpartner_id' => $userId'gelesen' => 0]);
  173.             foreach ($chatMessages as $message) {
  174.                 $message->setGelesen(1);
  175.                 $entityManager->persist($message);
  176.                 $entityManager->flush();
  177.             }
  178.         }
  179.         $returnData['error'] = false;
  180.         return new JsonResponse($returnData);
  181.     }
  182.     #[Route('/notification/chat/abfragen'name'notification_chat_abfragen')]
  183.     public function notification_chat_abfragen(Request $request,
  184.                                                FirmenGruppenRepository $firmenGruppenRepository,
  185.                                                UserRepository $userRepository,
  186.                                                UserNotificationRepository $notificationRepository,
  187.                                                EntityManagerInterface $entityManager,
  188.                                                UserBasisController $userBasisController,
  189.                                                ChatRepository $chatRepository): Response
  190.     {
  191.         $ungelesen false;
  192.         $chatPartnerId $request->get('chatPartner');
  193.         $type $request->get('type');
  194.         $userId $this->getUser()->getId();
  195.         $lastChatID $request->get('lastChatID');
  196.         $fehlendesChatHTML'';
  197.         $meinProfilbild $this->getUser()->getUserProfil()->getProfilbild();
  198.         if ($meinProfilbild != null) {
  199.             $meinBild $this->generateUrl('admin_user_profilbild', ['id' => $userId]) . '?v=' $meinProfilbild;
  200.         } else {
  201.             $meinBild $this->generateUrl('admin_user_profilbild', ['id' => 0]);
  202.         }
  203.         if($type === 'single') {
  204.             $notification $notificationRepository->findOneBy(['user' => $chatPartnerId'type' => 2'link' => '-1''von_user_id' => $userId'gelesen' => 0]);
  205.             if ($notification != null) {
  206.                 $ungelesen true;
  207.             }
  208.             $meineNotification $notificationRepository->findOneBy(['user' => $userId'type' => 2'link' => '-1''von_user_id' => $chatPartnerId'gelesen' => 0]);
  209.             if ($meineNotification != null) {
  210.                 $entityManager->remove($meineNotification);
  211.                 $entityManager->flush();
  212.             }
  213.             $lastChatMessage $chatRepository->findLetzteChatnachricht($userId$chatPartnerId);
  214.             if (count($lastChatMessage) > 0) {
  215.                 $neusteChatID $lastChatMessage[0]->getId();
  216.                 if($lastChatID $neusteChatID) {
  217.                     $chatMessages $chatRepository->getFehlendeChatForUser($userId$chatPartnerId$lastChatID);
  218.                     $userAnsprechpartner $userRepository->findOneBy(['id' => $chatPartnerId]);
  219.                     $ansprechpartnerProfilbild $userAnsprechpartner->getUserProfil()->getProfilbild();
  220.                     if ($ansprechpartnerProfilbild != null) {
  221.                         $ansprechpartnerBild $this->generateUrl('user_profilbild_laden', ['id' => $chatPartnerId]) . '?v=' $ansprechpartnerProfilbild;
  222.                     } else {
  223.                         $ansprechpartnerBild $this->generateUrl('user_profilbild_laden', ['id' => 0]);
  224.                     }
  225.                     foreach ($chatMessages as $chatMessage) {
  226.                         $selfMessage false;
  227.                         $chatGelesen = -1;
  228.                         if ($chatMessage->getUserId() == $userId) {
  229.                             $senderName $this->getUser()->getUserProfil()->getVorname() . ' ' $this->getUser()->getUserProfil()->getNachname();
  230.                             $selfMessage true;
  231.                             $profilBildLink $meinBild;
  232.                             $chatGelesen $chatMessage->getGelesen();
  233.                         } else {
  234.                             $senderName $userAnsprechpartner->getUserProfil()->getVorname() . ' ' $userAnsprechpartner->getUserProfil()->getNachname();
  235.                             $profilBildLink $ansprechpartnerBild;
  236.                             if ($chatMessage->getGelesen() == 0) {
  237.                                 $chatMessage->setGelesen(1);
  238.                                 $entityManager->persist($chatMessage);
  239.                                 $entityManager->flush();
  240.                             }
  241.                         }
  242.                         $nachricht $chatMessage->getNachricht();
  243.                         $zeit $chatMessage->getGesendetAm()->format('H:i');
  244.                         //$fehlendesChatHTML .= $userBasisController->getUserBC_Chateintrag($senderName, $selfMessage, $profilBildLink, $nachricht, $zeit, null, $chatMessage->getId(), $chatGelesen, $chatMessage->getDateiname());
  245.                         $fehlendesChatHTML .= $userBasisController->getUserBC_Chateintrag2($chatMessage->getId(), null);
  246.                     }
  247.                 }
  248.             }
  249.         } else {
  250.             $firmenGruppe $firmenGruppenRepository->findOneBy(['id' => $chatPartnerId]);
  251.             $lastChatMessage $chatRepository->findOneBy(['gruppe' => $firmenGruppe], ['gesendet_am' => 'DESC']);
  252.             if ($lastChatMessage != null) {
  253.                 $neusteChatID $lastChatMessage->getId();
  254.                 if($lastChatID $neusteChatID) {
  255.                     $chatMessages $chatRepository->getFehlendeChatForGroup($chatPartnerId$lastChatID);
  256.                     foreach ($chatMessages as $chatMessage) {
  257.                         $userAnsprechpartner $userRepository->findOneBy(['id' => $chatMessage->getUserId()]);
  258.                         $ansprechpartnerProfilbild $userAnsprechpartner->getUserProfil()->getProfilbild();
  259.                         if ($ansprechpartnerProfilbild != null) {
  260.                             $ansprechpartnerBild $this->generateUrl('user_profilbild_laden', ['id' => $userAnsprechpartner->getId()]) . '?v=' $ansprechpartnerProfilbild;
  261.                         } else {
  262.                             $ansprechpartnerBild $this->generateUrl('user_profilbild_laden', ['id' => 0]);
  263.                         }
  264.                         $senderName =  $userAnsprechpartner->getUserProfil()->getVorname() . ' ' $userAnsprechpartner->getUserProfil()->getNachname();
  265.                         $selfMessage $chatMessage->getUserId() == $userId;
  266.                         $profilBildLink $ansprechpartnerBild;
  267.                     /*    $selfMessage = false;
  268.                         if ($chatMessage->getUserId() == $userId) {
  269.                             $senderName = $this->getUser()->getUserProfil()->getVorname() . ' ' . $this->getUser()->getUserProfil()->getNachname();
  270.                             $selfMessage = true;
  271.                             $profilBildLink = $meinBild;
  272.                         } else {
  273.                             $senderName = $userAnsprechpartner->getUserProfil()->getVorname() . ' ' . $userAnsprechpartner->getUserProfil()->getNachname();
  274.                             $profilBildLink = $ansprechpartnerBild;
  275.                         }*/
  276.                         $nachricht $chatMessage->getNachricht();
  277.                         $zeit $chatMessage->getGesendetAm()->format('H:i');
  278.                         //$fehlendesChatHTML .= $userBasisController->getUserBC_Chateintrag($senderName, $selfMessage, $profilBildLink, $nachricht, $zeit, null, $chatMessage->getId(), -1,$chatMessage->getDateiname());
  279.                         $fehlendesChatHTML .= $userBasisController->getUserBC_Chateintrag2($chatMessage->getId(), null);
  280.                     }
  281.                 }
  282.             }
  283.         }
  284.         $returnData['ungelesen'] = $ungelesen;
  285.         $returnData['fehlenderChat'] = $fehlendesChatHTML;
  286.         return new JsonResponse($returnData);
  287.     }
  288.     #[Route('/notification/chat/letzte_chat_id'name'notification_chat_letzte_chat_id')]
  289.     public function notification_chat_letzte_chat_id(Request $request,
  290.                                                      ChatRepository $chatRepository): Response
  291.     {
  292.         $neueChatId 0;
  293.         $chatPartner $request->get('chatPartner');
  294.         $userId $this->getUser()?->getId();
  295.         $chatMessage $chatRepository->findOneBy(['user_id' => $userId'chatpartner_id' => $chatPartner], ['gesendet_am' => 'DESC']);
  296.         if ($chatMessage != null) {
  297.             $neueChatId $chatMessage->getId();
  298.         }
  299.         $returnData['neueChatId'] = $neueChatId;
  300.         return new JsonResponse($returnData);
  301.     }
  302.     #[Route('/notification/alles/loeschen'name'notification_alles_loeschen'methods: ['GET'])]
  303.     public function notificationAllesLoeschen(Request $requestUserNotificationRepository $notificationRepositoryEntityManagerInterface $entityManager): Response
  304.     {
  305.         $notifications $notificationRepository->findBy(['user' => $this->getUser()?->getId()]);
  306.         if ($notifications != null) {
  307.             foreach ($notifications as $notification) {
  308.                 $entityManager->remove($notification);
  309.                 $entityManager->flush();
  310.             }
  311.         }
  312.         $returnData['error'] = false;
  313.         return new JsonResponse($returnData);
  314.     }
  315. }