diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php new file mode 100644 index 0000000..f154dfc --- /dev/null +++ b/src/Controller/ProjectController.php @@ -0,0 +1,85 @@ +getUser(); + if (in_array("ROLE_ADMIN", $user->getRoles())) { + $projects = $this->getDoctrine()->getManager()->getRepository(Project::class)->findAll(); + } else { + $projects = $this->getDoctrine()->getManager()->getRepository(Project::class)->findBy(['owner' => $user]); + } + return $this->render('project/list.html.twig', [ + 'projects' => $projects + ]); + } + /** + * @Route("/project/create", name="createProject") + */ + public function create(Request $request): Response + { + $project = new Project(); + $form = $this->createForm(ProjectType::class, $project); + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $project->setOwner($this->getUser()); + $project->setKeyProject(); + $this->getDoctrine()->getManager()->persist($project); + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('listProject'); + } + return $this->render("project/add.html.twig", [ + 'form' => $form->createView() + ]); + } + + /** + * @Route("/project/{keyProject}/change", name="changeProject") + */ + public function change($keyProject, Request $request): Response + { + $project = $this->getDoctrine()->getRepository(Project::class)->findOneBy(["keyProject" => $keyProject]); + $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("listProject"); + } + return $this->render("project/change.html.twig", [ + "keyProject" => $keyProject, + "form" => $form->createView() + ]); + } + + /** + * @Route("/project/{keyProject}", name="infoProject") + */ + public function projectInfo($keyProject): Response + { + $tasks = $this->getDoctrine()->getRepository(Task::class) + ->findBy(['project' => $keyProject], []); + return $this->render('project/project.html.twig', [ + 'tasks' => $tasks, + '$keyProject' => $keyProject + ]); + } + + + + +} \ No newline at end of file diff --git a/src/Controller/TaskController.php b/src/Controller/TaskController.php index 0d9f9ad..0f368e4 100644 --- a/src/Controller/TaskController.php +++ b/src/Controller/TaskController.php @@ -5,6 +5,7 @@ use App\Entity\Task; use App\Type\TaskFilterType; use App\Type\TaskType; +use App\Entity\Project; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; @@ -22,12 +23,12 @@ class TaskController extends AbstractController public function create(Request $request): Response { $task = new Task(); - $form = $this->createForm(TaskType::class, $task); + + $form = $this->createForm(TaskType::class,$task); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $task->setAuthor($this->getUser()); $this->getDoctrine()->getManager()->persist($task); @@ -44,6 +45,7 @@ public function create(Request $request): Response /** * @Route("/tasks", name="task_list") + * @param Request $request * @return Response */ public function list(Request $request): Response @@ -74,7 +76,6 @@ public function list(Request $request): Response } - return $this->render('task/list.html.twig', [ 'tasks' => $tasks, 'filterForm' => $taskFilterForm->createView() diff --git a/src/Entity/Project.php b/src/Entity/Project.php new file mode 100644 index 0000000..c4d01b6 --- /dev/null +++ b/src/Entity/Project.php @@ -0,0 +1,78 @@ +owner; + } + + public function setOwner(UserInterface $owner = null) + { + $this->owner = $owner; + } + + public function getId() + { + return $this -> id; + } + + public function getKeyproject(): ?string + { + return $this->keyProject; + } + + public function setKeyProject(string $keyProject = null): self + { + $this->keyProject = $this->createKey(); + return $this; + } + + private function createKey(): string + { + return substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyz-_', 1)), 1, 5); + } + + public function getName() + { + return $this -> name; + } + + public function setName($name): void + { + $this -> name = $name; + } +} diff --git a/src/Entity/Task.php b/src/Entity/Task.php index 66a4b57..227d131 100644 --- a/src/Entity/Task.php +++ b/src/Entity/Task.php @@ -55,6 +55,12 @@ class Task */ protected $author; + /** + * @ORM\ManyToOne(targetEntity="App\Entity\Project", inversedBy="project") + * @var Project + */ + protected $project; + /** * Create empty task */ @@ -64,6 +70,24 @@ public function __construct() $this->isCompleted = false; } + /** + * @param Project|null $project + * @return void + */ + public function setProject(Project $project = null) + { + $this->project = $project; + } + + + /** + * @return Project|null + */ + public function getProject() + { + return $this->project; + } + /** * Set task Author @@ -80,7 +104,7 @@ public function setAuthor(UserInterface $author = null) * Return task author * @return User|null */ - public function getAuthor() + public function getAuthor(): ?User { return $this->author; } diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php new file mode 100644 index 0000000..469a6f7 --- /dev/null +++ b/src/Repository/ProjectRepository.php @@ -0,0 +1,17 @@ +add('name', TextType::class) + ->add('save', SubmitType::class) + ; + } + +} \ No newline at end of file diff --git a/src/Type/TaskType.php b/src/Type/TaskType.php index 3b58193..b533f0c 100644 --- a/src/Type/TaskType.php +++ b/src/Type/TaskType.php @@ -2,6 +2,8 @@ namespace App\Type; +use App\Entity\Project; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -19,6 +21,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('dueDate', DateType::class, [ 'years' => range(2022,2023) ]) + ->add('project', EntityType::class, [ + 'class' => Project::class + ]) + ->add('save', SubmitType::class) ; } diff --git a/templates/project/add.html.twig b/templates/project/add.html.twig new file mode 100644 index 0000000..41f11ab --- /dev/null +++ b/templates/project/add.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+
+
+ {{ form(form, {'action': path("createProject"), 'method': 'POST'}) }} +
+
+
+
+
+{% endblock %} diff --git a/templates/project/change.html.twig b/templates/project/change.html.twig new file mode 100644 index 0000000..076bd57 --- /dev/null +++ b/templates/project/change.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+
+
+ {{form(form,{'action':path('changeProject',{"keyProject": keyProject}),'method':'POST'})}} +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/project/list.html.twig b/templates/project/list.html.twig new file mode 100644 index 0000000..c9848d3 --- /dev/null +++ b/templates/project/list.html.twig @@ -0,0 +1,39 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
+
+
+
+
+ + + + + + + + + + + + + {% for project in projects %} + + +{# #} + + + + + {% endfor %} + +
Ключ проектаНазвание проектаАвтор проектаИзменить
{{project.keyProject}}{{ project.keyProject }}{{ project.name }}{{ project.owner }}X
+

Создать проект

+

Список задач

+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/project/project.html.twig b/templates/project/project.html.twig new file mode 100644 index 0000000..a8d1f7a --- /dev/null +++ b/templates/project/project.html.twig @@ -0,0 +1,44 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
+
+
+
+
+ + + + + + + + + + + + + + {% for task in tasks %} + + + + + + + + + + {% endfor %} + +
#НазваниеОписаниеСрок выполненияАвторВыполненаДействия
{{ task.id }}{{ task.name }}{{ task.description }}{{ task.dueDate|date("d.m.Y") }}{{ task.author }}{{ task.isCompleted ? 'Выполнена' : 'Не выполнена' }} + {% if (is_granted("complete", task)) %} + Сделано + {% endif %} +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/task/list.html.twig b/templates/task/list.html.twig index 0d50fd4..24e0566 100644 --- a/templates/task/list.html.twig +++ b/templates/task/list.html.twig @@ -38,8 +38,8 @@ - Создать задачу - +

Создать задачу

+

Список проектов