src/Controller/Front/InvestorController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Domain\Entity\Project;
  4. use App\Domain\Entity\User;
  5. use App\Service\FolderService;
  6. use App\Service\MailService;
  7. use App\Service\ProjectLogService;
  8. use App\Service\ProjectService;
  9. use App\Service\UserService;
  10. use Exception;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. class InvestorController extends AbstractController
  17. {
  18.     /**
  19.      *
  20.      * @Route("/investor", name="investor_home")
  21.      * @param FolderService $folderService
  22.      * @return Response
  23.      */
  24.     public function investorHome(FolderService $folderServiceUserService $userService): Response
  25.     {
  26.         /** @var User $user */
  27.         $user $this->getUser();
  28.         if (!$user->isAcceptedPolicy()) {
  29.             return $this->redirectToRoute('investor_privacy');
  30.         }
  31.         //Check if impersonating user
  32.         $data = [];
  33.         if ($this->isGranted('ROLE_ADMIN')) {
  34.             $userId $this->get('session')->get('impersonated_user');
  35.             if (!empty($userId)) {
  36.                 $user $userService->getOneById($userId);
  37.                 if (empty($user)) {
  38.                     $user $this->getUser();
  39.                 }
  40.                 $this->addFlash('success''You\'re seeing the app as ' $user->getName() . ' ' $user->getSurname() . ' (' $user->getOrganization()  . ') now <a href="' $this->generateUrl('admin_user_impersonalize', ['id' => -1]) . '" style="float: right;">Stop impersonating</a>');
  41.                 $data['impUser'] = $user;
  42.             }
  43.         }
  44.         return $this->render('investor/home.html.twig'array_merge($data, [ 'folders' => $folderService->getFoldersOfUserTree($user)]));
  45.     }
  46.     /**
  47.      *
  48.      * @Route("/investor/my-account", name="investor_my_account")
  49.      * @return Response
  50.      */
  51.     public function investorMyAccount(): Response
  52.     {
  53.         /** @var User $user */
  54.         $user $this->getUser();
  55.         if (!$user->isAcceptedPolicy()) {
  56.             return $this->redirectToRoute('investor_privacy');
  57.         }
  58.         return $this->render('investor/my-account.html.twig', [ 'user' => $user]);
  59.     }
  60.     /**
  61.      *
  62.      * @Route("/investor/privacy", name="investor_privacy")
  63.      * @param UserService $userService
  64.      * @return Response
  65.      */
  66.     public function investorPrivacy(UserService $userService): Response
  67.     {
  68.         /** @var User $user */
  69.         $user $this->getUser();
  70.         return $this->render('investor/privacy.html.twig', [ 'user' => $user]);
  71.     }
  72.     /**
  73.      *
  74.      * @Route("/investor/accept-privacy", name="investor_accept_privacy")
  75.      * @param Request $request
  76.      * @param UserService $userService
  77.      * @return Response
  78.      */
  79.     public function investorAcceptPrivacy(Request $requestUserService $userService): Response
  80.     {
  81.         /** @var User $user */
  82.         $user $this->getUser();
  83.         $userIP $request->getClientIp();
  84.         $userService->acceptPrivacy($user$userIP);
  85.         return $this->redirectToRoute('investor_home');
  86.     }
  87.     /**
  88.      *
  89.      * @Route("/investor/request-new-password", name="investor_request_new_password")
  90.      * @param UserService $userService
  91.      * @return Response
  92.      */
  93.     public function investorRequestNewPassword(UserService $userService,): Response
  94.     {
  95.         /** @var User $user */
  96.         $user $this->getUser();
  97.         $userService->requestNewPassword($user);
  98.         $this->addFlash('info''Password requested successfully');
  99.         return $this->redirectToRoute('investor_my_account');
  100.     }
  101.     /**
  102.      * @Route("/investor/history/{type}/{projectId}", name="investor_history_view_download")
  103.      * @param ProjectService $projectService
  104.      * @param ProjectLogService $projectLogService
  105.      * @param UserService $userService
  106.      * @param string $type
  107.      * @param string $projectId
  108.      * @return Response
  109.      * @throws Exception
  110.      */
  111.     public function investorHistoryDownloadOrView(
  112.         ProjectService $projectService,
  113.         ProjectLogService $projectLogService,
  114.         UserService $userService,
  115.         string $type,
  116.         string $projectId): Response
  117.     {
  118.         /** @var Project $project */
  119.         $project $projectService->getOneById($projectId);
  120.         /** @var User $user */
  121.         $user $this->getUser();
  122.         if (!$user->isAcceptedPolicy()) {
  123.             return $this->redirectToRoute('investor_privacy');
  124.         }
  125.         if ($project) {
  126.             $logs $projectLogService->getLogs($project$user$type);
  127.             return $this->render('investor/partials/logs.html.twig', [
  128.                 'logs' => $logs'title' => ucfirst($type 's'), 'projectTitle' => $project->getName()]);
  129.         }
  130.         throw new Exception('File or project not found');
  131.     }
  132. }