src/Controller/MyEurovisionController.php line 527

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Business\Equipment;
  4. use App\Business\EventCategoryProvider;
  5. use App\Business\Feedback;
  6. use App\Business\WorkOrderEditContainer;
  7. use App\Entity\Callback;
  8. use App\Entity\UserPreference;
  9. use App\Extern\XrmService;
  10. use App\Form\EquipmentType;
  11. use App\Form\FeedbackType;
  12. use App\Form\MyPreferencesType;
  13. use App\Form\WorkOrderEditContainerType;
  14. use App\Form\Type\BusinessUserType;
  15. use App\Security\OauthAuthenticator;
  16. use App\Security\TokenAuthenticator;
  17. use App\Services\BookingService;
  18. use App\Services\CallbackService;
  19. use App\Services\CompanyRegistrationService;
  20. use App\Services\CustomerOrderService;
  21. use App\Services\DashboardService;
  22. use App\Services\DomainService;
  23. use App\Services\EquipmentService;
  24. use App\Services\EventFollowerService;
  25. use App\Services\EventService;
  26. use App\Services\FreelancerPortalService;
  27. use App\Services\NewslettersService;
  28. use App\Services\NotificationSenderHelperService;
  29. use App\Services\ProviderService;
  30. use App\Services\UserService;
  31. use App\Utils\Helper;
  32. use App\Utils\JsonResponseHelper;
  33. use App\Utils\OperationResult;
  34. use App\Enum\FlashType;
  35. use App\Services\ActionLoggerService;
  36. use Exception;
  37. use FOS\RestBundle\Controller\Annotations\Get;
  38. use Knp\Snappy\Pdf;
  39. use Psr\Log\LoggerInterface;
  40. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  41. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  42. use Symfony\Component\HttpFoundation\File\UploadedFile;
  43. use Symfony\Component\HttpFoundation\JsonResponse;
  44. use Symfony\Component\HttpFoundation\Request;
  45. use Symfony\Component\HttpFoundation\Response;
  46. use Symfony\Component\Routing\Annotation\Route;
  47. use Symfony\Component\Security\Core\Security as SecurityInterface;
  48. use Throwable;
  49. class MyEurovisionController extends AbstractController
  50. {
  51.     /** @var EventFollowerService $eventFollowerService */
  52.     protected $eventFollowerService;
  53.     /** @var UserService $userService */
  54.     protected $userService;
  55.     /** @var XrmService $xrmService */
  56.     protected $xrmService;
  57.     /** @var EquipmentService $equipmentService */
  58.     protected $equipmentService;
  59.     /** @var SecurityInterface security */
  60.     private $security;
  61.     /** @var  NewslettersService $newslettersService */
  62.     private $newslettersService;
  63.     /** @var  BookingService $bookingService */
  64.     private $bookingService;
  65.     /** @var  CustomerOrderService $customerOrderService */
  66.     private $customerOrderService;
  67.     /** @var  DomainService $domainService */
  68.     private $domainService;
  69.     /** @var  CallbackService $callbackService */
  70.     private $callbackService;
  71.     /** @var  DashboardService $dashboardService */
  72.     private $dashboardService;
  73.     /** @var EventService $eventService */
  74.     private $eventService;
  75.     /** @var NotificationSenderHelperService $notificationSenderHelperService */
  76.     protected $notificationSenderHelperService;
  77.     protected OauthAuthenticator $authenticator;
  78.     protected TokenAuthenticator $tokenManager;
  79.     private ActionLoggerService $actionLoggerService;
  80.     /**
  81.      * MyEurovisionController constructor.
  82.      *
  83.      * @param SecurityInterface $security
  84.      * @param NewslettersService $newslettersService
  85.      * @param EventFollowerService $eventFollowerService
  86.      * @param UserService $userService
  87.      * @param BookingService $bookingService
  88.      * @param CustomerOrderService $eventRhsBookingService
  89.      * @param DomainService $domainService
  90.      * @param CallbackService $callbackService
  91.      * @param DashboardService $dashboardService
  92.      * @param EquipmentService $equipmentService
  93.      * @param EventService $eventService
  94.      * @param NotificationSenderHelperService $notificationSenderHelperService
  95.      * @param OAuthAuthenticator $authenticator
  96.      * @param TokenAuthenticator $tokenManager
  97.      * @param ActionLoggerService $actionLoggerService
  98.      */
  99.     public function __construct(
  100.         SecurityInterface               $security,
  101.         NewslettersService              $newslettersService,
  102.         EventFollowerService            $eventFollowerService,
  103.         UserService                     $userService,
  104.         BookingService                  $bookingService,
  105.         CustomerOrderService            $eventRhsBookingService,
  106.         DomainService                   $domainService,
  107.         CallbackService                 $callbackService,
  108.         DashboardService                $dashboardService,
  109.         XrmService                      $xrmService,
  110.         EquipmentService                $equipmentService,
  111.         EventService                    $eventService,
  112.         NotificationSenderHelperService $notificationSenderHelperService,
  113.         OAuthAuthenticator              $authenticator,
  114.         TokenAuthenticator              $tokenManager,
  115.         ActionLoggerService             $actionLoggerService
  116.     )
  117.     {
  118.         $this->security $security;
  119.         $this->newslettersService $newslettersService;
  120.         $this->eventFollowerService $eventFollowerService;
  121.         $this->userService $userService;
  122.         $this->bookingService $bookingService;
  123.         $this->customerOrderService $eventRhsBookingService;
  124.         $this->domainService $domainService;
  125.         $this->callbackService $callbackService;
  126.         $this->dashboardService $dashboardService;
  127.         $this->xrmService $xrmService;
  128.         $this->equipmentService $equipmentService;
  129.         $this->eventService $eventService;
  130.         $this->notificationSenderHelperService $notificationSenderHelperService;
  131.         $this->authenticator $authenticator;
  132.         $this->tokenManager $tokenManager;
  133.         $this->actionLoggerService  $actionLoggerService;
  134.     }
  135.     /**
  136.      * @Route("/myeurovision/test-upload-sharepoint", name="test_upload_sharepoint", options={"expose" = true })
  137.      */
  138.     public function testUploadSharepointAction(Request $request){
  139.         $this->xrmService->uploadDocumentToSharePoint("tochange"'/var/www/html''testupload.txt',); #TODO TEST AND REMOVE
  140.     }
  141.     /**
  142.      * @Route("/myeurovision/profile", name="my_profile", options={"expose" = true })
  143.      * @Security("is_granted('ROLE_USER')")
  144.      */
  145.     public function myProfileAction(Request $request)
  146.     {
  147.         //$user = $this->getUser();
  148.         $user $this->userService->getUserMainInformation($this->getUser()->getUid());
  149.         $user->companyCityComplete $user->companyCity;
  150.         if (empty($user->companyCityComplete)) {
  151.             $userOrganization $this->domainService->getOrganizationDetailsCurrentUser();
  152.             if (!empty($userOrganization)) {
  153.                 $city $this->domainService->getCity($userOrganization->cityCode);
  154.                 if ($city != null && $city->getName() != null) {
  155.                     $user->companyCityComplete $city->getName();
  156.                 }
  157.             }
  158.         }
  159.         $userPreference $this->dashboardService->getUserPreference($user->getUid());
  160.         if (!$userPreference) {
  161.             $userPreference = new UserPreference();
  162.         }
  163.         $userPreferenceForm $this->createForm(MyPreferencesType::class, $userPreference);
  164.         $userPreferenceForm->handleRequest($request);
  165.         $userInformationsForm $this->createForm(BusinessUserType::class, $user);
  166.         $userInformationsForm->handleRequest($request);
  167.         // Get user company from XRM
  168.         if ($user->getCompanyCodeOps()) {
  169.             $xrmCompany $this->xrmService->getOrganization($user->getcompanyCodeOps());
  170.         }
  171.         $parts explode('@'$user->getEmail());
  172.         $domain array_pop($parts);
  173.         $emailDomainOrganizations $this->xrmService->getOrganizationsRelatedToSpecificEmailDomainOrCodeOps($domain$user->getCompanyCodeOps());
  174.         $this->userService->clearCache($user->getUid());
  175.         return $this->render(
  176.             'my_eurovision/my_profile.html.twig',
  177.             [
  178.                 'user' => $user,
  179.                 'company' => (isset($xrmCompany) ? $xrmCompany null),
  180.                 'emailDomainOrganizations' => $emailDomainOrganizations,
  181.                 'preferenceForm' => $userPreferenceForm->createView(),
  182.                 'userInformationsForm' => $userInformationsForm->createView(),
  183.                 'location' => 'My Profile'
  184.             ]
  185.         );
  186.     }
  187.     /**
  188.      * @Route("/myeurovision/profile/revoke/password", name="my_profile_revoke_password", options={"expose" = true })
  189.      * @Security("is_granted('ROLE_USER')")
  190.      * @param Request $request
  191.      * @return JsonResponse
  192.      */
  193.     public function revokePassword(Request $request)
  194.     {
  195.         $result $this->userService->revokeSelfUserPassword();
  196.         if ($result["status"] === "success") {
  197.             return new JsonResponse($result);
  198.         } else {
  199.             return new JsonResponse($resultResponse::HTTP_INTERNAL_SERVER_ERROR);
  200.         }
  201.     }
  202.     /**
  203.      * @Route("/myeurovision/profile/revoke/session", name="my_profile_revoke_session", options={"expose" = true })
  204.      * @Security("is_granted('ROLE_USER')")
  205.      * @param Request $request
  206.      * @return JsonResponse
  207.      */
  208.     public function revokeSession(Request $request)
  209.     {
  210.         $result $this->userService->revokeSelfUserSession();
  211.         $this->tokenManager->refreshToken($this->getUser());
  212.         return new JsonResponse($result);
  213.     }
  214.     /**
  215.      * @Route("/myeurovision/profile/check/session", name="my_profile_check_session", options={"expose" = true })
  216.      * @Security("is_granted('ROLE_USER')")
  217.      * @param Request $request
  218.      * @return JsonResponse
  219.      */
  220.     public function checkSession(Request $request)
  221.     {
  222.         $result $this->authenticator->canChangeEmail($this->getUser());
  223.         return new JsonResponse($result);
  224.     }
  225.     /**
  226.      * @Route("/myeurovision/profile/change/email", name="my_profile_change_email", options={"expose" = true },methods={"POST"})
  227.      * @Security("is_granted('ROLE_USER')")
  228.      * @param Request $request
  229.      * @return JsonResponse
  230.      */
  231.     public function changeEmail(Request $request)
  232.     {
  233.         $email $request->get('email');
  234.         if(!$this->authenticator->canChangeEmail($this->getUser())){
  235.             return new JsonResponse(['status' => 'error''message' => 'You can not change your email'], JsonResponse::HTTP_FORBIDDEN);
  236.         }
  237.         $result $this->userService->changeUserEmail($email);
  238.         if($result->getStatus() === 'success'){
  239.             $this->userService->clearCache($this->getUser()->getUid());
  240.             return new JsonResponse($result->getData());
  241.         } else {
  242.             return new JsonResponse($result->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  243.         }
  244.         return new JsonResponse($result);
  245.     }
  246.     /**
  247.      * @Route("/myeurovision/profile/edit", name="my_profile_edit", options={"expose" = true })
  248.      * @Security("is_granted('ROLE_USER')")
  249.      */
  250.     public function editProfile(Request $request)
  251.     {
  252.         $user $this->getUser();
  253.         $userInformationsForm $this->createForm(BusinessUserType::class, $user);
  254.         $userInformationsForm->handleRequest($request);
  255.         if ($userInformationsForm->isSubmitted() && $userInformationsForm->isValid()) {
  256.             $response $this->userService->updateUser($user);
  257.             $this->userService->clearCache($user->getUid());
  258.             // Wait 5 seconds to be sure MS is refreshed
  259.             sleep(5);
  260.             $data = [
  261.                 "user" => [
  262.                     'firstName' => $user->getFirstName(),
  263.                     'lastName' => $user->getLastName(),
  264.                     'email' => $user->getEmail(),
  265.                     'businessMobilePhone' => $user->getBusinessMobilePhone(),
  266.                     'businessOfficePhone' => $user->getBusinessOfficePhone(),
  267.                     'faxPhone' => $user->getFaxPhone(),
  268.                     'jobTitle' => $user->getJobTitle(),
  269.                     'department' => $user->getDepartment(),
  270.                     'address' => $user->getAddress(),
  271.                     'postalCode' => $user->getPostalCode(),
  272.                     'country' => $user->getCountry(),
  273.                 ]
  274.             ];
  275.             if ($response["status"] === "success") {
  276.                 $data["message"] = "User updated successfully";
  277.                 return new JsonResponse($data);
  278.             } else {
  279.                 $data["message"] = "Error in updating user: " $response["message"];
  280.                 return new JsonResponse($data["message"], JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  281.             }
  282.         } else if ($userInformationsForm->isSubmitted()) {
  283.             $errors Helper::getErrorMessagesFlat($userInformationsFormtrue);
  284.             $data['message'] = "Please, check errors in the user form";
  285.             $data['errors'] = $errors;
  286.             $jsonResponse $this->json($dataJsonResponse::HTTP_BAD_REQUEST);
  287.             return $jsonResponse;
  288.         }
  289.         return new JsonResponse('Error'Response::HTTP_INTERNAL_SERVER_ERROR);
  290.     }
  291.     /**
  292.      * @Route("/myeurovision", name="my_eurovision")
  293.      * @Route("/myeurovision/", name="my_eurovision_slash")
  294.      * @Security("is_granted('ROLE_USER')")
  295.      */
  296.     public function myEurovisionHomepageAction(Request $request)
  297.     {
  298.         $errorMessage $request->get('errorMessage');
  299.         $user $this->getUser();
  300.         $upcomingEvents $this->eventService->getUpcomingEvents(5null);
  301.         $userEvents $this->eventFollowerService->getEventsFollowedByCurrentUser();
  302.         $events $this->eventService->getEventsByType("ALL", ['date' => 'year'], null);
  303.         $userSubs $this->newslettersService->getCurrentUserInterests();
  304.         $newslettersCategories $this->newslettersService->getAllNewslettersEventCategories();
  305.         $nbNewsletters 0;
  306.         foreach ($newslettersCategories as $nlCateg) {
  307.             $nbNewsletters $nbNewsletters count($nlCateg->getGroups() ?? []);
  308.         }
  309.         $arrayNbSubs = [];
  310.         foreach ($newslettersCategories as $nlCateg) {
  311.             $currentCptGroup 0;
  312.             foreach ($nlCateg->getGroups() as $group) {
  313.                 if (in_array($group->getExternGroupId(), $userSubs)) {
  314.                     $currentCptGroup++;
  315.                 }
  316.             }
  317.             $arrayNbSubs[$nlCateg->getExternGroupId()]['externId'] = $nlCateg->getExternGroupId();
  318.             $arrayNbSubs[$nlCateg->getExternGroupId()]['title'] = $nlCateg->getTitle();
  319.             $arrayNbSubs[$nlCateg->getExternGroupId()]['hint'] = $currentCptGroup " OF " count($nlCateg->getGroups() ?? []) . " SUBSCRIBED";
  320.         }
  321.         $res $this->customerOrderService->getCustomersOrders(null);
  322.         $customerOrders $res->getData();
  323.         $lastCustomerOrders array_slice($customerOrders06);
  324.         return $this->render(
  325.             'my_eurovision/my_eurovision_homepage.html.twig',
  326.             [
  327.                 'errorMessage' => $errorMessage,
  328.                 'location' => 'My Orders',
  329.                 'user' => $user,
  330.                 'newslettersCategories' => $newslettersCategories,
  331.                 'userSubs' => $userSubs,
  332.                 'arrayNbSubs' => $arrayNbSubs,
  333.                 'upcomingEvents' => $upcomingEvents,
  334.                 'nbUserEvents' => count($userEvents ?? []),
  335.                 'nbEvents' => count($events ?? []),
  336.                 'nbUserSubscriptions' => count($userSubs ?? []),
  337.                 'nbNewsletters' => $nbNewsletters,
  338.                 'customerOrdersDetails' => $lastCustomerOrders
  339.             ]
  340.         );
  341.     }
  342.     /**
  343.      * @Route("/myeurovision/orders", name="my_orders", options={"expose" = true })
  344.      * @Security("is_granted('ROLE_USER')")
  345.      */
  346.     public function myBookingsAction(Request $request)
  347.     {
  348.         $errorMessage $request->get('errorMessage');
  349.         $view = (!empty($request->get('view'))) ? $request->get('view') : 'thumbnail';
  350.         $period = (!empty($request->get('period'))) ? $request->get('period') : 'month';
  351.         $res $this->customerOrderService->getCustomersOrdersByPeriod($period);
  352.         $totalOrders count($res->getData() ?? []);
  353.         return $this->render(
  354.             'my_eurovision/my_bookings.html.twig',
  355.             [
  356.                 'user' => $this->getUser(),
  357.                 'errorMessage' => $errorMessage,
  358.                 'location' => 'My Orders',
  359.                 'view' => $view,
  360.                 'period' => $period,
  361.                 'totalOrders' => $totalOrders
  362.             ]
  363.         );
  364.     }
  365.     /**
  366.      * @Security("is_granted('ROLE_USER')")
  367.      * @Route("/intern/myeurovision/preferences/submit", name="my_preferences_submit", options={"expose" = true})
  368.      * @param Request $request
  369.      * @return Response
  370.      */
  371.     public function submitMyPreferences(Request $request)
  372.     {
  373.         try {
  374.             $uid $this->getUser()->getUid();
  375.             $userPreference $this->dashboardService->getUserPreference($uid);
  376.             if (!$userPreference) {
  377.                 $userPreference = new UserPreference();
  378.             }
  379.             $userPreferenceForm $this->createForm(MyPreferencesType::class, $userPreference);
  380.             $userPreferenceForm->handleRequest($request);
  381.             $result $this->dashboardService->saveAllUserPreference($uid$userPreference);
  382.             return new JsonResponse($result);
  383.         } catch (Throwable $ex) {
  384.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  385.         }
  386.     }
  387.     /**
  388.      * @Route("/myeurovision/callbacks", name="my_callbacks", options={"expose" = true })
  389.      * @Security("is_granted('ROLE_USER')")
  390.      */
  391.     public function myCallbacksAction(Request $request)
  392.     {
  393.         $userInformation $this->getUser();
  394.         if (empty($userInformation->getCompanyCodeOps())) {
  395.             return $this->redirectToRoute('eurovision_no_booking_authorized');
  396.         }
  397.         $callbackNotification $this->callbackService->getCallbackByOrganizationCode($userInformation->getCompanyCodeOps());
  398.         $synopsisNotifications $this->callbackService->getCallbackByOrganizationCodeByType($userInformation->getCompanyCodeOps(), Callback::SYNOPSIS);
  399.         $requestNotifications $this->callbackService->getCallbackByOrganizationCodeByType($userInformation->getCompanyCodeOps(), Callback::REQUEST);
  400.         return $this->render(
  401.             'my_eurovision/my_callbacks.html.twig',
  402.             [
  403.                 'location' => 'My Callbacks',
  404.                 'user' => $userInformation,
  405.                 'organizationCode' => $userInformation->getCompanyCodeOps(),
  406.                 'callbackNotifications' => $callbackNotification,
  407.                 'synopsisNotifications' => $synopsisNotifications,
  408.                 'requestNotifications' => $requestNotifications
  409.             ]
  410.         );
  411.     }
  412.     /**
  413.      * Save callback url
  414.      * @Route("/intern/callback/url/new", name="callback_add_new_url", options={"expose"=true})
  415.      *
  416.      * @param Request $request
  417.      * @return JsonResponse
  418.      */
  419.     public function saveCallbackAction(Request $request)
  420.     {
  421.         $res $this->callbackService->addNewCallbackUrl($request->request->all());
  422.         return new JsonResponse([
  423.             'message' => $res->getMessage(),
  424.             'status' => $res->getStatus(),
  425.             'data' => $res->getData(),
  426.         ]);
  427.     }
  428.     /**
  429.      * update callback url
  430.      * @Route("/intern/callback/url/update/{callbackId}", name="callback_update_url", options={"expose"=true})
  431.      *
  432.      * @param Request $request
  433.      * @param string $callbackId
  434.      * @return JsonResponse
  435.      */
  436.     public function updateCallbackUrl(Request $requeststring $callbackId)
  437.     {
  438.         $res $this->callbackService->updateCallbackUrl($callbackId$request->request->all());
  439.         return new JsonResponse([
  440.             'message' => $res->getMessage(),
  441.             'status' => $res->getStatus(),
  442.             'data' => $res->getData(),
  443.         ]);
  444.     }
  445.     /**
  446.      * delete callback url
  447.      * @Route("/intern/callback/delete/{callbackId}", name="delete_notification", options={"expose"=true})
  448.      *
  449.      * @param Request $request
  450.      * @param string $callbackId
  451.      * @return JsonResponse
  452.      */
  453.     public function deleteCallbackAction(Request $requeststring $callbackId)
  454.     {
  455.         $res $this->callbackService->deleteCallbackUrl($callbackId);
  456.         return new JsonResponse([
  457.             'message' => $res->getMessage(),
  458.             'status' => $res->getStatus(),
  459.             'data' => $res->getData(),
  460.         ]);
  461.     }
  462.     /**
  463.      * @Route("/myeurovision/myevents", name="my_events", options={"expose" = true })
  464.      * @Security("is_granted('ROLE_USER')")
  465.      * @return Response
  466.      */
  467.     public function myEventsAction(Request $request)
  468.     {
  469.         $byEmail = (!empty($request->get('byEmail'))) ? $request->get('byEmail') : false;
  470.         $userEvents $this->eventFollowerService->getEventsFollowedByCurrentUser();
  471.         return $this->render(
  472.             'my_eurovision/my_events.html.twig',
  473.             [
  474.                 'user' => $this->getUser(),
  475.                 'byEmail' => $byEmail,
  476.                 'location' => 'My Events',
  477.                 'userEvents' => $userEvents
  478.             ]
  479.         );
  480.     }
  481.     /**
  482.      * @Route("/myeurovision/subscriptions", name="my_subscriptions", options={"expose" = true })
  483.      * @Security("is_granted('ROLE_USER')")
  484.      * @return Response
  485.      */
  486.     public function newslettersAction(Request $request)
  487.     {
  488.         $newslettersCategories $this->newslettersService->getAllNewslettersEventCategories();
  489.         $isRegistered $this->newslettersService->isUserRegistered($this->getUser()->getUid());
  490.         $memberDetails $this->newslettersService->getMemberDetails($this->getUser()->getUid());
  491.         $subscribeUrl '';
  492.         if (empty($memberDetails) || $memberDetails['status'] == 404) {
  493.             $isRegistered true;
  494.         } else {
  495.             $subscribeUrl $this->newslettersService->getSubscribeUrlList($memberDetails);
  496.         }
  497.         $userSubs $this->newslettersService->getCurrentUserInterests();
  498.         $userEvents $this->eventFollowerService->getEventsFollowedByCurrentUser();
  499.         return $this->render(
  500.             'my_eurovision/my_subscriptions.html.twig',
  501.             [
  502.                 'user' => $this->getUser(),
  503.                 'isRegistered' => $isRegistered,
  504.                 'subscribeUrl' => $subscribeUrl,
  505.                 'newslettersCategories' => $newslettersCategories,
  506.                 'userSubs' => $userSubs,
  507.                 'location' => 'My Subscriptions',
  508.                 'userEvents' => $userEvents
  509.             ]
  510.         );
  511.     }
  512.     /**
  513.      * @Route("/intern/newsletters/group/add/{interestsId}", name="add_interest_user", options={"expose"=true}, methods={"GET"})
  514.      * @Security("is_granted('ROLE_USER')")
  515.      * @param $interestsId
  516.      * @return JsonResponse
  517.      */
  518.     public function addUserInterest($interestsId)
  519.     {
  520.         try {
  521.             $interestArray = [$interestsId];
  522.             $success $this->newslettersService->addUserInterestForCurrentUser($interestArray);
  523.             if ($success) {
  524.                 return JsonResponseHelper::buildSuccessJson("Subscription Added");
  525.             }
  526.             return JsonResponseHelper::buildErrorJsonData("Error in adding Subscription !");
  527.         } catch (Exception $e) {
  528.             return JsonResponseHelper::buildErrorJson("Error to add subscription : " $e->getMessage());
  529.         }
  530.     }
  531.     /**
  532.      * @Route("/intern/newsletters/group/remove/{interestsId}", name="remove_interest_user", options={"expose"=true}, methods={"GET"})
  533.      * @Security("is_granted('ROLE_USER')")
  534.      * @param $interestsId
  535.      * @return JsonResponse
  536.      */
  537.     public function removeUserInterest($interestsId)
  538.     {
  539.         try {
  540.             $interestArray = [$interestsId];
  541.             $this->newslettersService->removeUserInterestForCurrentUser($interestArray);
  542.             return new JsonResponse(
  543.                 [
  544.                     'success' => true,
  545.                     'code' => 200,
  546.                     'message' => "Subscription Removed"
  547.                 ]
  548.             );
  549.         } catch (Exception $e) {
  550.             return new JsonResponse(
  551.                 [
  552.                     'success' => false,
  553.                     'code' => 200,
  554.                     'message' => "Error to remove subscription : " $e->getMessage()
  555.                 ]
  556.             );
  557.         }
  558.     }
  559.     /**
  560.      * @Route("/intern/newsletters/group/removeall", name="remove_all_interests", options={"expose"=true}, methods={"GET"})
  561.      * @Security("is_granted('ROLE_USER')")
  562.      * @return JsonResponse
  563.      */
  564.     public function removeUserAllInterests()
  565.     {
  566.         try {
  567.             $this->newslettersService->removeUserAllInterests($this->getUser()->getUid());
  568.             return new JsonResponse(
  569.                 [
  570.                     'success' => true,
  571.                     'code' => 200,
  572.                     'message' => "All Subscriptions Removed"
  573.                 ]
  574.             );
  575.         } catch (Exception $e) {
  576.             return new JsonResponse(
  577.                 [
  578.                     'success' => false,
  579.                     'code' => 200,
  580.                     'message' => "Error to remove subscriptions : " $e->getMessage()
  581.                 ]
  582.             );
  583.         }
  584.     }
  585.     /**
  586.      * @param Request $request
  587.      * @return Response
  588.      * @Get("/intern/all-customer-orders-view", name="get_all_customers_orders_view", options={"expose" = true })
  589.      */
  590.     public function getAllCustomerOrderViewAction(Request $request)
  591.     {
  592.         $period = (!empty($request->get('period'))) ? $request->get('period') : 'month';
  593.         $res $this->customerOrderService->getCustomersOrdersByPeriod($period);
  594.         $customerOrders $res->getData();
  595.         $status $res->getStatus();
  596.         $message $res->getMessage();
  597.         return $this->render(
  598.             'customer_orders/myordersview.html.twig',
  599.             [
  600.                 'isOperationSuccess' => $status === OperationResult::SUCCESS,
  601.                 'message' => $message,
  602.                 'customerOrdersDetails' => $customerOrders
  603.             ]
  604.         );
  605.     }
  606.     /**
  607.      * @param Request $request
  608.      * @return Response
  609.      * @Get("/intern/get-booking-type-customer-order", name="get_booking_type_customer_order", options={"expose" = true })
  610.      */
  611.     public function getGlobalBookingTypeForCustomerORderAction(Request $request)
  612.     {
  613.         $customerOrderNo = (!empty($request->get('customerOrderNo'))) ? $request->get('customerOrderNo') : null;
  614.         if (empty($customerOrderNo)) {
  615.             return null;
  616.         }
  617.         $res $this->customerOrderService->getWorkOrdersJson($customerOrderNo);
  618.         $allBookings json_decode($restrue);
  619.         $bookingType '';
  620.         if (!empty($allBookings)) {
  621.             foreach ($allBookings as $booking) {
  622.                 $bookingType $booking['product']['code'];
  623.             }
  624.         }
  625.         return $this->render(
  626.             'customer_orders/customer-order-booking-type-image.html.twig',
  627.             [
  628.                 'bookingType' => $bookingType
  629.             ]
  630.         );
  631.     }
  632.     /**
  633.      * @return Response
  634.      * @Get("/intern/get-nb-customer-orders", name="get_nb_customers_orders", options={"expose" = true })
  635.      * @return JsonResponse
  636.      */
  637.     public function getNbCustomerOrderAction(Request $request)
  638.     {
  639.         $customerOrders $this->customerOrderService->getCustomersOrders(null);
  640.         $nbBookings count($customerOrders->getData() ?? []);
  641.         return $this->json($nbBookings);
  642.     }
  643.     /**
  644.      * @return Response
  645.      * @Get("/intern/last-customer-orders-view", name="get_last_customers_orders_view", options={"expose" = true })
  646.      * @return Response
  647.      */
  648.     public function getLastCustomerOrderViewAction(Request $request)
  649.     {
  650.         $nbCustomerOrderToDisplay = (!empty($request->get('nbCustomerOrder'))) ? $request->get('nbCustomerOrder') : 4;
  651.         $res $this->customerOrderService->getCustomersOrders(null);
  652.         $customerOrders $res->getData();
  653.         $lastCustomerOrders array_slice($customerOrders0$nbCustomerOrderToDisplay);
  654.         $status $res->getStatus();
  655.         $message $res->getMessage();
  656.         return $this->render(
  657.             'customer_orders/mylastordersview.html.twig',
  658.             [
  659.                 'isOperationSuccess' => $status === OperationResult::SUCCESS,
  660.                 'message' => $message,
  661.                 'customerOrdersDetails' => $lastCustomerOrders
  662.             ]
  663.         );
  664.     }
  665.     /**
  666.      * @Route("/myeurovision/orders/{customerOrderNo}/details", name="my_orders_details_work_order", options={"expose" = true })
  667.      * @Security("is_granted('ROLE_USER')")
  668.      * @param $customerOrderNo
  669.      * @return Response
  670.      */
  671.     public function getAllworkOrderViewAction($customerOrderNo)
  672.     {
  673.         $customerWorkOrdersDetails $this->customerOrderService->getWorkOrders($customerOrderNo"default");
  674.         $editable $this->customerOrderService->createEditContainer($customerWorkOrdersDetails)->isEditable();
  675.         $eventNo $customerWorkOrdersDetails->getCustomerOrder()->getEventNo();
  676.         if (!empty($eventNo)) {
  677.             $event $this->eventService->getEventByNo($eventNo);
  678.             if (!empty($event) && !$event->isBookable()) {
  679.                 $editable $event->isBookable();
  680.             }
  681.         }
  682.         $isEventOffer = !empty($eventNo) ? $customerWorkOrdersDetails->hasMultiWorkOrder() : false;
  683.         return $this->render(
  684.             'my_eurovision/my_bookings_details.html.twig',
  685.             [
  686.                 'user' => $this->getUser(),
  687.                 'location' => 'Work-orders',
  688.                 'editable' => $editable,
  689.                 'isEventOffer' => $isEventOffer,
  690.                 'eventNo' => $eventNo,
  691.                 'customerWorkOrdersDetails' => $customerWorkOrdersDetails,
  692.             ]
  693.         );
  694.     }
  695.     /**
  696.      * @Route("/myeurovision/orders/{customerOrderNo}/edit", name="my_orders_edit_work_order")
  697.      * @Security("is_granted('ROLE_USER')")
  698.      * @param Request $request
  699.      * @param null|string $customerOrderNo
  700.      * @return Response
  701.      */
  702.     public function editWorkOrdersAction(Request $request, ?string $customerOrderNo)
  703.     {
  704.         $customerWorkOrdersDetails $this->customerOrderService->getWorkOrders($customerOrderNo"default");
  705.         $workOrderEditContainer $this->customerOrderService->loadWorkOrdersForEdition($customerOrderNo);
  706.         $form $this->createForm(WorkOrderEditContainerType::class, $workOrderEditContainer);
  707.         $form->handleRequest($request);
  708.         return $this->render('my_eurovision/my_bookings_edit.html.twig',
  709.             [
  710.                 'user' => $this->getUser(),
  711.                 'location' => 'Work-orders',
  712.                 'workOrderEditContainer' => $workOrderEditContainer,
  713.                 'customerWorkOrdersDetails' => $customerWorkOrdersDetails,
  714.                 'form' => $form->createView()
  715.             ]);
  716.     }
  717.     /**
  718.      * It will redirect to the correct work-order
  719.      * @Route("/myeurovision/work-order/{workOrderId}/edit", name="my_orders_edit_one_work_order")
  720.      * @Security("is_granted('ROLE_USER')")
  721.      *
  722.      * @param Request $request
  723.      * @param null|string $workOrderId
  724.      * @return Response
  725.      */
  726.     public function editOneWorkOrdesAction(Request $request, ?string $workOrderId)
  727.     {
  728.         $customerOrderNo $this->customerOrderService->getCustomerOrderNoFromWorkOrder($workOrderId);
  729.         if (!empty($customerOrderNo)) {
  730.             return $this->redirectToRoute('my_orders_edit_work_order', ['customerOrderNo' => $customerOrderNo]);
  731.         }
  732.         return $this->redirectToRoute('my_orders');
  733.     }
  734.     /**
  735.      * @Security("is_granted('ROLE_USER')")
  736.      * @Route("/intern/work-order-edition/submit", name="work-order-edition-submit", options={"expose" = true})
  737.      * @param Request $request
  738.      * @param LoggerInterface $logger
  739.      * @return Response
  740.      */
  741.     public function submitWorkOrderEditionAction(Request $requestLoggerInterface $logger)
  742.     {
  743.         try {
  744.             $workOrderEditContainer = new WorkOrderEditContainer();
  745.             $form $this->createForm(WorkOrderEditContainerType::class, $workOrderEditContainer, []);
  746.             $form->handleRequest($request);
  747.             if (!$form->isValid()) {
  748.                 $jsonResponse $this->buildJsonResponseForModificationsNotValid($form);
  749.                 return $jsonResponse;
  750.             }
  751.             $result $this->bookingService->editBookings($workOrderEditContainer);
  752.             if ($result->isError()) {
  753.                 $errorToDisplay $this->render("booking_cart/booking_error.html.twig", ["operationResult" => $result])->getContent();
  754.                 return $this->json($errorToDisplayJsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  755.             }
  756.             return $this->json('ok');
  757.         } catch (Exception $ex) {
  758.             $logger->alert("error in work-order edition" $ex->getMessage(), ["exception" => $ex]);
  759.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  760.         }
  761.     }
  762.     /**
  763.      * @param $form
  764.      * @return JsonResponse
  765.      */
  766.     private function buildJsonResponseForModificationsNotValid($form): JsonResponse
  767.     {
  768.         $data = [];
  769.         $errors Helper::getErrorMessagesFlat($formtrue);
  770.         $data['message'] = "Please, check  your modifications";
  771.         $data['errors'] = $errors;
  772.         //warn: the javascript is waiting for this response in case of unvalide data
  773.         //our javascript use the code to differentiate validation errors to internal errors.
  774.         $jsonResponse $this->json($dataJsonResponse::HTTP_BAD_REQUEST);
  775.         return $jsonResponse;
  776.     }
  777.     /**
  778.      * @Route("/myeurovision/incident-tickets", name="incident_tickets", options={"expose" = true })
  779.      * @Security("is_granted('ROLE_USER')")
  780.      */
  781.     public function incidentTicketsAction(Request $request)
  782.     {
  783.         // Check if user belongs to a company
  784.         $codeOps $this->userService->getCurrentUserCodeOps();
  785.         if (empty($codeOps)) {
  786.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  787.         }
  788.         $feedback = new Feedback();
  789.         $form $this->createForm(FeedbackType::class, $feedback, ['is_incident_ticket' => true]);
  790.         $form->handleRequest($request);
  791.         return $this->render(
  792.             'my_eurovision/incident_tickets.html.twig',
  793.             [
  794.                 'user' => $this->getUser(),
  795.                 'location' => 'Incident tickets',
  796.                 'form' => $form->createView()
  797.             ]
  798.         );
  799.     }
  800.     /**
  801.      * @Route("/myeurovision/maintenance", name="maintenance", options={"expose" = true })
  802.      * @Security("is_granted('ROLE_USER')")
  803.      */
  804.     public function maintenanceAction(Request $request)
  805.     {
  806.         // Check if user belongs to a company
  807.         $codeOps $this->userService->getCurrentUserCodeOps();
  808.         if (empty($codeOps)) {
  809.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  810.         }
  811.         return $this->render(
  812.             'my_eurovision/maintenance_tickets.html.twig',
  813.             [
  814.                 'user' => $this->getUser(),
  815.                 'location' => 'Maintenance'
  816.             ]
  817.         );
  818.     }
  819.     /**
  820.      * @Route("/myeurovision/flex-portal", name="flex_portal", options={"expose" = true })
  821.      * @Security("is_granted('ROLE_USER')")
  822.      */
  823.     public function flexPortalAction(Request $request)
  824.     {
  825.         // Check if user belongs to a company
  826.         $codeOps $this->userService->getCurrentUserCodeOps();
  827.         if (empty($codeOps)) {
  828.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  829.         }
  830.         return $this->render(
  831.             'my_eurovision/flex_portal.html.twig',
  832.             [
  833.                 'user' => $this->getUser(),
  834.                 'location' => 'Flex portal'
  835.             ]
  836.         );
  837.     }
  838.     /**
  839.      * @Route("/intern/incident/list", name="incident_tickets_list", options={"expose" = true })
  840.      * @Security("is_granted('ROLE_USER')")
  841.      */
  842.     public function getIncidentTicketsListAction(Request $request)
  843.     {
  844.         // Check if user belongs to a company
  845.         $codeOps $this->userService->getCurrentUserCodeOps();
  846.         if (empty($codeOps)) {
  847.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  848.         }
  849.         $user $this->getUser();
  850.         $isMaintenance = (!empty($request->get('isMaintenance'))) ? true false;
  851.         $incidents $this->xrmService->getIncidents($user->getCompanyCodeOps(), $isMaintenance);
  852.         return $this->render(
  853.             'my_eurovision/incident_tickets_list.html.twig',
  854.             [
  855.                 'incidents' => $incidents,
  856.                 'nbIncidents' => count($incidents ?? [])
  857.             ]
  858.         );
  859.     }
  860.     /**
  861.      * @Route("/intern/incident/{id}/details", name="incident_ticket_details", options={"expose" = true})
  862.      * @Security("is_granted('ROLE_USER')")
  863.      */
  864.     public function incidentDetailsAction(Request $request, ?string $id)
  865.     {
  866.         // Check if user belongs to a company
  867.         $codeOps $this->userService->getCurrentUserCodeOps();
  868.         if (empty($codeOps)) {
  869.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  870.         }
  871.         $incident $this->xrmService->getIncidentById($id);
  872.         return $this->render(
  873.             'my_eurovision/incident_details.html.twig',
  874.             [
  875.                 'incident' => $incident
  876.             ]
  877.         );
  878.     }
  879.     /**
  880.      * @Route("/intern/incident/{id}/updates", name="incident_ticket_updates", options={"expose" = true})
  881.      * @Security("is_granted('ROLE_USER')")
  882.      */
  883.     public function incidentUpdatesAction(Request $request, ?string $id)
  884.     {
  885.         // Check if user belongs to a company
  886.         $codeOps $this->userService->getCurrentUserCodeOps();
  887.         if (empty($codeOps)) {
  888.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  889.         }
  890.         $incident $this->xrmService->getIncidentById($id);
  891.         return $this->render(
  892.             'my_eurovision/incident_updates.html.twig',
  893.             [
  894.                 'incident' => $incident
  895.             ]
  896.         );
  897.     }
  898.     /**
  899.      * @Route("/myeurovision/incident/pdf/{reference}", name="incident_details_get_pdf_by_reference", options={"expose" = true})
  900.      * @Security("is_granted('ROLE_USER')")
  901.      * @param string $id
  902.      * @return Response
  903.      */
  904.     public function getIncidentDetailsPDFByReference(string $referenceRequest $requestPdf $pdf)
  905.     {
  906.         // Check if user belongs to a company
  907.         $codeOps $this->userService->getCurrentUserCodeOps();
  908.         if (empty($codeOps)) {
  909.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  910.         }
  911.         $filename 'incident_' $reference '_details';
  912.         $incident $this->xrmService->getIncidentByReference($reference);
  913.         $html $this->renderView('my_eurovision/incident_ticket_pdf_content.html.twig', [
  914.             'incident' => $incident,
  915.             'incidentTitle' => 'Service Interruption Report',
  916.             'base_dir' => $this->getParameter('kernel.project_dir') . '/../web' $request->getBasePath()
  917.         ]);
  918.         $header $this->renderView('my_eurovision/incident_ticket_pdf_header.html.twig');
  919.         $footer $this->renderView('my_eurovision/incident_ticket_pdf_footer.html.twig');
  920.         return new Response(
  921.             $pdf->getOutputFromHtml($html, [
  922.                 'header-html' => $header,
  923.                 'footer-html' => $footer,
  924.             ]), 200, [
  925.                 'Content-Type' => 'application/pdf',
  926.                 'Content-Disposition' => 'attachment; filename="' $filename '.pdf"'
  927.             ]
  928.         );
  929.     }
  930.     /**
  931.      * @Route("/intern/incident/details/pdf/{id}", name="incident_details_get_pdf", options={"expose" = true})
  932.      * @Security("is_granted('ROLE_USER')")
  933.      * @param string $id
  934.      * @return Response
  935.      */
  936.     public function getIncidentDetailsPDF(string $idRequest $requestPdf $pdf)
  937.     {
  938.         // Check if user belongs to a company
  939.         $codeOps $this->userService->getCurrentUserCodeOps();
  940.         if (empty($codeOps)) {
  941.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  942.         }
  943.         $filename 'incident_' $id '_details';
  944.         $incident $this->xrmService->getIncidentById($id);
  945.         $html $this->renderView('my_eurovision/incident_ticket_pdf_content.html.twig', [
  946.             'incident' => $incident,
  947.             'incidentTitle' => 'Service Interruption Report',
  948.             'base_dir' => $this->getParameter('kernel.project_dir') . '/../web' $request->getBasePath()
  949.         ]);
  950.         $header $this->renderView('my_eurovision/incident_ticket_pdf_header.html.twig');
  951.         $footer $this->renderView('my_eurovision/incident_ticket_pdf_footer.html.twig');
  952.         return new Response(
  953.             $pdf->getOutputFromHtml($html, [
  954.                 'header-html' => $header,
  955.                 'footer-html' => $footer,
  956.             ]), 200, [
  957.                 'Content-Type' => 'application/pdf',
  958.                 'Content-Disposition' => 'attachment; filename="' $filename '.pdf"'
  959.             ]
  960.         );
  961.     }
  962.     /**
  963.      * @Security("is_granted('ROLE_USER')")
  964.      * @Route("/intern/incident/{caseId}/{action}/{source}", name="incident_accept_reject_sir", options={"expose" = true})
  965.      * @param Request $request
  966.      * @param string $caseId
  967.      * @param string $action
  968.      * @return Response
  969.      */
  970.     public function incidentAcceptSirAction(Request $requeststring $caseIdstring $actionstring $source)
  971.     {
  972.         // Check if user belongs to a company
  973.         $codeOps $this->userService->getCurrentUserCodeOps();
  974.         if (empty($codeOps)) {
  975.             return $this->redirectToRoute('myeurovision_not_authorized', ['email' => 'websupport@eurovisionservices.com']);
  976.         }
  977.         try {
  978.             $comments = (!empty($request->get('comments'))) ? $request->get('comments') : '';
  979.             $user $this->userService->getCurrentUserFullname();
  980.             $this->xrmService->changeStatusCase($caseId$actionXrmService::XRM_STATUS_REJECTED_CODE$comments$user$source);
  981.             return $this->json("ok");
  982.         } catch (Exception $ex) {
  983.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  984.         }
  985.     }
  986.     /**
  987.      * @Security("is_granted('ROLE_USER')")
  988.      * @Route("/myeurovision/company/equipment", name="myeurovision_equipment", options={"expose" = true})
  989.      * @param Request|null $request
  990.      * @return Response
  991.      */
  992.     public function equipmentAction(Request $request null)
  993.     {
  994.         // Check if user belongs to a company
  995.         $codeOps $this->userService->getCurrentUserCodeOps();
  996.         if (empty($codeOps)) {
  997.             return $this->redirectToRoute('myeurovision_not_authorized');
  998.         }
  999.         // Build the form
  1000.         $equipment = new Equipment();
  1001.         $surveyEquipmentModelList $this->equipmentService->getSurveyEquipmentModelList();
  1002.         $surveyTypeList $this->equipmentService->getSurveyTypeList();
  1003.         krsort($surveyTypeList);
  1004.         // Generate uniqId for attachments
  1005.         $uniqIdForm uniqid();
  1006.         $form $this->createForm(EquipmentType::class, $equipment, ['surveyEquipmentModelList' => $surveyEquipmentModelList'surveyTypeList' => $surveyTypeList'uniqIdForm' => $uniqIdForm]);
  1007.         $form->handleRequest($request);
  1008.         $user $this->getUser();
  1009.         return $this->render(
  1010.             'my_eurovision/equipment.html.twig',
  1011.             [
  1012.                 'user' => $user,
  1013.                 'uniqIdForm' => $uniqIdForm,
  1014.                 'surveyTypeList' => $surveyTypeList,
  1015.                 'newEquipmentId' => array_key_first($surveyTypeList),
  1016.                 'form' => $form->createView()
  1017.             ]
  1018.         );
  1019.     }
  1020.     /**
  1021.      * @Route("/intern/myeurovision/company/equipment/{userCodeops}", name="myeurovision_equipment_list", options={"expose" = true }, methods={"GET"})
  1022.      * @param Request $request
  1023.      * @param string $userEmail
  1024.      * @return Response
  1025.      */
  1026.     public function getEquipmentsByCodeops(Request $requeststring $userCodeops)
  1027.     {
  1028.         $jiraIssues = [];
  1029.         try {
  1030.             $codeops = [];
  1031.             // Get user codeops family
  1032.             $companies $this->domainService->getListUserOrganizationAndOrganizationFamilies();
  1033.             if (!empty($companies)) {
  1034.                 foreach ($companies as $company) {
  1035.                     $codeops[] = $company->code;
  1036.                 }
  1037.             }
  1038.             $jiraIssues $this->equipmentService->getJiraTicketByCodeops($codeops);
  1039.         } catch (Exception $ex) {
  1040.             $this->actionLoggerService->getLogger()->error("cant get jira tickets", ["exception" => $ex]);
  1041.         }
  1042.         return $this->render(
  1043.             'my_eurovision/equipment_jira_list_table.html.twig', [
  1044.             'jiraIssues' => $jiraIssues
  1045.         ]);
  1046.     }
  1047.     /**
  1048.      * @Route("/intern/myeurovision/company/equipment/{userCodeops}/by-serial-number/{serialNumber}", name="myeurovision_equipment_by_serial_number", options={"expose" = true }, methods={"GET"})
  1049.      * @param Request $request
  1050.      * @param string $userCodeops
  1051.      * @param string $serialNumber
  1052.      * @return Response
  1053.      */
  1054.     public function getEquipmentsBySerialNumber(Request $requeststring $userCodeopsstring $serialNumber)
  1055.     {
  1056.         return $this->json($this->equipmentService->checkEquipmentsBySerialNumber($userCodeops$serialNumber));
  1057.     }
  1058.     /**
  1059.      * @Security("is_granted('ROLE_USER')")
  1060.      * @Route("/intern/myeurovision/company/equipment/submit", name="myeurovision_equipment_submit", options={"expose" = true})
  1061.      * @param Request $request
  1062.      * @param LoggerInterface $logger
  1063.      * @return Response
  1064.      */
  1065.     public function submitEquipmentAction(Request $requestLoggerInterface $logger)
  1066.     {
  1067.         try {
  1068.             $equipment = new Equipment();
  1069.             $surveyEquipmentModelList $this->equipmentService->getSurveyEquipmentModelList();
  1070.             $surveyTypeList $this->equipmentService->getSurveyTypeList();
  1071.             $form $this->createForm(EquipmentType::class, $equipment, ['surveyEquipmentModelList' => $surveyEquipmentModelList'surveyTypeList' => $surveyTypeList]);
  1072.             $form->handleRequest($request);
  1073.             //not valid...
  1074.             if (!$form->isValid()) {
  1075.                 $errors Helper::getErrorMessagesFlat($formtrue);
  1076.                 $data['message'] = "Please, check errors in your equipment";
  1077.                 $data['errors'] = $errors;
  1078.                 $jsonResponse $this->json($dataJsonResponse::HTTP_BAD_REQUEST);
  1079.                 return $jsonResponse;
  1080.             }
  1081.             $user $this->getUser();
  1082.             // Create/Edit ticket in JIRA
  1083.             $result $this->equipmentService->createEditEquipmentJiraTicket($equipment$user);
  1084.             $this->equipmentService->changeStatusJiraTicketAndSendMail($result['key']);
  1085.             // Add user in Mailchimp mailing list
  1086.             $subscriptionResult $this->equipmentService->addUserSubscription($equipment$user);
  1087.             if (empty($result)) {
  1088.                 return $this->json($resultJsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  1089.             }
  1090.             return $this->json($result);
  1091.         } catch (Exception $ex) {
  1092.             $logger->alert("error in submit equipment" $ex->getMessage(), ["exception" => $ex]);
  1093.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  1094.         }
  1095.     }
  1096.     /**
  1097.      * @Security("is_granted('ROLE_USER')")
  1098.      * @Route("/intern/myeurovision/company/equipment/add-comment", name="myeurovision_equipment_add_comment", options={"expose" = true})
  1099.      * @param Request $request
  1100.      * @param LoggerInterface $logger
  1101.      * @return Response
  1102.      */
  1103.     public function addJiraCommentAction(Request $requestLoggerInterface $logger)
  1104.     {
  1105.         try {
  1106.             $jiraKey = (!empty($request->get('jiraKey'))) ? $request->get('jiraKey') : null;
  1107.             $uniqIdForm = (!empty($request->get('uniqIdForm'))) ? $request->get('uniqIdForm') : null;
  1108.             $comment = (!empty($request->get('comment'))) ? $request->get('comment') : null;
  1109.             $result $this->equipmentService->addJiraComment($jiraKey$uniqIdForm$comment);
  1110.             return $this->json($result);
  1111.         } catch (Exception $ex) {
  1112.             $logger->alert("error in submitting comment" $ex->getMessage(), ["exception" => $ex]);
  1113.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  1114.         }
  1115.     }
  1116.     /**
  1117.      * @Security("is_granted('ROLE_USER')")
  1118.      * @Route("/intern/myeurovision/company/equipment/add-decoder-public-key", name="myeurovision_equipment_add_decoder_public_key", options={"expose" = true})
  1119.      * @param Request $request
  1120.      * @param LoggerInterface $logger
  1121.      * @return Response
  1122.      */
  1123.     public function addDecoderPublicKeyAction(Request $requestLoggerInterface $logger)
  1124.     {
  1125.         try {
  1126.             $jiraKey = (!empty($request->get('jiraKey'))) ? $request->get('jiraKey') : null;
  1127.             $uniqIdForm = (!empty($request->get('uniqIdForm'))) ? $request->get('uniqIdForm') : null;
  1128.             $result $this->equipmentService->addDecoderPublicKey($jiraKey$uniqIdForm);
  1129.             return $this->json($result);
  1130.         } catch (Exception $ex) {
  1131.             $logger->alert("error in submitting decoder public key" $ex->getMessage(), ["exception" => $ex]);
  1132.             return $this->json($ex->getMessage(), JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  1133.         }
  1134.     }
  1135.     /**
  1136.      * @Route("/intern/myeurovision/company/equipment/{reference}/details", name="myeurovision_equipment_details", options={"expose" = true }, methods={"GET"})
  1137.      * @param Request $request
  1138.      * @param string $reference
  1139.      * @return Response
  1140.      */
  1141.     public function getEquipmentDetails(Request $requeststring $reference)
  1142.     {
  1143.         try {
  1144.             $detailsHtml '';
  1145.             $attachmentsHtml '';
  1146.             $jiraIssue $this->equipmentService->getJiraTicketDetails($reference);
  1147.             $issue $this->equipmentService->parseJiraTicketDetailsBSResponse($jiraIssue);
  1148.             $detailsHtml $this->renderView(
  1149.                 'my_eurovision/equipment_details.html.twig',
  1150.                 [
  1151.                     'equipment' => $issue
  1152.                 ]
  1153.             );
  1154.             if (!empty($issue->attachment)) {
  1155.                 $attachmentsHtml $this->renderView(
  1156.                     'my_eurovision/equipment_attachments.html.twig',
  1157.                     [
  1158.                         'attachments' => $issue->attachment
  1159.                     ]
  1160.                 );
  1161.             }
  1162.         } catch (Exception $ex) {
  1163.             $this->actionLoggerService->getLogger()->error("cant get jira ticket", ["exception" => $ex]);
  1164.         }
  1165.         return $this->json(
  1166.             [
  1167.                 'details' => $issue,
  1168.                 'detailsHtml' => $detailsHtml,
  1169.                 'attachmentsHtml' => $attachmentsHtml
  1170.             ]
  1171.         );
  1172.     }
  1173.     /**
  1174.      * @Route("/intern/myeurovision/company/equipment/attachment/{attachmentId}/delete", name="myeurovision_equipment_delete_attachment", options={"expose" = true }, methods={"GET"})
  1175.      * @param Request $request
  1176.      * @param string $attachmentId
  1177.      * @return Response
  1178.      */
  1179.     public function deleteEquipmentAttachment(Request $requeststring $attachmentId)
  1180.     {
  1181.         try {
  1182.             $result $this->equipmentService->deleteAttachmentJiraTicket($attachmentId);
  1183.         } catch (Exception $ex) {
  1184.             $this->actionLoggerService->getLogger()->error("cant delete attachment", ["exception" => $ex]);
  1185.         }
  1186.         return $this->json($result->getData());
  1187.     }
  1188.     /**
  1189.      * @Route("/intern/myeurovision/dropzone/upload", name="myeurovision_dropzone_upload", options={"expose" = true}, methods={"GET", "POST"})
  1190.      * @param Request $request
  1191.      */
  1192.     public function dropzoneUploadAction(Request $request)
  1193.     {
  1194.         /** @var UploadedFile $media */
  1195.         $media $request->files->get('file');
  1196.         $type = (!empty($request->get('type'))) ? $request->get('type') : null;
  1197.         $uniqIdForm = (!empty($request->get('uniqIdForm'))) ? $request->get('uniqIdForm') : null;
  1198.         $directory null;
  1199.         if ($type == 'freelancer-portal') {
  1200.             $directory FreelancerPortalService::UPLOADED_FOLDER;
  1201.         } elseif ($type == 'equipment') {
  1202.             $directory EquipmentService::UPLOADED_FOLDER;
  1203.         } elseif ($type == 'providers') {
  1204.             $directory ProviderService::UPLOADED_FOLDER;
  1205.         } elseif ($type == 'company-registration') {
  1206.             $directory CompanyRegistrationService::UPLOADED_FOLDER;
  1207.         }
  1208.         $uniqDirectory $directory "/" $uniqIdForm;
  1209.         if (!is_dir($directory)) {
  1210.             mkdir($directory);
  1211.         }
  1212.         if (!is_dir($uniqDirectory)) {
  1213.             mkdir($uniqDirectory);
  1214.         }
  1215.         move_uploaded_file($media->getPathName(), $media->getPath() . '/' $type '/' $uniqIdForm '/' $media->getClientOriginalName());
  1216.         return new JsonResponse(['success' => true'data' => $media]);
  1217.     }
  1218.     /**
  1219.      * @Route("/intern/myeurovision/dropzone/upload/cancel", name="myeurovision_dropzone_upload_cancel", options={"expose" = true}, methods={"GET", "POST"})
  1220.      * @param Request $request
  1221.      */
  1222.     public function dropzoneUploadCancelAction(Request $request)
  1223.     {
  1224.         $type = (!empty($request->get('type'))) ? $request->get('type') : null;
  1225.         $uniqIdForm = (!empty($request->get('uniqIdForm'))) ? $request->get('uniqIdForm') : null;
  1226.         $filename = (!empty($request->get('filename'))) ? $request->get('filename') : null;
  1227.         $directory null;
  1228.         if ($type == 'freelancer-portal') {
  1229.             $directory FreelancerPortalService::UPLOADED_FOLDER;
  1230.         } elseif ($type == 'equipment') {
  1231.             $directory EquipmentService::UPLOADED_FOLDER;
  1232.         } elseif ($type == 'providers') {
  1233.             $directory ProviderService::UPLOADED_FOLDER;
  1234.         } elseif ($type == 'company-registration') {
  1235.             $directory CompanyRegistrationService::UPLOADED_FOLDER;
  1236.         }
  1237.         $filePath $directory "/" $uniqIdForm "/" $filename;
  1238.         if (file_exists($filePath)) {
  1239.             unlink($filePath);
  1240.         }
  1241.         return new JsonResponse(['success' => true'data' => 'ok']);
  1242.     }
  1243.     /**
  1244.      * @Route("/myeurovision/not-authorized", name="myeurovision_not_authorized")
  1245.      */
  1246.     public function notAuthorizedAction(Request $request)
  1247.     {
  1248.         $message $request->get("message");
  1249.         if ($message === null) {
  1250.             $message "";
  1251.         }
  1252.         $supportEmail $request->get("email");
  1253.         if ($supportEmail === null) {
  1254.             $supportEmail "p2p_cps@eurovisionservices.com";
  1255.         }
  1256.         return $this->render(
  1257.             'my_eurovision/not-authorized.html.twig',
  1258.             [
  1259.                 'user' => $this->getUser(),
  1260.                 'message' => $message,
  1261.                 'supportEmail' => $supportEmail
  1262.             ]
  1263.         );
  1264.     }
  1265.     /**
  1266.      * @Route("/myeurovision/profile/change-user-codeops/{codeops}", name="change_user_codeops", options={"expose" = true })
  1267.      * @param string $codeops
  1268.      * @Security("is_granted('ROLE_USER')")
  1269.      */
  1270.     public function changeUserCodeopsAction(Request $requeststring $codeops)
  1271.     {
  1272.         $res $this->userService->updateUserCompanyName($this->getUser(), $codeops);
  1273.         // Wait 5 seconds to be sure MS is refreshed
  1274.         sleep(5);
  1275.         return new JsonResponse([
  1276.             'message' => $res->getMessage(),
  1277.             'status' => $res->getStatus(),
  1278.             'data' => $res->getData(),
  1279.         ]);
  1280.     }
  1281.     /**
  1282.      * @Route("/myeurovision/profile/regenerate-api-keys", name="regenerate_api_keys", options={"expose" = true })
  1283.      * @Security("is_granted('ROLE_USER')")
  1284.      */
  1285.     public function regenerateApiKeysAction(Request $request)
  1286.     {
  1287.         $res $this->userService->regenerateApiKeys($this->getUser());
  1288.         if (!empty($res) && $res->getStatus() === 'success') {
  1289.             $this->notificationSenderHelperService->sendRegenerateAuthenticationKeysEmail($this->getUser());
  1290.         }
  1291.         return new JsonResponse([
  1292.             'message' => $res->getMessage(),
  1293.             'status' => $res->getStatus(),
  1294.             'data' => $res->getData(),
  1295.         ]);
  1296.     }
  1297.     /**
  1298.      * @Route("/intern/check-first-login", name="check_first_login", options={"expose" = true}, methods={"GET"})
  1299.      * @param Request|null $request
  1300.      * @return JsonResponse|Response
  1301.      */
  1302.     public function getFirstLoginAction(Request $request null)
  1303.     {
  1304.         // Get user preference to know if it is the first login on new website
  1305.         $firstLogin false;
  1306.         $redirectToRoute null;
  1307.         $user $this->getUser();
  1308.         if ($user) {
  1309.             $userPreference $this->dashboardService->getUserPreference($user->getId());
  1310.             if (!empty($userPreference) && !empty($userPreference->getFirstLogin())) {
  1311.                 $firstLogin false;
  1312.             } else {
  1313.                 $this->dashboardService->saveUserPreference($user->getId(), UserPreference::TABLE);
  1314.                 $firstLogin true;
  1315.                 // Check domain mapping
  1316.                 // If only one organisation associated to user email domain - auto associate user to the organisation
  1317.                 // If several organisations associated to user email domain - redirect user to my profile (with Flash message)
  1318.                 if (empty($user->getCompanyCodeOps())) {
  1319.                     $parts explode('@'$user->getEmail());
  1320.                     $domain array_pop($parts);
  1321.                     $emailDomainOrganizations $this->xrmService->getOrganizationsRelatedToSpecificEmailDomain($domain);
  1322.                     $nbOrganisations count($emailDomainOrganizations ?? []);
  1323.                     if ($nbOrganisations === 1) {
  1324.                         $user->setCompanyCodeOps($emailDomainOrganizations[0]['ava_opscode']);
  1325.                     } elseif ($nbOrganisations 1) {
  1326.                         $this->addFlash(FlashType::INFO, [
  1327.                             'title' => 'Please select an organisation',
  1328.                             'message' => 'Your email domain is matching several organisations in our system. Please select your organisation.'
  1329.                         ]);
  1330.                         $redirectToRoute $this->generateUrl('my_profile');
  1331.                     }
  1332.                 }
  1333.                 // Update "displayName" in Microsoft Entra ID - (Full name of the user connected) + associate account to a company (it depends of the email domain mapping)
  1334.                 $this->userService->updateUser($user);
  1335.             }
  1336.         }
  1337.         return new JsonResponse([
  1338.             'firstLogin' => $firstLogin,
  1339.             'redirectUrl' => $redirectToRoute
  1340.         ]);
  1341.     }
  1342. }