-
Notifications
You must be signed in to change notification settings - Fork 10
Дьяченко Максим - РИ-200003 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| /** | ||
| * Auto-generated Migration: Please modify to your needs! | ||
| */ | ||
| final class Version20220529203600 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return ''; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| // this up() migration is auto-generated, please modify it to your needs | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('CREATE TABLE project (id INT AUTO_INCREMENT NOT NULL, owner_id INT DEFAULT NULL, token VARCHAR(5) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, INDEX IDX_2FB3D0EE7E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, description TINYTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, due_date DATE NOT NULL, is_completed TINYINT(1) DEFAULT 0 NOT NULL, INDEX IDX_527EDB25F675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, roles LONGTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(DC2Type:json)\', password VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('DROP TABLE project'); | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('DROP TABLE task'); | ||
| $this->abortIf( | ||
| !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform, | ||
| "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'." | ||
| ); | ||
|
|
||
| $this->addSql('DROP TABLE user'); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
|
|
||
| namespace App\Controller; | ||
|
|
||
| use App\Entity\Project; | ||
| use App\Entity\Task; | ||
| use App\Repository\ProjectRepository; | ||
| use App\Type\ProjectType; | ||
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Routing\Annotation\Route; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| class ProjectController extends AbstractController | ||
| { | ||
| /** | ||
| * | ||
| * @Route("/projects/create", name="project_create") | ||
| * @param Request $request | ||
| * @return Response | ||
| */ | ||
| 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()); | ||
|
|
||
| $this->getDoctrine()->getManager()->persist($project); | ||
| $this->getDoctrine()->getManager()->flush(); | ||
|
|
||
| return $this->redirectToRoute('project_list'); | ||
| } | ||
|
|
||
| return $this->render("project/create.html.twig", [ | ||
| 'form' => $form->createView() | ||
| ]); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @Route("/projects", name = "project_list") | ||
| * @return Response | ||
| */ | ||
| public function list(Request $request): Response | ||
| { | ||
| $projects = $this->getDoctrine()->getManager() | ||
| ->getRepository(Project::class)->findAllByUser($this->getUser()); | ||
| return $this->render('project/list.html.twig', [ | ||
| 'projects' => $projects, | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/projects/{id}", name="project_page") | ||
| * @param $id | ||
| * @return Response | ||
| */ | ||
| public function projectPage($id): Response | ||
| { | ||
| $project = $this->getDoctrine()->getManager() | ||
| ->getRepository(Project::class)->findOneBy(['token' => $id]); | ||
|
|
||
| $tasks = $this->getDoctrine()->getManager() | ||
| ->getRepository(Task::class)->findAllByProject($project); | ||
|
|
||
| return $this->render('project/project.html.twig', [ | ||
| 'project' => $project, | ||
| 'tasks' => $tasks | ||
| ]); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| namespace App\Controller; | ||
|
|
||
| use App\Entity\Project; | ||
| use App\Entity\Task; | ||
| use App\Type\TaskFilterType; | ||
| use App\Type\TaskType; | ||
|
|
@@ -22,13 +23,21 @@ 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, ["data" => $this->getDoctrine()->getManager() | ||
| ->getRepository(Project::class)->findAllByUser($this->getUser())]); | ||
|
|
||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted() && $form->isValid()) { | ||
|
|
||
| // var_dump($form); | ||
|
|
||
| $task->setAuthor($this->getUser()); | ||
| $task->setName($form->get('name')->getData()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кажется этот код не нужен. |
||
| $task->setDueDate($form->get('dueDate')->getData()); | ||
| $task->setDescription($form->get('description')->getData()); | ||
| $task->setProject($this->getDoctrine()->getManager() | ||
| ->getRepository(Project::class)->find($form->get('project')->getData())); | ||
|
|
||
| $this->getDoctrine()->getManager()->persist($task); | ||
| $this->getDoctrine()->getManager()->flush(); | ||
|
|
@@ -74,7 +83,6 @@ public function list(Request $request): Response | |
| } | ||
|
|
||
|
|
||
|
|
||
| return $this->render('task/list.html.twig', [ | ||
| 'tasks' => $tasks, | ||
| 'filterForm' => $taskFilterForm->createView() | ||
|
|
@@ -86,8 +94,11 @@ public function list(Request $request): Response | |
| * @IsGranted("ROLE_USER") | ||
| * @return Response | ||
| */ | ||
| public function complete($id): Response | ||
| public function complete(Request $request): Response | ||
| { | ||
| $id = $request->get('id'); | ||
| $token = $request->get('token'); | ||
|
|
||
| /** @var Task $task */ | ||
| $task = $this->getDoctrine()->getManager()->find(Task::class, $id); | ||
|
|
||
|
|
@@ -102,6 +113,10 @@ public function complete($id): Response | |
| $this->getDoctrine()->getManager()->persist($task); | ||
| $this->getDoctrine()->getManager()->flush(); | ||
|
|
||
| if ($token !== null) { | ||
| return $this->redirectToRoute('project_page', ["id" => $token]); | ||
| } | ||
|
|
||
| return $this->redirectToRoute('task_list'); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно делать через $project->getTasks(); предварительно добавив в сущность Project $tasks.
Пример:
https://symfony.com/doc/4.4/doctrine/associations.html#mapping-the-manytoone-relationship