title = $news->getTitle(); $this->content = $news->getContent(); $this->id = $news->getId(); $this->tagIds = array_map(fn(NewsTag $t) => $t->getId(), $news->getTags()->getArrayCopy()); $this->news = $news; } public function getTitle(): ?string { return $this->title ?? null; } /** * @param string $title */ public function setTitle(string $title) { $this->title = $title; } public function getImageFile(): ?File { return $this->imageFile; } public function setImageFile(?File $imageFile) { $this->imageFile = $imageFile; } /** * @return array */ public function getTagIds(): array { return $this->tagIds; } /** * @param array $tagIds */ public function setTagIds(array $tagIds): void { $this->tagIds = $tagIds; } /** * @return string */ public function getContent(): ?string { return $this->content ?? null; } /** * @param string $content */ public function setContent(string $content) { $this->content = $content; } public function getTagOptions(): array { return $this->tags; } private function _mapping(MappingResult $mr) { $mr->setLabel('title', 'Titel'); $mr->setLabel('content', 'Beschreibung'); $mr->setLabel('imageFile', 'Bild'); $mr->setLabel('tagIds', 'zugewiesene Tags'); } private function _validation(BindingDefinition $bd) { $bd->val(array('content', 'title'), new ValNotEmpty()); $bd->val('imageFile', new ValImageFile(true)); } public function save(NewsDao $newsDao) { $selectedTagObjects = new \ArrayObject(); foreach ($this->tags as $tagObject) { if (in_array($tagObject->getId(),$this->tagIds )) { $selectedTagObjects[] = $tagObject; } } $news = $this->news ?? new NewsItem(); $news->setTitle($this->title); $news->setLead(substr_replace($this->content, "...", 50)); $news->setContent($this->content); $news->setImageFile($this->imageFile); $news->setUrlPart(strtolower(IoUtils::stripSpecialChars($this->title))); $news->setCategory($this->category); $news->setTags($selectedTagObjects); $newsDao->saveNews($news); } public function delete(NewsDao $newsDao) { if (!$this->news) { throw new PageNotFoundException('no id set'); } $news = $this->news; $newsDao->deleteNews($news); } }