Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added composer.phar
Binary file not shown.
Binary file added composer_2.phar
Binary file not shown.
3 changes: 2 additions & 1 deletion config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/task/*, roles: ROLE_USER }
- { path: ^/tasks/*, roles: ROLE_USER }
- { path: ^/projects/*, roles: ROLE_USER }

# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
31 changes: 0 additions & 31 deletions migrations/Version20220408194827.php

This file was deleted.

31 changes: 0 additions & 31 deletions migrations/Version20220409071443.php

This file was deleted.

32 changes: 0 additions & 32 deletions migrations/Version20220409072039.php

This file was deleted.

31 changes: 0 additions & 31 deletions migrations/Version20220423060135.php

This file was deleted.

65 changes: 65 additions & 0 deletions migrations/Version20220529203600.php
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
Expand Up @@ -10,7 +10,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220423072607 extends AbstractMigration
final class Version20220529203620 extends AbstractMigration
{
public function getDescription(): string
{
Expand All @@ -20,16 +20,16 @@ public function getDescription(): string
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE task ADD author_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB25F675F31B FOREIGN KEY (author_id) REFERENCES user (id)');
$this->addSql('CREATE INDEX IDX_527EDB25F675F31B ON task (author_id)');
$this->addSql('ALTER TABLE task ADD project_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB25166D1F9C FOREIGN KEY (project_id) REFERENCES project (id)');
$this->addSql('CREATE INDEX IDX_527EDB25166D1F9C ON task (project_id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB25F675F31B');
$this->addSql('DROP INDEX IDX_527EDB25F675F31B ON task');
$this->addSql('ALTER TABLE task DROP author_id, CHANGE is_completed is_completed TINYINT(1) DEFAULT NULL');
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB25166D1F9C');
$this->addSql('DROP INDEX IDX_527EDB25166D1F9C ON task');
$this->addSql('ALTER TABLE task DROP project_id');
}
}
77 changes: 77 additions & 0 deletions src/Controller/ProjectController.php
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()

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

->getRepository(Task::class)->findAllByProject($project);

return $this->render('project/project.html.twig', [
'project' => $project,
'tasks' => $tasks
]);
}
}
21 changes: 18 additions & 3 deletions src/Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller;

use App\Entity\Project;
use App\Entity\Task;
use App\Type\TaskFilterType;
use App\Type\TaskType;
Expand All @@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется этот код не нужен.
$form->handleRequest будет заполнять сущность переданную в форму

$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();
Expand Down Expand Up @@ -74,7 +83,6 @@ public function list(Request $request): Response
}



return $this->render('task/list.html.twig', [
'tasks' => $tasks,
'filterForm' => $taskFilterForm->createView()
Expand All @@ -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);

Expand All @@ -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');
}
}
Loading