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