Skip to content

Дьяченко Максим - РИ-200003#6

Open
prsntday wants to merge 6 commits intoartsofte-php-course:mainfrom
prsntday:main
Open

Дьяченко Максим - РИ-200003#6
prsntday wants to merge 6 commits intoartsofte-php-course:mainfrom
prsntday:main

Conversation

@prsntday
Copy link

Доделал все пункты из ТЗ и проверил. Всё работает

$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

// 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 будет заполнять сущность переданную в форму

return $this->filterByUser($allProjects, $user);
}

private function filterByUser(array $projects, User $user): array{

Choose a reason for hiding this comment

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

Это лучше сделать с помощью SQL, JOIN + WHERE, см пример
https://symfony.com/doc/4.4/doctrine/associations.html#joining-related-records

return $this->filterByProject($allTasks, $project);
}

private function filterByProject(array $tasks, Project $project): array{

Choose a reason for hiding this comment

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

Аналогично ProjectRepository, фильтрацию лучше делать через SQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants