src/Controller/ProjectManager/ProjectManagerController.php line 36

Open in your IDE?
  1. <?php
  2. // --------------------------------------------------------------------------------
  3. // src/Controller/ProjectManager/ProjectManagerController.php
  4. // --------------------------------------------------------------------------------
  5. namespace App\Controller\ProjectManager;
  6. use App\Entity\Mission\Mission;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpKernel\Exception\HttpException;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use App\Entity\ProjectManager\Blueprint;
  15. use App\Services\Admin\AdminTools;
  16. use App\Services\LogTools;
  17. use App\Services\ProjectManager\NotebookTools;
  18. class ProjectManagerController extends AbstractController
  19. {
  20.     public function __construct(ManagerRegistry $doctrineTranslatorInterface $translator
  21.         LogTools $logToolsAdminTools $adminToolsNotebookTools $notebookTools)
  22.     {
  23.         $this->em $doctrine->getManager();       
  24.         $this->translator $translator;
  25.         $this->logTools $logTools;
  26.         $this->adminTools $adminTools;
  27.         $this->notebookTools $notebookTools;
  28.     }
  29.     
  30.     // Entry point for ProjectManager
  31.     public function projectManagerModule(Request $requestMission $mission): Response
  32.     {
  33.         // Check if ressource can be accessed by the current user
  34.         $this->denyAccessUnlessGranted('can_access_project_manager'$mission);
  35.         // Init mandatory values
  36.         $access $this->getUser();
  37.         $currentGroup $access->getSocietyGroup(); 
  38.         
  39.         // Where do you want to go ?
  40.         $route $request->attributes->get('_route');
  41.         // Are we in the right place ?
  42.         $readonly $this->notebookTools->projectNotebookIsReadonlyForMission($mission);
  43.         if ($readonly)
  44.         {
  45.             // Wrong place => Go on the readonly route
  46.             $route .= "_readonly";
  47.             return $this->redirectToRoute($route, [
  48.                 'id'    =>  $mission->getId(),
  49.             ]);
  50.         }
  51.         $module null;
  52.         switch ($route)
  53.         {
  54.             case 'icod_platform_project_manager_dashboard':
  55.                 $module Blueprint::module_dashboard;
  56.                 break;
  57.             case 'icod_platform_project_manager_site_access':
  58.                 $module Blueprint::module_site_access;
  59.                 break;
  60.             // Replaced by App\Controller\Ikea\KitchenPlanner\KitchenPlannerProjectController::add
  61.             // case 'icod_platform_project_manager_kitchen_planner':
  62.             //     $module = Blueprint::module_kitchen_planner;
  63.             //     break;
  64.             case 'icod_platform_project_manager_supports':
  65.                 $module Blueprint::module_supports;
  66.                 break;
  67.             case 'icod_platform_project_manager_structure':
  68.                 $module Blueprint::module_structure;
  69.                 break;
  70.             case 'icod_platform_project_manager_additional_work':
  71.                 $module Blueprint::module_additional_work;
  72.                 break;
  73.             case 'icod_platform_project_manager_technical_layout':
  74.                 $module Blueprint::module_technical_layout;
  75.                 break;
  76.             case 'icod_platform_project_manager_appliances':
  77.                 $module Blueprint::module_appliances;
  78.                 break;
  79.             // This needs special attention
  80.             // case 'icod_platform_project_manager_kitchen_planner_items':
  81.             //     $module = Blueprint::module_kitchen_planner_items;
  82.             //     break;
  83.             case 'icod_platform_project_manager_worktops':
  84.                 $module Blueprint::module_worktops;
  85.                 break;
  86.             case 'icod_platform_project_manager_notes':
  87.                 $module Blueprint::module_notes;
  88.                 break;
  89.             case 'icod_platform_project_manager_devis':
  90.                 $module Blueprint::module_devis;
  91.                 break;
  92.             case 'icod_platform_project_manager_photos':
  93.                 $module Blueprint::module_photos;
  94.                 break;
  95.         }
  96.         $returnRoute "icod_platform_mission_view";
  97.         $returnArgs = ['id' => $mission->getId()];
  98.         if ($module === null)
  99.         {
  100.             // This should not happen
  101.             // Something went wrong, Inform user
  102.             $flashBag $this->translator->trans('unknown_error');
  103.             $this->addFlash('error'$flashBag);
  104.             return $this->redirectToRoute($returnRoute$returnArgs);            
  105.         }  
  106.         
  107.         if (!array_key_exists('view'$module))
  108.         {
  109.             // This should not happen
  110.             // Something went wrong, Inform user
  111.             $flashBag $this->translator->trans('unknown_error');
  112.             $this->addFlash('error'$flashBag);
  113.             return $this->redirectToRoute($returnRoute$returnArgs);              
  114.         }
  115.         $data $this->notebookTools->loadDataForModule($currentGroup$mission$access$module);
  116.         if ($data === null)
  117.         {
  118.             // This should not happen
  119.             // Something went wrong, Inform user
  120.             $flashBag $this->translator->trans('unknown_error');
  121.             $this->addFlash('error'$flashBag);
  122.             return $this->redirectToRoute($returnRoute$returnArgs); 
  123.         }   
  124.         // All looks good
  125.         return $this->render($module['view'], $data);
  126.     }
  127.     public function kitchenPlannerItems(Request $requestMission $mission): Response
  128.     {
  129.         $module Blueprint::module_kitchen_planner_items;
  130.         // Check if ressource can be accessed by the current user
  131.         $this->denyAccessUnlessGranted('can_access_project_manager'$mission);
  132.         // Are we in the right place ?
  133.         $readonly $this->notebookTools->projectNotebookIsReadonlyForMission($mission);
  134.         if ($readonly)
  135.         {
  136.             // Wrong place => Go on the readonly route
  137.              $route $request->attributes->get('_route');
  138.             $route .= "_readonly";
  139.             return $this->redirectToRoute($route, [
  140.                 'id'    =>  $mission->getId(),
  141.             ]);
  142.         }
  143.         
  144.         // Init mandatory values
  145.         $access $this->getUser();
  146.         $currentGroup $access->getSocietyGroup(); 
  147.         $data $this->notebookTools->loadDataForModule($currentGroup$mission$access$module);
  148.         if ($data === null)
  149.         {
  150.             // This should not happen
  151.             // Something went wrong, Inform user
  152.             $flashBag $this->translator->trans('unknown_error');
  153.             $this->addFlash('error'$flashBag);
  154.             return $this->redirectToRoute('icod_platform_mission_view', [
  155.                 'id'    =>  $mission->getId()
  156.             ]);
  157.         }   
  158.         // KitchenPlanner project exists => Load tool
  159.         $kpProject $data['projectNotebook']->getKitchenPlannerProject();
  160.         if ($kpProject !== null)
  161.         {
  162.             return $this->redirectToRoute('icod_platform_ikea_kp_pages_annotation_tool', [
  163.                 'uid'       => $kpProject->getUid(),
  164.                 'viewKey'   => 'product',
  165.             ]);
  166.         }
  167.         // KitchenPlanner project does not exist => Load empty page
  168.         return $this->render('project_manager/modules/kitchen_planner_items.html.twig'$data);
  169.     }
  170. }