-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProjectController.php
More file actions
98 lines (83 loc) · 3.06 KB
/
ProjectController.php
File metadata and controls
98 lines (83 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Controller;
use App\Entity\Project;
use App\Entity\Task;
use App\Entity\User;
use App\Type\ProjectType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ProjectController extends AbstractController
{
/**
* @Route("/project/list", name="project_list")
*/
public function index(): Response
{
$projects = $this->getDoctrine()
->getManager()
->getRepository(Project::class)
->getAvailableProject($this->getUser()->getId(),$this->isGranted('ROLE_ADMIN'));
return $this->render('project/index.html.twig', [
'projects' => $projects
]);
}
/**
* @Route("/project/create/form", name="project_create_form")
*/
public function createProjectForm(Request $request): Response
{
$project = new Project();
$form = $this->createForm(ProjectType::class, $project);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$project->setAuthor($this->getUser());
$project->setToken();
$this->getDoctrine()->getManager()->persist($project);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute("project_list");
}
return $this->render('project/create_project_form.html.twig', [
'form' => $form->createView()
]);
}
/**
* @Route("/project/{id}", name="project_byId")
*/
public function projectById($id): Response
{
$project = $this->getDoctrine()->getManager()->find(Project::class, $id);
if($project === null)
throw $this->createNotFoundException("Project with %s not found", $id);
$this->denyAccessUnlessGranted('project_view', $project);
$tasks = $this->getDoctrine()->getRepository(Task::class)
->findBy(['project' => $project]);
return $this->render('project/project.html.twig', [
'project' => $project,
'tasks' => $tasks
]);
}
/**
* @Route("/project/{id}/edit", name="project_byId_edit")
*/
public function projectEdit($id, Request $request): Response
{
$project = $this->getDoctrine()->getManager()->find(Project::class, $id);
if($project === null)
throw $this->createNotFoundException("Project with %s not found", $id);
$this->denyAccessUnlessGranted('project_edit', $project);
$form = $this->createForm(ProjectType::class, $project);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$this->getDoctrine()->getManager()->persist($project);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute("project_list");
}
return $this->render('project/project_edit_form.html.twig', [
'form' => $form->createView()
]);
}
}