| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace internship\model;
- use n2n\context\attribute\RequestScoped;
- use n2n\persistence\orm\EntityManager;
- use internship\bo\Category;
- #[RequestScoped]
- class CategoryDao {
- private EntityManager $em;
- private function _init(EntityManager $em): void {
- $this->em = $em;
- }
- /**
- * Gebe alle {@see Category}-Objekte, nach id absteigend sortiert, zurück.
- *
- * @return Category[]
- */
- function getCategories(): array {
- $criteria = $this->em->createSimpleCriteria(Category::getClass(), array(), array('id' => 'DESC'));
- return $criteria->toQuery()->fetchArray();
- }
- /**
- * Gebe den {@see Category} mit der enstprechenden ID zurück.
- */
- function getCategoryById(int $id): ?Category {
- return $this->em->find(Category::getClass(), $id);
- }
- function saveCategory(Category $newCategory): void {
- $this->em->persist($newCategory);
- }
- function removeCategory(int $articleId): void {
- $category = $this->getCategoryById($articleId);
- $this->em->remove($category);
- }
- }
|