-
Notifications
You must be signed in to change notification settings - Fork 10
Задание #8
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
bda-nt
wants to merge
2
commits into
artsofte-php-course:main
Choose a base branch
from
bda-nt: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
Задание #8
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #index: | ||
| # path: / | ||
| # controller: App\Controller\DefaultController::index | ||
| index: | ||
| path: / | ||
| controller: App\Controller\ProjectController::list |
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,34 @@ | ||
| <?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 Version20220602121009 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, author_id INT NOT NULL, key_project VARCHAR(5) NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_2FB3D0EEF675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
| $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEF675F31B FOREIGN KEY (author_id) REFERENCES user (id)'); | ||
| $this->addSql('ALTER TABLE task CHANGE is_completed is_completed TINYINT(1) DEFAULT 0 NOT NULL'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('DROP TABLE project'); | ||
| $this->addSql('ALTER TABLE task 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,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 Version20220602123943 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 task ADD project_id INT 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 INDEX IDX_527EDB25166D1F9C ON task'); | ||
| $this->addSql('ALTER TABLE task DROP project_id'); | ||
| } | ||
| } |
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,80 @@ | ||
| <?php | ||
|
|
||
| namespace App\Controller; | ||
|
|
||
| use App\Entity\Project; | ||
| use App\Entity\Task; | ||
| use App\Form\ProjectType; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use App\Type\TaskFilterType; | ||
| use App\Type\TaskType; | ||
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
| use Symfony\Component\Routing\Annotation\Route; | ||
|
|
||
|
|
||
| class ProjectController extends AbstractController | ||
| { | ||
| /** | ||
| * @Route("/projects", name="project_list") | ||
| */ | ||
| public function list(): Response | ||
| { | ||
| $user = $this->getUser(); | ||
| $projects = $this->getDoctrine()->getManager() | ||
| ->getRepository(Project::class) | ||
| ->getAvailableProjects($user->getId(), $this->isGranted('ROLE_ADMIN')); | ||
| return $this->render('project/list.html.twig', [ | ||
| 'projects' => $projects, | ||
| ]); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @Route("/projects/create", name="project_create") | ||
| */ | ||
| public function create(Request $request): Response | ||
| { | ||
| $project = new Project(); | ||
| $form = $this->createForm(ProjectType::class, $project); | ||
|
|
||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted() && $form->isValid()) { | ||
|
|
||
| $project->setAuthor($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("project/show={id}", name="show_porject") | ||
| * @param $id | ||
| * @return void | ||
| */ | ||
| public function show($id): Response | ||
| { | ||
| $project = $this->getDoctrine()->getManager()->find(Project::class, $id); | ||
|
|
||
| if ($project === null) { | ||
| throw $this->createNotFoundException(sprintf("Project with id %s not found", $id)); | ||
| } | ||
|
|
||
| $tasks = $this->getDoctrine()->getRepository(Task::class) | ||
|
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->getTasks(); |
||
| ->findBy(['project' => $id], []); | ||
|
|
||
| return $this->render('project/show.html.twig',[ | ||
| 'id' => $id, | ||
| 'tasks' => $tasks, | ||
| ]); | ||
| } | ||
| } | ||
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,76 @@ | ||
| <?php | ||
|
|
||
| namespace App\Entity; | ||
|
|
||
| use App\Repository\ProjectRepository; | ||
| use Doctrine\ORM\Mapping as ORM; | ||
|
|
||
| /** | ||
| * @ORM\Entity(repositoryClass=ProjectRepository::class) | ||
| */ | ||
| class Project | ||
| { | ||
| /** | ||
| * @ORM\Id | ||
| * @ORM\GeneratedValue | ||
| * @ORM\Column(type="integer") | ||
| */ | ||
| private $id; | ||
|
|
||
| /** | ||
| * @ORM\Column(type="string", length=5) | ||
| */ | ||
| private $keyProject; | ||
|
|
||
| /** | ||
| * @ORM\Column(type="string", length=255) | ||
| */ | ||
| private $name; | ||
|
|
||
| /** | ||
| * @ORM\ManyToOne(targetEntity=User::class, inversedBy="projects") | ||
| * @ORM\JoinColumn(nullable=false) | ||
| */ | ||
| private $author; | ||
|
|
||
| public function getId(): ?int | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| public function getKeyProject(): ?string | ||
| { | ||
| return $this->keyProject; | ||
| } | ||
|
|
||
| public function setKeyProject(string $keyProject): self | ||
| { | ||
| $this->keyProject = $keyProject; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getName(): ?string | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| public function setName(?string $name): self | ||
| { | ||
| $this->name = $name; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getAuthor(): ?User | ||
| { | ||
| return $this->author; | ||
| } | ||
|
|
||
| public function setAuthor(?User $author): self | ||
| { | ||
| $this->author = $author; | ||
|
|
||
| return $this; | ||
| } | ||
| } |
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
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
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,22 @@ | ||
| <?php | ||
|
|
||
| namespace App\Form; | ||
|
|
||
| use App\Entity\Project; | ||
| use Symfony\Component\Form\AbstractType; | ||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||
| use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
| use Symfony\Component\Form\FormBuilderInterface; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
|
||
| class ProjectType extends AbstractType | ||
| { | ||
| public function buildForm(FormBuilderInterface $builder, array $options): void | ||
| { | ||
| $builder | ||
| ->add('keyProject', TextType::class) | ||
| ->add('name', TextType::class) | ||
| ->add('save', SubmitType::class) | ||
| ; | ||
| } | ||
| } |
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.
Нужно добавить проверку что пользователю доступен данные проект