| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace internship\model;
- use n2n\persistence\orm\EntityManager;
- use n2n\context\attribute\RequestScoped;
- use internship\bo\Comment;
- use n2n\context\attribute\Inject;
- #[RequestScoped]
- class CommentDao {
- #[Inject]
- private EntityManager $em;
- /**
- * Gebe alle {@see Comment}-Objekte, nach id absteigend sortiert, zurück.
- *
- * @return Comment[]
- */
- function getComments(): array {
- // http://localhost/php-storm/internship-playground/src-php/public/api/comment/comments/
- $criteria = $this->em->createSimpleCriteria(Comment::getClass(), array(), array('id' => 'DESC'));
- return $criteria->toQuery()->fetchArray();
- }
- function getCommentById(int $id): ?Comment {
- // http://localhost/php-storm/internship-playground/src-php/public/api/comment/comment/2
- return $this->em->find(Comment::getClass(), $id);
- }
- /* function getCommentById(int $id) {
- $criteria = $this->em->createCriteria();
- $criteria->select('c.id', 'commentId')
- ->select('c.article.id', 'articleId')
- ->from(Comment::class , 'c')
- ->where(['c.id'=>$id]);
- return $criteria->toQuery()->fetchSingle();
- } */
- }
|