<?php
namespace App\Controller\Project;
use App\Entity\Project;
use App\Entity\Workroom;
use App\Entity\WorkroomArena;
use App\Form\Project\ProjectPrivateUpdateType;
use App\Form\Project\ProjectRequestPublishedType;
use App\Form\Project\WorkroomType;
use App\Form\Workroom\ArenaInvitationsType;
use App\Form\Workroom\ArenaType;
use App\Form\Workroom\SectionArenaType;
use App\Form\Workroom\SectionRenameType;
use App\Form\Workroom\SectionType;
use App\Form\Workroom\WorkroomInvitationsType;
use App\Form\Workroom\WorkroomRenameType;
use App\Form\Workroom\WorkroomRevisionType;
use App\Security\Voter\UserProjectVoter;
use App\Service\Account\SattAccountService;
use App\Service\Common\SattFormService;
use App\Service\Project\SattProjectService;
use App\Service\Workroom\SattWorkroomService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class ManageController.
*/
class ManageController extends AbstractController
{
private SattFormService $sattForm;
private EntityManagerInterface $entityManager;
private SattProjectService $sattProjectService;
private SattWorkroomService $sattWorkroomService;
private SattAccountService $sattAccountService;
private RequestStack $requestStack;
/**
* AccountController constructor.
*/
public function __construct(
SattFormService $sattForm,
EntityManagerInterface $entityManager,
SattProjectService $sattProjectService,
SattWorkroomService $sattWorkroomService,
SattAccountService $sattAccountService,
RequestStack $requestStack
) {
$this->sattForm = $sattForm;
$this->entityManager = $entityManager;
$this->sattProjectService = $sattProjectService;
$this->sattWorkroomService = $sattWorkroomService;
$this->sattAccountService = $sattAccountService;
$this->requestStack = $requestStack;
}
#[Route(path: '/project/informations/{id}', name: 'project_info')]
public function projectInformations(Project $project): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP_AND_WL, $project);
$form = $this->createForm(ProjectPrivateUpdateType::class, $project);
return $this->render(
'project/index.html.twig',
[
'project' => $project,
'user' => $this->getUser(),
'projectPrivateUpdateForm' => $form->createView(),
]
);
}
#[Route(path: '/project/members/{id}', name: 'project_members')]
public function projectMembers(Project $project): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP_AND_WL, $project);
$session = $this->requestStack->getSession();
$session->set('project_id', $project->getId());
$user = $this->getUser();
// Get all users email Labomega
$emails = $this->sattAccountService->getEmailsLabomega($user->getEmail());
return $this->render('project/members.html.twig',
[
'project' => $project,
'user' => $user,
'emailsLabo' => $emails,
'workroomInvitationsForm' => $this->createForm(WorkroomInvitationsType::class)->createView(),
'arenaInvitationsForm' => $this->createForm(ArenaInvitationsType::class)->createView(),
]
);
}
#[Route(path: '/project/workrooms/{id}', name: 'project_workrooms', options: ['expose' => true])]
public function workrooms(Project $project): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP, $project);
// Get all workrooms of the current project
$workroomsProject = $this->sattWorkroomService->getAllWorkroomsOfProject($project);
$user = $this->getUser();
// Get all users email Labomega
$emails = $this->sattAccountService->getEmailsLabomega($user->getEmail());
$arenaForm = $this->createForm(ArenaType::class);
return $this->render('project/workrooms.html.twig',
[
'project' => $project,
'workrooms' => $workroomsProject,
'user' => $user,
'emailsLabo' => $emails,
'workroomForm' => $this->createForm(WorkroomType::class)->createView(),
'arenaForm' => $arenaForm->createView(),
]
);
}
#[Route(path: '/project/workroom/{id}', name: 'project_workroom')]
public function workroom(Workroom $workroom): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP, $workroom->getProject());
$session = $this->requestStack->getSession();
$session->set('workroom_id', (int) $workroom->getId());
return $this->render('project/workroom.html.twig',
[
'project' => $workroom->getProject(),
'workroomCurrent' => $workroom,
'user' => $this->getUser(),
'sectionForm' => $this->createForm(SectionType::class)->createView(),
'sectionRenameForm' => $this->createForm(SectionRenameType::class)->createView(),
'workroomRevisionForm' => $this->createForm(WorkroomRevisionType::class)->createView(),
'workroomRenameForm' => $this->createForm(WorkroomRenameType::class)->createView(),
'workroomArenaForm' => $this->createForm(ArenaType::class)->createView(),
]
);
}
#[Route(path: '/project/arena/{id}', name: 'project_arena')]
public function arena(WorkroomArena $workroomArena): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP, $workroomArena->getWorkroom()->getProject());
$session = $this->requestStack->getSession();
$session->set('workroom_arena_id', (int) $workroomArena->getId());
$workroom = $workroomArena->getWorkroom();
return $this->render('project/arena.html.twig',
[
'project' => $workroom->getProject(),
'workroomArenaCurrent' => $workroomArena,
'workroomCurrent' => $workroom,
'user' => $this->getUser(),
'sectionForm' => $this->createForm(SectionArenaType::class)->createView(),
'sectionRenameForm' => $this->createForm(SectionRenameType::class)->createView(),
]
);
}
#[Route(path: '/project/revisions/{id}', name: 'project_revisions')]
public function projectRevisions(Project $project): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP, $project);
return $this->render('project/revisions.html.twig',
[
'project' => $project,
'user' => $this->getUser(),
'revisionRenameForm' => $this->createForm(WorkroomRevisionType::class)->createView(),
]
);
}
#[Route(path: '/project/actions/{id}', name: 'project_actions')]
public function projectActions(Project $project): Response
{
$this->denyAccessUnlessGranted(UserProjectVoter::PROJECT_MANAGE_VIEW_CDP, $project);
$session = $this->requestStack->getSession();
$session->set('project_id', $project->getId());
return $this->render('project/actions.html.twig',
[
'project' => $project,
'user' => $this->getUser(),
'projectRequestPublishedForm' => $this->createForm(ProjectRequestPublishedType::class)->createView(),
]
);
}
}