CraftCamp /
official-website
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Manager\Project; |
||
| 4 | |||
| 5 | use Doctrine\ORM\EntityManagerInterface; |
||
| 6 | |||
| 7 | use App\Entity\Project\{ |
||
| 8 | Project, |
||
| 9 | News |
||
| 10 | }; |
||
| 11 | |||
| 12 | class NewsManager |
||
| 13 | { |
||
| 14 | /** @var EntityManagerInterface **/ |
||
| 15 | protected $em; |
||
| 16 | |||
| 17 | public function __construct(EntityManagerInterface $em) |
||
| 18 | { |
||
| 19 | $this->em = $em; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getProjectNews(Project $project): array |
||
| 23 | { |
||
| 24 | return $this->em->getRepository(News::class)->findByProject($project, ['createdAt' => 'DESC']); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | } |
||
| 26 | |||
| 27 | public function create(Project $project, string $category, array $data): News |
||
| 28 | { |
||
| 29 | $news = |
||
| 30 | (new News()) |
||
| 31 | ->setProject($project) |
||
| 32 | ->setCategory($category) |
||
| 33 | ->setData($data) |
||
| 34 | ; |
||
| 35 | $this->em->persist($news); |
||
| 36 | $this->em->flush(); |
||
| 37 | return $news; |
||
| 38 | } |
||
| 39 | } |