<?php
// --------------------------------------------------------------------------------
// src/Controller/ProjectManager/ProjectManagerController.php
// --------------------------------------------------------------------------------
namespace App\Controller\ProjectManager;
use App\Entity\Mission\Mission;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\ProjectManager\Blueprint;
use App\Services\Admin\AdminTools;
use App\Services\LogTools;
use App\Services\ProjectManager\NotebookTools;
class ProjectManagerController extends AbstractController
{
public function __construct(ManagerRegistry $doctrine, TranslatorInterface $translator,
LogTools $logTools, AdminTools $adminTools, NotebookTools $notebookTools)
{
$this->em = $doctrine->getManager();
$this->translator = $translator;
$this->logTools = $logTools;
$this->adminTools = $adminTools;
$this->notebookTools = $notebookTools;
}
// Entry point for ProjectManager
public function projectManagerModule(Request $request, Mission $mission): Response
{
// Check if ressource can be accessed by the current user
$this->denyAccessUnlessGranted('can_access_project_manager', $mission);
// Init mandatory values
$access = $this->getUser();
$currentGroup = $access->getSocietyGroup();
// Where do you want to go ?
$route = $request->attributes->get('_route');
// Are we in the right place ?
$readonly = $this->notebookTools->projectNotebookIsReadonlyForMission($mission);
if ($readonly)
{
// Wrong place => Go on the readonly route
$route .= "_readonly";
return $this->redirectToRoute($route, [
'id' => $mission->getId(),
]);
}
$module = null;
switch ($route)
{
case 'icod_platform_project_manager_dashboard':
$module = Blueprint::module_dashboard;
break;
case 'icod_platform_project_manager_site_access':
$module = Blueprint::module_site_access;
break;
// Replaced by App\Controller\Ikea\KitchenPlanner\KitchenPlannerProjectController::add
// case 'icod_platform_project_manager_kitchen_planner':
// $module = Blueprint::module_kitchen_planner;
// break;
case 'icod_platform_project_manager_supports':
$module = Blueprint::module_supports;
break;
case 'icod_platform_project_manager_structure':
$module = Blueprint::module_structure;
break;
case 'icod_platform_project_manager_additional_work':
$module = Blueprint::module_additional_work;
break;
case 'icod_platform_project_manager_technical_layout':
$module = Blueprint::module_technical_layout;
break;
case 'icod_platform_project_manager_appliances':
$module = Blueprint::module_appliances;
break;
// This needs special attention
// case 'icod_platform_project_manager_kitchen_planner_items':
// $module = Blueprint::module_kitchen_planner_items;
// break;
case 'icod_platform_project_manager_worktops':
$module = Blueprint::module_worktops;
break;
case 'icod_platform_project_manager_notes':
$module = Blueprint::module_notes;
break;
case 'icod_platform_project_manager_devis':
$module = Blueprint::module_devis;
break;
case 'icod_platform_project_manager_photos':
$module = Blueprint::module_photos;
break;
}
$returnRoute = "icod_platform_mission_view";
$returnArgs = ['id' => $mission->getId()];
if ($module === null)
{
// This should not happen
// Something went wrong, Inform user
$flashBag = $this->translator->trans('unknown_error');
$this->addFlash('error', $flashBag);
return $this->redirectToRoute($returnRoute, $returnArgs);
}
if (!array_key_exists('view', $module))
{
// This should not happen
// Something went wrong, Inform user
$flashBag = $this->translator->trans('unknown_error');
$this->addFlash('error', $flashBag);
return $this->redirectToRoute($returnRoute, $returnArgs);
}
$data = $this->notebookTools->loadDataForModule($currentGroup, $mission, $access, $module);
if ($data === null)
{
// This should not happen
// Something went wrong, Inform user
$flashBag = $this->translator->trans('unknown_error');
$this->addFlash('error', $flashBag);
return $this->redirectToRoute($returnRoute, $returnArgs);
}
// All looks good
return $this->render($module['view'], $data);
}
public function kitchenPlannerItems(Request $request, Mission $mission): Response
{
$module = Blueprint::module_kitchen_planner_items;
// Check if ressource can be accessed by the current user
$this->denyAccessUnlessGranted('can_access_project_manager', $mission);
// Are we in the right place ?
$readonly = $this->notebookTools->projectNotebookIsReadonlyForMission($mission);
if ($readonly)
{
// Wrong place => Go on the readonly route
$route = $request->attributes->get('_route');
$route .= "_readonly";
return $this->redirectToRoute($route, [
'id' => $mission->getId(),
]);
}
// Init mandatory values
$access = $this->getUser();
$currentGroup = $access->getSocietyGroup();
$data = $this->notebookTools->loadDataForModule($currentGroup, $mission, $access, $module);
if ($data === null)
{
// This should not happen
// Something went wrong, Inform user
$flashBag = $this->translator->trans('unknown_error');
$this->addFlash('error', $flashBag);
return $this->redirectToRoute('icod_platform_mission_view', [
'id' => $mission->getId()
]);
}
// KitchenPlanner project exists => Load tool
$kpProject = $data['projectNotebook']->getKitchenPlannerProject();
if ($kpProject !== null)
{
return $this->redirectToRoute('icod_platform_ikea_kp_pages_annotation_tool', [
'uid' => $kpProject->getUid(),
'viewKey' => 'product',
]);
}
// KitchenPlanner project does not exist => Load empty page
return $this->render('project_manager/modules/kitchen_planner_items.html.twig', $data);
}
}