Skip to content
Snippets Groups Projects
News.php 7.35 KiB
Newer Older
Stefan Galinski's avatar
Stefan Galinski committed
<?php

namespace SGalinski\SgNews\Domain\Model;

/***************************************************************
 *  Copyright notice
 *
 *  (c) sgalinski Internet Services (https://www.sgalinski.de)
Stefan Galinski's avatar
Stefan Galinski committed
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

/**
 * News
 */
class News extends CategoryAndNews {
	public const DOK_TYPE_NEWS = 116;

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @var string
	 */
	protected $description = '';

	/**
	 * @var boolean
	 */
	protected $highlighted = FALSE;

	/**
	 * @var boolean
	 */
	protected $neverHighlighted = FALSE;

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @var \DateTime
	 */
	protected $lastUpdated;

	/**
	 * @var \DateTime
	 */
	protected $dateEnd;

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @var \DateTime
	 */
	protected $creationDate;

	/**
	 * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
Stefan Galinski's avatar
Stefan Galinski committed
	 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SGalinski\SgNews\Domain\Model\News>
	 */
	protected $relatedNews;

	/**
	 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SGalinski\SgNews\Domain\Model\Tag>
	 */
	protected $tags;

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
	 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SGalinski\SgNews\Domain\Model\Author>
Stefan Galinski's avatar
Stefan Galinski committed
	 */
Stefan Galinski's avatar
Stefan Galinski committed

	/**
	 * @var int
	 */
	protected $likes;

	/**
	 * @var string
	 */
	protected $location;

	/**
	 * @var int
	 */
	protected $contentFromAnotherPage = 0;

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * Constructor
	 */
	public function __construct() {
		parent::__construct();
		$this->relatedNews = new ObjectStorage();
		$this->tags = new ObjectStorage();
		$this->newsAuthor = new ObjectStorage();
Stefan Galinski's avatar
Stefan Galinski committed
	}

	/**
	 * @param string $description
	 * @return void
	 */
	public function setDescription($description) {
		$this->description = $description;
	}

	/**
	 * @return string
	 */
	public function getDescription() {
		return $this->description;
	}

	/**
	 * @param \DateTime $lastUpdated
	 * @return void
	 */
	public function setLastUpdated(\DateTime $lastUpdated) {
		$this->lastUpdated = $lastUpdated;
	}

	/**
	 * @return \DateTime
	 */
	public function getLastUpdated() {
		return $this->lastUpdated;
	}

	/**
	 * @return \DateTime
	 */
	public function getDateEnd() {
		return $this->dateEnd;
	}

	/**
	 * @param \DateTime $dateEnd
	 */
	public function setDateEnd(\DateTime $dateEnd) {
		$this->dateEnd = $dateEnd;
	}

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @param \DateTime $creationDate
	 * @return void
	 */
	public function setCreationDate(\DateTime $creationDate) {
		$this->creationDate = $creationDate;
	}

	/**
	 * @return \DateTime
	 */
	public function getCreationDate() {
		return $this->creationDate;
	}

	/**
	 * @param ObjectStorage $relatedNews
	 * @return void
	 */
	public function setRelatedNews(ObjectStorage $relatedNews) {
		$this->relatedNews = $relatedNews;
	}

	/**
	 * @return ObjectStorage
	 */
	public function getRelatedNews() {
		if ($this->relatedNews instanceof LazyLoadingProxy) {
			$this->relatedNews->_loadRealInstance();
		}

		return $this->relatedNews;
	}

	/**
	 * @param News $relatedNews
	 * @return void
	 */
	public function addRelatedNews(News $relatedNews) {
		if ($this->relatedNews instanceof LazyLoadingProxy) {
			$this->relatedNews->_loadRealInstance();
		}

		$this->relatedNews->attach($relatedNews);
	}

	/**
	 * @param News $relatedNews
	 * @return void
	 */
	public function removeRelatedNews(News $relatedNews) {
		if ($this->relatedNews instanceof LazyLoadingProxy) {
			$this->relatedNews->_loadRealInstance();
		}

		$this->relatedNews->detach($relatedNews);
	}

