-
Notifications
You must be signed in to change notification settings - Fork 10
Lesson 2.8 #3
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
Open
ArtyomYaprintsev
wants to merge
4
commits into
artsofte-php-course:main
Choose a base branch
from
ArtyomYaprintsev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lesson 2.8 #3
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1433e2f
Lesson 2.8
ArtyomYaprintsev 90b78ec
Комит со всеми нужными функциями
ArtyomYaprintsev 1a11d91
Постарался убрать все основные ошибки, список изменений напишу в теле…
ArtyomYaprintsev 8be23c2
Доделал воутеры для проектов и тасков, внёс их в шаблоны
ArtyomYaprintsev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?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 Version20220506101824 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->addSql('CREATE TABLE project (id INT AUTO_INCREMENT NOT NULL, owner_id INT DEFAULT NULL, `key` VARCHAR(5) NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_2FB3D0EE7E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
| $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE7E3C61F9 FOREIGN KEY (owner_id) REFERENCES user (id)'); | ||
| $this->addSql('ALTER TABLE task ADD project_id INT DEFAULT NULL, CHANGE is_completed is_completed TINYINT(1) DEFAULT 0 NOT 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_527EDB25166D1F9C'); | ||
| $this->addSql('DROP TABLE project'); | ||
| $this->addSql('DROP INDEX IDX_527EDB25166D1F9C ON task'); | ||
| $this->addSql('ALTER TABLE task DROP project_id, CHANGE is_completed is_completed TINYINT(1) DEFAULT NULL'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?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 Version20220506111051 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->addSql('ALTER TABLE project CHANGE `key` `key` VARCHAR(255) NOT NULL'); | ||
| $this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE8A90ABA9 ON project (`key`)'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('DROP INDEX UNIQ_2FB3D0EE8A90ABA9 ON project'); | ||
| $this->addSql('ALTER TABLE project CHANGE `key` `key` VARCHAR(5) NOT NULL'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?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 Version20220506132158 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->addSql('DROP INDEX UNIQ_2FB3D0EE8A90ABA9 ON project'); | ||
| $this->addSql('ALTER TABLE project CHANGE `key` project_key VARCHAR(255) NOT NULL'); | ||
| $this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE18EB714A ON project (project_key)'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('DROP INDEX UNIQ_2FB3D0EE18EB714A ON project'); | ||
| $this->addSql('ALTER TABLE project CHANGE project_key `key` VARCHAR(255) NOT NULL'); | ||
| $this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE8A90ABA9 ON project (`key`)'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| <?php | ||
|
|
||
| namespace App\Controller; | ||
|
|
||
| use App\Entity\Project; | ||
| use App\Entity\Task; | ||
| use App\Type\ProjectType; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use const http\Client\Curl\PROXY_HTTP; | ||
| use Symfony\Component\Routing\Annotation\Route; | ||
|
|
||
| class ProjectController extends AbstractController | ||
| { | ||
|
|
||
| /** | ||
| * @Route("/projects", name="project_list") | ||
| * @return Response | ||
| */ | ||
|
|
||
| public function list(Request $request): Response | ||
| { | ||
| $user = $this->getUser(); | ||
| $projectRepository = $this->getDoctrine() -> getManager() -> getRepository(Project::class); | ||
|
|
||
| $projects = $projectRepository->findByUserRole($user->getId()); | ||
|
|
||
| return $this -> render("projects/list.html.twig", [ | ||
| "projects" => $projects, | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @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("projects/create.html.twig", [ | ||
| "form" => $form -> createView(), | ||
| "action" => "create" | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/projects/{slug}", name="project_show") | ||
| * @return Response | ||
| */ | ||
| public function show($slug, Request $request): Response | ||
| { | ||
| $project = $this->getDoctrine()->getRepository(Project::class)->findOneBy(["projectKey" => $slug]); | ||
| // dd($project); | ||
|
|
||
| $this->denyAccessUnlessGranted('view', $project); | ||
|
|
||
| if ($project === null) { | ||
| throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug)); | ||
| } | ||
|
|
||
| $tasks = $project -> getTasks(); | ||
|
|
||
| return $this->render('task/project_tasks.html.twig', [ | ||
| 'tasks' => $tasks, | ||
| "project_name" => $project -> getName(), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/projects/{slug}/edit", name="project_edit") | ||
| * @param $slug | ||
| * @param Request $request | ||
| * @return Response | ||
| */ | ||
| public function edit($slug, Request $request): Response | ||
|
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. Также нет проверки на доступность |
||
| { | ||
| $project = $this->getDoctrine()->getRepository(Project::class) -> findOneBy(["projectKey" => $slug]); | ||
|
|
||
| $this->denyAccessUnlessGranted('edit', $project); | ||
|
|
||
| if ($project === null) { | ||
| throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug)); | ||
| } | ||
|
|
||
| $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("projects/create.html.twig", [ | ||
| "form" => $form->createView(), | ||
| "action" => "edit", | ||
| "slug" => $slug | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/projects/{slug}/delete", name="project_delete") | ||
| * @param $slug | ||
| * @param Request $request | ||
| * @return Response | ||
| */ | ||
| public function delete($slug, Request $request): Response | ||
| { | ||
| $em = $this->getDoctrine()->getManager(); | ||
| $project = $this->getDoctrine()->getRepository( | ||
| Project::class) -> findOneBy(["projectKey" => $slug]); | ||
|
|
||
| $this->denyAccessUnlessGranted('delete', $project); | ||
|
|
||
| if ($project === null) { | ||
| throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug)); | ||
| } | ||
|
|
||
| $em -> remove($project); | ||
| $em -> flush(); | ||
|
|
||
| return $this->redirectToRoute("project_list"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Нет проверки что проект доступен пользователю.
Нужно добавить, реализовать через Voter
https://symfony.com/doc/4.4/security/voters.html