src/Controller/Front/InvestorController.php line 28

  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. use Symfony\Component\HttpFoundation\RequestStack;
  17. class InvestorController extends AbstractController
  18. {
  19.     private $session;
  20.     public function __construct(RequestStack $requestStack)
  21.     {
  22.         $this->session $requestStack->getSession();
  23.     }
  24.     /**
  25.      *
  26.      * @Route("/investor", name="investor_home")
  27.      * @param FolderService $folderService
  28.      * @return Response
  29.      */
  30.     public function investorHome(FolderService $folderServiceUserService $userService): Response
  31.     {
  32.         /** @var User $user */
  33.         $user $this->getUser();
  34.         if (!$user->isAcceptedPolicy()) {
  35.             return $this->redirectToRoute('investor_privacy');
  36.         }
  37.         //Check if impersonating user
  38.         $data = [];
  39.         if ($this->isGranted('ROLE_ADMIN')) {
  40.             $userId $this->session->get('impersonated_user');
  41.             if (!empty($userId)) {
  42.                 $user $userService->getOneById($userId);
  43.                 if (empty($user)) {
  44.                     $user $this->getUser();
  45.                 }
  46.                 $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>');
  47.                 $data['impUser'] = $user;
  48.             }
  49.         }
  50.         return $this->render('investor/home.html.twig'array_merge($data, [ 'folders' => $folderService->getFoldersOfUserTree($user)]));
  51.     }
  52.     /**
  53.      *
  54.      * @Route("/investor/my-account", name="investor_my_account")
  55.      * @return Response
  56.      */
  57.     public function investorMyAccount(): Response
  58.     {
  59.         /** @var User $user */
  60.         $user $this->getUser();
  61.         if (!$user->isAcceptedPolicy()) {
  62.             return $this->redirectToRoute('investor_privacy');
  63.         }
  64.         return $this->render('investor/my-account.html.twig', [ 'user' => $user]);
  65.     }
  66.     /**
  67.      *
  68.      * @Route("/investor/privacy", name="investor_privacy")
  69.      * @param UserService $userService
  70.      * @return Response
  71.      */
  72.     public function investorPrivacy(UserService $userService): Response
  73.     {
  74.         /** @var User $user */
  75.         $user $this->getUser();
  76.         return $this->render('investor/privacy.html.twig', [ 'user' => $user]);
  77.     }
  78.     /**
  79.      *
  80.      * @Route("/investor/accept-privacy", name="investor_accept_privacy")
  81.      * @param Request $request
  82.      * @param UserService $userService
  83.      * @return Response
  84.      */
  85.     public function investorAcceptPrivacy(Request $requestUserService $userService): Response
  86.     {
  87.         /** @var User $user */
  88.         $user $this->getUser();
  89.         $userIP $request->getClientIp();
  90.         $userService->acceptPrivacy($user$userIP);
  91.         return $this->redirectToRoute('investor_home');
  92.     }
  93.     /**
  94.      *
  95.      * @Route("/investor/request-new-password", name="investor_request_new_password")
  96.      * @param UserService $userService
  97.      * @return Response
  98.      */
  99.     public function investorRequestNewPassword(UserService $userService,): Response
  100.     {
  101.         /** @var User $user */
  102.         $user $this->getUser();
  103.         $userService->requestNewPassword($user);
  104.         $this->addFlash('info''Password requested successfully');
  105.         return $this->redirectToRoute('investor_my_account');
  106.     }
  107.     /**
  108.      * @Route("/investor/history/{type}/{projectId}", name="investor_history_view_download")
  109.      * @param ProjectService $projectService
  110.      * @param ProjectLogService $projectLogService
  111.      * @param UserService $userService
  112.      * @param string $type
  113.      * @param string $projectId
  114.      * @return Response
  115.      * @throws Exception
  116.      */
  117.     public function investorHistoryDownloadOrView(
  118.         ProjectService $projectService,
  119.         ProjectLogService $projectLogService,
  120.         UserService $userService,
  121.         string $type,
  122.         string $projectId): Response
  123.     {
  124.         /** @var Project $project */
  125.         $project $projectService->getOneById($projectId);
  126.         /** @var User $user */
  127.         $user $this->getUser();
  128.         if (!$user->isAcceptedPolicy()) {
  129.             return $this->redirectToRoute('investor_privacy');
  130.         }
  131.         if ($project) {
  132.             $logs $projectLogService->getLogs($project$user$type);
  133.             return $this->render('investor/partials/logs.html.twig', [
  134.                 'logs' => $logs'title' => ucfirst($type 's'), 'projectTitle' => $project->getName()]);
  135.         }
  136.         throw new Exception('File or project not found');
  137.     }
  138. }