	/**
	 * @param ObjectStorage $tags
	 * @return void
	 */
	public function setTags(ObjectStorage $tags) {
		$this->tags = $tags;
	}

	/**
	 * @return ObjectStorage
	 */
	public function getTags() {
		return $this->tags;
	}

	/**
	 * @param Tag $tag
	 * @return void
	 */
	public function addTag(Tag $tag) {
		$this->tags->attach($tag);
	}

	/**
	 * @param Tag $tag
	 * @return void
	 */
	public function removeTags(Tag $tag) {
		$this->tags->detach($tag);
	}

Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @param boolean $highlighted
	 */
	public function setHighlighted($highlighted) {
		$this->highlighted = (bool) $highlighted;
Stefan Galinski's avatar
Stefan Galinski committed
	}

	/**
	 * @return boolean
	 */
	public function getHighlighted() {
		return $this->highlighted;
	}

	/**
	 * @return bool
	 */
	public function getNeverHighlighted() {
		return $this->neverHighlighted;
	}

	/**
	 * @param bool $neverHighlighted
	 * @return void
	 */
	public function setNeverHighlighted($neverHighlighted) {
		$this->neverHighlighted = (bool) $neverHighlighted;
Stefan Galinski's avatar
Stefan Galinski committed
	/**
Stefan Galinski's avatar
Stefan Galinski committed
	 */
	public function getNewsAuthor(): ?ObjectStorage {
		if ($this->newsAuthor instanceof LazyLoadingProxy) {
			$this->newsAuthor->_loadRealInstance();
		}

		return $this->newsAuthor;
Stefan Galinski's avatar
Stefan Galinski committed
	}

	/**
	 * @param ObjectStorage $objectStorage
	 */
	public function setNewsAuthor(ObjectStorage $objectStorage): void {
		$this->newsAuthor = $objectStorage;
	}

	/**
	 * @param Author $author
	 */
	public function addNewsAuthor(Author $author): void {
		if ($this->newsAuthor instanceof LazyLoadingProxy) {
			$this->newsAuthor->_loadRealInstance();
		}

		$this->newsAuthor->attach($author);
	}

	/**
	 * @param Author $author
Stefan Galinski's avatar
Stefan Galinski committed
	 */
	public function removeNewsAuthor(Author $author): void {
		if ($this->newsAuthor instanceof LazyLoadingProxy) {
			$this->newsAuthor->_loadRealInstance();
		}

		$this->newsAuthor->detach($author);
	}

	/**
	 * @return Author
	 */
	public function getFirstNewsAuthor(): ?Author {
		$newsAuthors = $this->getNewsAuthor();
		if (!$newsAuthors) {
			return NULL;
		}

		// Needs to be like that, because the LazyObjectStorage isn't initialized sometimes, if we use "->current" here.
		$firstAuthor = NULL;
		/** @noinspection LoopWhichDoesNotLoopInspection */
		foreach ($newsAuthors as $newsAuthor) {
			/** @var Author $newsAuthor */
			$firstAuthor = $newsAuthor;
			break;
		}

		return $firstAuthor;
	}

	/**
	 * @return string
	 */
	public function getAuthor(): string {
		$newsAuthor = $this->getFirstNewsAuthor();
		if (!$newsAuthor) {
			return '';
		}

		return $newsAuthor->getName();
Stefan Galinski's avatar
Stefan Galinski committed
	}

	/**
	 * @return int
	 */
	public function getLikes() {
		return $this->likes;
	}

	/**
	 * @param int $likes
	 */
	public function setLikes($likes) {
		$this->likes = $likes;
	}

	/**
	 * @return string
	 */
	public function getLocation() {
		return $this->location;
	}

	/**
	 * @param string $location
	 */
	public function setLocation($location) {
		$this->location = $location;
	}

	/**
	 * @return int
	 */
	public function getContentFromAnotherPage(): int {
		return $this->contentFromAnotherPage;
	}

	/**
	 * @param int $contentFromAnotherPage
	 */
	public function setContentFromAnotherPage(int $contentFromAnotherPage): void {
		$this->contentFromAnotherPage = $contentFromAnotherPage;
	}
Stefan Galinski's avatar
Stefan Galinski committed
}