ArticleGroupDao.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace internship\model;
  3. use n2n\context\attribute\RequestScoped;
  4. use n2n\persistence\orm\EntityManager;
  5. use internship\bo\Article;
  6. use internship\bo\ArticleGroup;
  7. #[RequestScoped]
  8. class ArticleGroupDao {
  9. private EntityManager $em;
  10. private function _init(EntityManager $em): void {
  11. $this->em = $em;
  12. }
  13. /**
  14. * Gebe alle {@see ArticleGroup}-Objekte, nach id absteigend sortiert, zurück.
  15. *
  16. * @return ArticleGroup[]
  17. */
  18. function getArticleGroups(): array {
  19. $criteria = $this->em->createNqlCriteria("SELECT ag FROM ArticleGroup ag");
  20. return $criteria->toQuery()->fetchArray();
  21. }
  22. /**
  23. * Gebe den {@see ArticleGroup} mit der enstprechenden ID zurück.
  24. *
  25. * @param int $id
  26. * @return ArticleGroup
  27. */
  28. function getArticleGroupById(int $id): ?ArticleGroup {
  29. return $this->em->find(ArticleGroup::getClass(), $id);
  30. }
  31. /**
  32. * Speichere den {@see ArticleGroup}.
  33. *
  34. * @param ArticleGroup $articleGroup
  35. * @return null
  36. */
  37. function saveArticleGroup(ArticleGroup $articleGroup) {
  38. $this->em->persist($articleGroup);
  39. }
  40. /**
  41. * Entferne den {@see ArticleGroup} mit der entsprechenden Id.
  42. *
  43. * @param int $id
  44. * @return void
  45. */
  46. function removeArticleGroup(int $id): void{
  47. $articleGroupToRemove = $this->em->find(ArticleGroup::getClass(), $id);
  48. $this->em->remove($articleGroupToRemove);
  49. }
  50. }