ew_bloggy/Classes/Domain/Model/Author.php
2025-01-21 20:22:57 +01:00

176 lines
3.5 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 TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class Author extends AbstractEntity
{
protected string $name = '';
protected string $title = '';
protected ?FileReference $image = null;
protected string $email = '';
protected string $website = '';
protected string $profile = '';
protected string $bio = '';
protected int $detailsPage = 0;
/**
* @var ObjectStorage<Post>
*/
#[Extbase\ORM\Lazy]
protected ObjectStorage $posts;
public function __construct()
{
$this->initializeObject();
}
public function initializeObject(): void
{
$this->posts = new ObjectStorage();
}
/**
* @return ObjectStorage<Post>
*/
public function getPosts(): ObjectStorage
{
return $this->posts;
}
/**
* @param ObjectStorage<Post> $posts
*/
public function setPosts(ObjectStorage $posts): void
{
$this->posts = $posts;
}
public function addPost(Post $post): void
{
$this->posts->attach($post);
}
public function removePost(Post $post): void
{
$this->posts->detach($post);
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getImage(): ?FileReference
{
return $this->image;
}
public function setImage(FileReference $image): void
{
$this->image = $image;
}
public function getWebsite(): string
{
return $this->website;
}
public function setWebsite(string $website): void
{
$this->website = $website;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getProfile(): string
{
return $this->profile;
}
public function setProfile(string $profile): void
{
$this->profile = $profile;
}
public function getBio(): string
{
return $this->bio;
}
public function setBio(string $bio): void
{
$this->bio = $bio;
}
public function getDetailsPage(): int
{
return $this->detailsPage;
}
public function setDetailsPage(int $page): void
{
$this->detailsPage = $page;
}
public function getAllTags(): array
{
$uniqueTags = [];
foreach ($this->getPosts() as $post) {
foreach ($post->getTags() as $tag) {
if (!array_key_exists((int) $tag->getUid(), $uniqueTags)) {
$uniqueTags[(int) $tag->getUid()] = $tag;
}
}
}
return $uniqueTags;
}
}