CommentDao.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #[RequestScoped]
  8. class CommentDao {
  9. #[Inject]
  10. private EntityManager $em;
  11. /**
  12. * Gebe alle {@see Comment}-Objekte, nach id absteigend sortiert, zurück.
  13. *
  14. * @return Comment[]
  15. */
  16. function getComments(): array {
  17. // http://localhost/php-storm/internship-playground/src-php/public/api/comment/comments/
  18. $criteria = $this->em->createSimpleCriteria(Comment::getClass(), array(), array('id' => 'DESC'));
  19. return $criteria->toQuery()->fetchArray();
  20. }
  21. function getCommentById(int $id): ?Comment {
  22. // http://localhost/php-storm/internship-playground/src-php/public/api/comment/comment/2
  23. return $this->em->find(Comment::getClass(), $id);
  24. }
  25. /* function getCommentById(int $id) {
  26. $criteria = $this->em->createCriteria();
  27. $criteria->select('c.id', 'commentId')
  28. ->select('c.article.id', 'articleId')
  29. ->from(Comment::class , 'c')
  30. ->where(['c.id'=>$id]);
  31. return $criteria->toQuery()->fetchSingle();
  32. } */
  33. }