NewsDao.php 881 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace internship\model;
  3. use n2n\persistence\orm\EntityManager;
  4. use n2n\context\attribute\RequestScoped;
  5. use internship\bo\Comment;
  6. use n2n\context\attribute\Inject;
  7. use internship\bo\News;
  8. use internship\bo\Article;
  9. use internship\bo\MainNews;
  10. #[RequestScoped]
  11. class NewsDao {
  12. #[Inject]
  13. private EntityManager $em;
  14. /**
  15. * Gebe alle {@see Comment}-Objekte, nach id absteigend sortiert, zurück.
  16. *
  17. * @return Comment[]
  18. *
  19. * http://localhost/php-storm/internship-playground/src-php/public/api/news/news
  20. */
  21. function getNews(): array {
  22. $criteria = $this->em->createSimpleCriteria(News::getClass(), array(), array('id' => 'DESC'));
  23. return $criteria->toQuery()->fetchArray();
  24. }
  25. function getNewsById(int $id): ?News {
  26. return $this->em->find(News::getClass(), $id);
  27. }
  28. function saveNews(News $newArticle): void {
  29. $this->em->persist($newArticle);
  30. }
  31. }