m('categoryDetail', new AnnoPath('/urlPart:*')); $ai->m('newsDetail', new AnnoPath('newsCategoryUrlPart:*/detail/newsItemUrlPart:*/id:*')); } private NewsDao $newsDao; private function _init(NewsDao $newsDao) { $this->newsDao = $newsDao; } #[Inject] private MessageContainer $mc; public function index() { $newsCategories = $this->newsDao->getNewsCategories(); $this->forward('~\view\overview.html', ['newsCategories' => $newsCategories, 'mc' => $this->mc]); } public function categoryDetail( string $urlPart) { $NewsCategory = $this->newsDao->getNewsCategory($urlPart); if ($NewsCategory === null) { throw new PageNotFoundException('Kategorie nicht gefunden'); } $this->forward('~\view\categorydetail.html', ['newsCategory' => $NewsCategory, 'mc' => $this->mc]); } public function newsDetail(string $newsCategoryUrlPart, string $newsItemUrlPart, int $id) { $newsItem = $this->newsDao->getNewsItemById($id); if ($newsItem === null) { throw new PageNotFoundException('News nicht gefunden'); } $newsCategory = $this->newsDao->getNewsCategory($newsCategoryUrlPart); if ($newsCategory === null || $newsCategory != $newsItem->getCategory()) { throw new PageNotFoundException('News oder News Kategorie nicht gefunden'); } if ($newsItem->getUrlPart() != $newsItemUrlPart) { throw new PageNotFoundException('News-Url nicht gefunden'); } $this->forward('~\view\newsdetail.html', ['newsItem' => $newsItem, 'mc' => $this->mc]); } public function doCreateCategory(int $id = null) { $category = null; $method = 'new'; if ($id !== null) { $category = $this->newsDao->getNewsCategoryById($id); if ($category instanceof NewsCategory) { $method = 'edit'; } } $categoryForm = new CategoryForm($category); $this->beginTransaction(); if ($this->dispatch($categoryForm, 'save')) { $this->commit(); $this->mc->addInfo('Kategorie erfolgreich erstellt!'); $this->redirectToController(); return; } if ($this->dispatch($categoryForm, 'delete')) { $this->commit(); $this->mc->addInfo('Kategorie erfolgreich gelöscht!'); $this->redirectToController(); return; } $this->commit(); $this->forward('~\view\createcategory.html', array('categoryForm'=> $categoryForm, 'mc' => $this->mc, 'method' => $method)); } public function doDeleteCategory(int $id) { $category = $this->newsDao->getNewsCategoryById($id); if ($category === null) { throw new PageNotFoundException('invalid category id: ' . $id); } $this->beginTransaction(); $this->newsDao->deleteCategory($category); $this->commit(); $this->mc->addInfo('Kategorie, inkl. zugeordneter News erfolgreich gelöscht!'); $this->redirectToController(); } public function doCreateNews(string $urlPart, int $newsId = null) { $category = $this->newsDao->getNewsCategory($urlPart); $method = 'new'; $news = null; if ($category === null) { throw new PageNotFoundException('invalid category name: ' . $urlPart); } if ($newsId !== null){ $news = $this->newsDao->getNewsItemById($newsId); if ($news instanceof NewsItem) { $method = 'edit'; } } $this->beginTransaction(); $newsForm = new NewsForm($category, $this->newsDao->getTags(), $news); if ($this->dispatch($newsForm, 'save')) { $this->commit(); $this->mc->addInfo('NewsItem erfolgreich erstellt!'); $this->redirectToController(array($urlPart)); return; } if ($this->dispatch($newsForm, 'delete')) { $this->commit(); $this->mc->addInfo('NewsItem erfolgreich gelöscht!'); $this->redirectToController(array($urlPart)); return; } $this->commit(); $this->forward('~\view\createnews.html', array('newsForm'=> $newsForm,'urlPart'=> $urlPart, 'mc' => $this->mc, 'method' => $method)); } public function doDeleteNews(int $newsId) { $news = $this->newsDao->getNewsItemById($newsId); if (empty($news)) { throw new PageNotFoundException('invalid news id: ' . $newsId); } $this->beginTransaction(); $this->newsDao->deleteNews($news); $this->commit(); $this->mc->addInfo('NewsItem erfolgreich gelöscht!'); $this->redirectToController(); } public function doCreateTag(int $tagId = null) { $tag = null; $method = 'new'; if ($tagId !== null) { $tag = $this->newsDao->getNewsTagById($tagId); if ($tag instanceof NewsTag) { $method = 'edit'; } } $this->beginTransaction(); $tagForm = new TagForm($tag); if ($this->dispatch($tagForm, 'save')) { $this->commit(); $this->mc->addInfo('Tag erfolgreich erstellt!'); $this->redirectToController(); return; } if ($this->dispatch($tagForm, 'delete')) { $this->commit(); $this->mc->addInfo('Tag erfolgreich gelöscht!'); $this->redirectToController(); return; } $this->commit(); $this->forward('~\view\createtag.html', array('tagForm'=> $tagForm, 'mc' => $this->mc, 'method' => $method)); } public function doDeleteTag(int $tagId) { $tag = $this->newsDao->getNewsTagById($tagId); if (empty($tag)) { throw new PageNotFoundException('invalid tag id: ' . $tagId); } $this->beginTransaction(); $this->newsDao->deleteTag($tag); $this->commit(); $this->mc->addInfo('Tag erfolgreich gelöscht!'); $this->redirectToController(); } public function doTagList(string $tagName = null) { $newsTags = $this->newsDao->getTags($tagName); $this->forward('~\view\taglist.html', array('newsTags'=> $newsTags, 'mc' => $this->mc)); } }