325 lines
7.1 KiB
PHP
325 lines
7.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* This file is developed by evoWeb.
|
|
*
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, either version 2
|
|
* of the License, or any later version.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Evoweb\EwBloggy\Domain\Model;
|
|
|
|
use Evoweb\EwBloggy\Constants;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
|
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
|
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
|
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
|
use TYPO3\CMS\Frontend\Typolink\LinkFactory;
|
|
|
|
class Post extends AbstractEntity
|
|
{
|
|
protected bool $hidden = false;
|
|
|
|
protected int $doktype = Constants::DOKTYPE_BLOG_POST;
|
|
|
|
protected string $title = '';
|
|
|
|
protected string $subtitle = '';
|
|
|
|
protected string $abstract = '';
|
|
|
|
protected string $description = '';
|
|
|
|
protected bool $commentsActive = true;
|
|
|
|
protected int $archiveDate = 0;
|
|
|
|
protected int $publishDate = 0;
|
|
|
|
protected \DateTime $crdate;
|
|
|
|
protected ?FileReference $featuredImage = null;
|
|
|
|
/**
|
|
* @var ObjectStorage<Category>
|
|
*/
|
|
#[Extbase\ORM\Lazy]
|
|
protected ObjectStorage $categories;
|
|
|
|
/**
|
|
* @var ObjectStorage<Tag>
|
|
*/
|
|
#[Extbase\ORM\Lazy]
|
|
protected ObjectStorage $tags;
|
|
|
|
/**
|
|
* @var ObjectStorage<Author>
|
|
*/
|
|
#[Extbase\ORM\Lazy]
|
|
protected ObjectStorage $authors;
|
|
|
|
/**
|
|
* @var ObjectStorage<FileReference>
|
|
*/
|
|
#[Extbase\ORM\Lazy]
|
|
protected ObjectStorage $media;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->initializeObject();
|
|
}
|
|
|
|
public function initializeObject(): void
|
|
{
|
|
$this->categories = new ObjectStorage();
|
|
$this->tags = new ObjectStorage();
|
|
$this->authors = new ObjectStorage();
|
|
$this->media = new ObjectStorage();
|
|
}
|
|
|
|
public function addCategory(Category $category): void
|
|
{
|
|
$this->categories->attach($category);
|
|
}
|
|
|
|
public function removeCategory(Category $category): void
|
|
{
|
|
$this->categories->detach($category);
|
|
}
|
|
|
|
/**
|
|
* @return ObjectStorage<Category>
|
|
*/
|
|
public function getCategories(): ObjectStorage
|
|
{
|
|
return $this->categories;
|
|
}
|
|
|
|
/**
|
|
* @param ObjectStorage<Category> $categories
|
|
*/
|
|
public function setCategories(ObjectStorage $categories): void
|
|
{
|
|
$this->categories = $categories;
|
|
}
|
|
|
|
public function addTag(Tag $tag): void
|
|
{
|
|
$this->tags->attach($tag);
|
|
}
|
|
|
|
public function removeTag(Tag $tag): void
|
|
{
|
|
$this->tags->detach($tag);
|
|
}
|
|
|
|
/**
|
|
* @return ObjectStorage<Tag>
|
|
*/
|
|
public function getTags(): ObjectStorage
|
|
{
|
|
return $this->tags;
|
|
}
|
|
|
|
/**
|
|
* @param ObjectStorage<Tag> $tags
|
|
*/
|
|
public function setTags(ObjectStorage $tags): void
|
|
{
|
|
$this->tags = $tags;
|
|
}
|
|
|
|
public function addAuthor(Author $author): void
|
|
{
|
|
$this->authors->attach($author);
|
|
}
|
|
|
|
public function removeAuthor(Author $author): void
|
|
{
|
|
$this->authors->detach($author);
|
|
}
|
|
|
|
/**
|
|
* @return ObjectStorage<Author>
|
|
*/
|
|
public function getAuthors(): ObjectStorage
|
|
{
|
|
return $this->authors;
|
|
}
|
|
|
|
/**
|
|
* @param ObjectStorage<Author> $authors
|
|
*/
|
|
public function setAuthors(ObjectStorage $authors): void
|
|
{
|
|
$this->authors = $authors;
|
|
}
|
|
|
|
/**
|
|
* @return ObjectStorage<FileReference>
|
|
*/
|
|
public function getMedia(): ObjectStorage
|
|
{
|
|
return $this->media;
|
|
}
|
|
|
|
/**
|
|
* @param ObjectStorage<FileReference> $media
|
|
*/
|
|
public function setMedia(ObjectStorage $media): void
|
|
{
|
|
$this->media = $media;
|
|
}
|
|
|
|
public function getFeaturedImage(): ?FileReference
|
|
{
|
|
return $this->featuredImage;
|
|
}
|
|
|
|
public function setFeaturedImage(?FileReference $featuredImage): void
|
|
{
|
|
$this->featuredImage = $featuredImage;
|
|
}
|
|
|
|
public function getHidden(): bool
|
|
{
|
|
return $this->hidden;
|
|
}
|
|
|
|
public function isHidden(): bool
|
|
{
|
|
return $this->getHidden();
|
|
}
|
|
|
|
public function getDoktype(): int
|
|
{
|
|
return $this->doktype;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(string $title): void
|
|
{
|
|
$this->title = $title;
|
|
}
|
|
|
|
public function getSubtitle(): string
|
|
{
|
|
return $this->subtitle;
|
|
}
|
|
|
|
public function setSubtitle(string $subtitle): void
|
|
{
|
|
$this->subtitle = $subtitle;
|
|
}
|
|
|
|
public function getAbstract(): string
|
|
{
|
|
return $this->abstract;
|
|
}
|
|
|
|
public function setAbstract(string $abstract): void
|
|
{
|
|
$this->abstract = $abstract;
|
|
}
|
|
|
|
public function getDescription(): string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(string $description): void
|
|
{
|
|
$this->description = $description;
|
|
}
|
|
|
|
public function getCrdate(): \DateTime
|
|
{
|
|
return $this->crdate;
|
|
}
|
|
|
|
public function setCrdate(\DateTime $crdate): void
|
|
{
|
|
$this->crdate = $crdate;
|
|
}
|
|
|
|
public function getCommentsActive(): bool
|
|
{
|
|
return $this->commentsActive;
|
|
}
|
|
|
|
public function setCommentsActive(bool $commentsActive): void
|
|
{
|
|
$this->commentsActive = $commentsActive;
|
|
}
|
|
|
|
public function getArchiveDate(): int
|
|
{
|
|
return $this->archiveDate;
|
|
}
|
|
|
|
public function setArchiveDate(int $archiveDate): void
|
|
{
|
|
$this->archiveDate = $archiveDate;
|
|
}
|
|
|
|
public function getPublishDate(): int
|
|
{
|
|
return $this->publishDate;
|
|
}
|
|
|
|
public function setPublishDate(int $publishDate): void
|
|
{
|
|
$this->publishDate = $publishDate;
|
|
}
|
|
|
|
public function getUri(): string
|
|
{
|
|
if (class_exists(LinkFactory::class)) {
|
|
return (string) GeneralUtility::makeInstance(LinkFactory::class)->create(
|
|
'',
|
|
[
|
|
'parameter' => (string) $this->getUid(),
|
|
'forceAbsoluteUrl' => true
|
|
],
|
|
GeneralUtility::makeInstance(ContentObjectRenderer::class)
|
|
)->getUrl();
|
|
}
|
|
|
|
return GeneralUtility::makeInstance(UriBuilder::class)
|
|
->setCreateAbsoluteUri(true)
|
|
->setTargetPageUid((int) $this->getUid())
|
|
->build();
|
|
}
|
|
|
|
public function getAsArray(): array
|
|
{
|
|
return $this->__toArray();
|
|
}
|
|
|
|
public function __toArray(): array
|
|
{
|
|
return [
|
|
'uid' => $this->getUid(),
|
|
'hidden' => $this->getHidden(),
|
|
'doktype' => $this->getDoktype(),
|
|
'title' => $this->getTitle(),
|
|
'subtitle' => $this->getSubtitle(),
|
|
'abstract' => $this->getAbstract(),
|
|
'description' => $this->getDescription()
|
|
];
|
|
}
|
|
}
|