title = ''; $this->content = ''; if ($category) { $this->title = $category->getTitle(); $this->id = $category->getId(); $this->content = $category->getContent(); $this->category = $category; } } public function getTitle() { return $this->title; } public function setTitle(string $title) { $this->title = $title; } public function getImageFile() { return $this->imageFile; } public function setImageFile(File $imageFile = null) { $this->imageFile = $imageFile; } public function getContent() { return $this->content; } public function setContent(string $content) { $this->content = $content; } private function _mapping(MappingResult $mr) { $mr->setLabel('title', 'Titel'); $mr->setLabel('content', 'Beschreibung'); $mr->setLabel('imageFile', 'Bild'); } private function _validation(BindingDefinition $bd) { $bd->val(array('content', 'title'), new ValNotEmpty()); $bd->val('imageFile', new ValImageFile(true)); } public function save(NewsDao $newsDao) { $category = $this->category ?? new NewsCategory(); $category->setTitle($this->title); $category->setLead(substr_replace($this->content, "...", 50)); $category->setContent($this->content); $category->setImageFile($this->imageFile); $category->setUrlPart(strtolower(IoUtils::stripSpecialChars($this->title))); $newsDao->saveCategory($category); } public function delete(NewsDao $newsDao) { if (!$this->category) { throw new PageNotFoundException('no id set'); } $category = $this->category; $newsDao->deleteCategory($category); } }