Initial commit - Typo3 11.5.41
This commit is contained in:
323
typo3conf/ext/pw_teaser/Classes/Domain/Model/Content.php
Normal file
323
typo3conf/ext/pw_teaser/Classes/Domain/Model/Content.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
namespace PwTeaserTeam\PwTeaser\Domain\Model;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
|
||||
* Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
|
||||
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
|
||||
*
|
||||
* 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 2 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\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
|
||||
/**
|
||||
* Content model
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
|
||||
*/
|
||||
class Content extends AbstractEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* ctype
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ctype;
|
||||
|
||||
/**
|
||||
* colPos
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $colPos;
|
||||
|
||||
/**
|
||||
* header
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $header;
|
||||
|
||||
/**
|
||||
* bodytext
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bodytext;
|
||||
|
||||
/**
|
||||
* It may contain multiple images, but TYPO3 called this field just "image"
|
||||
*
|
||||
* @var ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*
|
||||
* @var ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Complete row (from database) of this content element
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $contentRow;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->image = new ObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for images
|
||||
*
|
||||
* @param ObjectStorage $image
|
||||
* @return void
|
||||
*/
|
||||
public function setImage(ObjectStorage $image)
|
||||
{
|
||||
$this->image = $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for images
|
||||
*
|
||||
* @return ObjectStorage images
|
||||
*/
|
||||
public function getImage()
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image
|
||||
*
|
||||
* @param FileReference $image
|
||||
* @return void
|
||||
*/
|
||||
public function addImage(FileReference $image)
|
||||
{
|
||||
$this->image->attach($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove image
|
||||
*
|
||||
* @param FileReference $image
|
||||
* @return void
|
||||
*/
|
||||
public function removeImage(FileReference $image)
|
||||
{
|
||||
$this->image->detach($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns image files as array (with all attributes)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImageFiles()
|
||||
{
|
||||
$imageFiles = [];
|
||||
/** @var FileReference $image */
|
||||
foreach ($this->getImage() as $image) {
|
||||
$imageFiles[] = $image->getOriginalResource()->toArray();
|
||||
}
|
||||
return $imageFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for bodytext
|
||||
*
|
||||
* @param string $bodytext bodytext
|
||||
* @return void
|
||||
*/
|
||||
public function setBodytext($bodytext)
|
||||
{
|
||||
$this->bodytext = $bodytext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for bodytext
|
||||
*
|
||||
* @return string bodytext
|
||||
*/
|
||||
public function getBodytext()
|
||||
{
|
||||
return $this->bodytext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for ctype
|
||||
*
|
||||
* @param string $ctype ctype
|
||||
* @return void
|
||||
*/
|
||||
public function setCtype($ctype)
|
||||
{
|
||||
$this->ctype = $ctype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for ctype
|
||||
*
|
||||
* @return string ctype
|
||||
*/
|
||||
public function getCtype()
|
||||
{
|
||||
return $this->ctype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for colPos
|
||||
*
|
||||
* @param integer $colPos colPos
|
||||
* @return void
|
||||
*/
|
||||
public function setColPos($colPos)
|
||||
{
|
||||
$this->colPos = $colPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for colPos
|
||||
*
|
||||
* @return integer colPos
|
||||
*/
|
||||
public function getColPos()
|
||||
{
|
||||
return $this->colPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for header
|
||||
*
|
||||
* @param string $header header
|
||||
* @return void
|
||||
*/
|
||||
public function setHeader($header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for header
|
||||
*
|
||||
* @return string header
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for categories
|
||||
*
|
||||
* @return ObjectStorage
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for categories
|
||||
*
|
||||
* @param ObjectStorage $categories
|
||||
* @return void
|
||||
*/
|
||||
public function setCategories($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category
|
||||
*
|
||||
* @param Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function addCategory(Category $category)
|
||||
{
|
||||
$this->categories->attach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove category
|
||||
*
|
||||
* @param Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function removeCategory(Category $category)
|
||||
{
|
||||
$this->categories->detach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for attribute in _contentRow
|
||||
*
|
||||
* @param string $name Name of unknown method
|
||||
* @param array arguments Arguments of call
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (substr(strtolower($name), 0, 3) == 'get' && strlen($name) > 3) {
|
||||
$attributeName = lcfirst(substr($name, 3));
|
||||
|
||||
if (empty($this->contentRow)) {
|
||||
/** @var PageRepository $pageSelect */
|
||||
$pageSelect = $GLOBALS['TSFE']->sys_page;
|
||||
$contentRow = $pageSelect->getRawRecord('tt_content', $this->getUid());
|
||||
foreach ($contentRow as $key => $value) {
|
||||
$this->contentRow[GeneralUtility::underscoredToLowerCamelCase($key)] = $value;
|
||||
}
|
||||
}
|
||||
if (isset($this->contentRow[$attributeName])) {
|
||||
return $this->contentRow[$attributeName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw content row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getContentRow()
|
||||
{
|
||||
return $this->contentRow;
|
||||
}
|
||||
}
|
||||
922
typo3conf/ext/pw_teaser/Classes/Domain/Model/Page.php
Normal file
922
typo3conf/ext/pw_teaser/Classes/Domain/Model/Page.php
Normal file
@@ -0,0 +1,922 @@
|
||||
<?php
|
||||
namespace PwTeaserTeam\PwTeaser\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Context\Context;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\RootlineUtility;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
|
||||
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
|
||||
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
|
||||
*
|
||||
* 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 2 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!
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Page model
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
|
||||
*/
|
||||
class Page extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
|
||||
{
|
||||
/** Translation constant: Show page always */
|
||||
const L18N_SHOW_ALWAYS = 0;
|
||||
/** Translation constant: Hide page on default language */
|
||||
const L18N_HIDE_DEFAULT_LANGUAGE = 1;
|
||||
/** Translation constant: Hide page on foreign language if no translation exists */
|
||||
const L18N_HIDE_IF_NO_TRANSLATION_EXISTS = 2;
|
||||
/** Translation constant: Hide page always, but show on foreign langauge if translation exists */
|
||||
const L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS = 3;
|
||||
|
||||
/**
|
||||
* doktype
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $doktype;
|
||||
|
||||
/**
|
||||
* isCurrentPage
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isCurrentPage = false;
|
||||
|
||||
/**
|
||||
* title
|
||||
*
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* subtitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subtitle;
|
||||
|
||||
/**
|
||||
* navTitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $navTitle;
|
||||
|
||||
/**
|
||||
* meta keywords
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keywords;
|
||||
|
||||
/**
|
||||
* meta description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* abstract
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $abstract;
|
||||
|
||||
/**
|
||||
* alias
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* media
|
||||
*
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
|
||||
*/
|
||||
protected $media;
|
||||
|
||||
/**
|
||||
* sorting
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $sorting;
|
||||
|
||||
/**
|
||||
* creation date (crdate)
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $creationDate;
|
||||
|
||||
/**
|
||||
* timestamp (tstamp)
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $tstamp;
|
||||
|
||||
/**
|
||||
* lastUpdated
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $lastUpdated;
|
||||
|
||||
/**
|
||||
* start time
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $starttime;
|
||||
|
||||
/**
|
||||
* end time
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $endtime;
|
||||
|
||||
/**
|
||||
* new until
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $newUntil;
|
||||
|
||||
/**
|
||||
* author
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $author;
|
||||
|
||||
/**
|
||||
* author email
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $authorEmail;
|
||||
|
||||
/**
|
||||
* contents
|
||||
*
|
||||
* @var array<\PwTeaserTeam\PwTeaser\Domain\Model\Content>
|
||||
*/
|
||||
protected $contents;
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $l18nConfiguration;
|
||||
|
||||
/**
|
||||
* Child pages
|
||||
*
|
||||
* @var array<Page>
|
||||
*/
|
||||
protected $childPages = [];
|
||||
|
||||
/**
|
||||
* Custom Attributes
|
||||
* which can be set by hooks
|
||||
*
|
||||
* @var array<mixed>
|
||||
*/
|
||||
protected $customAttributes = [];
|
||||
|
||||
/**
|
||||
* Complete row (from database) of this page
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pageRow = null;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Core\Resource\FileRepository
|
||||
* @TYPO3\CMS\Extbase\Annotation\Inject
|
||||
*/
|
||||
protected $fileRepository;
|
||||
|
||||
/**
|
||||
* Sets a custom attribute
|
||||
*
|
||||
* @param string $key The name of the attribute
|
||||
* @param mixed $value Attribute's value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCustomAttribute($key, $value)
|
||||
{
|
||||
$this->customAttributes[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a custom attribute
|
||||
*
|
||||
* @param string $key Name of attribute
|
||||
* @return mixed The value of a custom attribute
|
||||
*/
|
||||
public function getCustomAttribute($key)
|
||||
{
|
||||
if (!empty($key) && $this->hasCustomAttribute($key)) {
|
||||
return $this->customAttributes[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given custom attribute has been set
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCustomAttribute($key)
|
||||
{
|
||||
return isset($this->customAttributes[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getGet(): array
|
||||
{
|
||||
if (empty($this->pageRow)) {
|
||||
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageSelect */
|
||||
$pageSelect = $GLOBALS['TSFE']->sys_page;
|
||||
$pageRow = $pageSelect->getPage($this->getUid());
|
||||
foreach ($pageRow as $key => $value) {
|
||||
$this->pageRow[GeneralUtility::underscoredToLowerCamelCase($key)] = $value;
|
||||
}
|
||||
}
|
||||
return array_merge($this->customAttributes, $this->pageRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for attribute in _customAttributes and _pageRow
|
||||
*
|
||||
* @param string $name Name of unknown method
|
||||
* @param array arguments Arguments of call
|
||||
* @return mixed
|
||||
* @deprecated Use getGet() instead (in fluid template: {page.get.attributeName})
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (substr(strtolower($name), 0, 3) === 'get' && strlen($name) > 3) {
|
||||
$attributeName = lcfirst(substr($name, 3));
|
||||
return $this->getGet()[$attributeName];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
|
||||
$this->media = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for contents
|
||||
*
|
||||
* @param array <\PwTeaserTeam\PwTeaser\Domain\Model\Content> $contents array of contents
|
||||
* @return void
|
||||
*/
|
||||
public function setContents($contents)
|
||||
{
|
||||
$this->contents = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for contents
|
||||
*
|
||||
* @return array<\PwTeaserTeam\PwTeaser\Domain\Model\Content> contents
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
return $this->contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for isCurrentPage
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsCurrentPage()
|
||||
{
|
||||
return $this->isCurrentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for isCurrentPage
|
||||
*
|
||||
* @param boolean $isCurrentPage
|
||||
* @return void
|
||||
*/
|
||||
public function setIsCurrentPage($isCurrentPage)
|
||||
{
|
||||
$this->isCurrentPage = $isCurrentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for authorEmail
|
||||
*
|
||||
* @param string $authorEmail authorEmail
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthorEmail($authorEmail)
|
||||
{
|
||||
$this->authorEmail = $authorEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for authorEmail
|
||||
*
|
||||
* @return string authorEmail
|
||||
*/
|
||||
public function getAuthorEmail()
|
||||
{
|
||||
return $this->authorEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for keywords
|
||||
*
|
||||
* @param string $keywords keywords
|
||||
* @return void
|
||||
*/
|
||||
public function setKeywords($keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for keywords
|
||||
*
|
||||
* @return array array of keywords
|
||||
*/
|
||||
public function getKeywords()
|
||||
{
|
||||
return (GeneralUtility::trimExplode(',', $this->keywords, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for keywords. Returns a string
|
||||
*
|
||||
* @return string keywords as string
|
||||
*/
|
||||
public function getKeywordsAsString()
|
||||
{
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for description
|
||||
*
|
||||
* @param string $description description
|
||||
* @return void
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
*
|
||||
* @return string description
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for alias
|
||||
*
|
||||
* @param string $alias alias
|
||||
* @return void
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for alias
|
||||
*
|
||||
* @return string alias
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for navTitle
|
||||
*
|
||||
* @param string $navTitle navTitle
|
||||
* @return void
|
||||
*/
|
||||
public function setNavTitle($navTitle)
|
||||
{
|
||||
$this->navTitle = $navTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for navTitle
|
||||
*
|
||||
* @return string navTitle
|
||||
*/
|
||||
public function getNavTitle()
|
||||
{
|
||||
return $this->navTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for abstract
|
||||
*
|
||||
* @param string $abstract abstract
|
||||
* @return void
|
||||
*/
|
||||
public function setAbstract($abstract)
|
||||
{
|
||||
$this->abstract = $abstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for abstract
|
||||
*
|
||||
* @return string abstract
|
||||
*/
|
||||
public function getAbstract()
|
||||
{
|
||||
return $this->abstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for subtitle
|
||||
*
|
||||
* @param string $subtitle subtitle
|
||||
* @return void
|
||||
*/
|
||||
public function setSubtitle($subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for subtitle
|
||||
*
|
||||
* @return string subtitle
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
return $this->subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for title
|
||||
*
|
||||
* @param string $title title
|
||||
* @return void
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for title
|
||||
*
|
||||
* @return string title
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for media
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $media
|
||||
* @return void
|
||||
*/
|
||||
public function setMedia(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $media)
|
||||
{
|
||||
$this->media = $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for media (returns FileReference objects)
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
|
||||
*/
|
||||
public function getMedia()
|
||||
{
|
||||
return $this->media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add single medium
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $medium
|
||||
* @return void
|
||||
*/
|
||||
public function addMedium(\TYPO3\CMS\Extbase\Domain\Model\FileReference $medium)
|
||||
{
|
||||
$this->media->attach($medium);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes single medium
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $medium
|
||||
* @return void
|
||||
*/
|
||||
public function removeMedium(\TYPO3\CMS\Extbase\Domain\Model\FileReference $medium)
|
||||
{
|
||||
$this->media->detach($medium);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns media files as array (with all attributes)
|
||||
*
|
||||
* @return array
|
||||
* @deprecated Use media attribute instead
|
||||
*/
|
||||
public function getMediaFiles()
|
||||
{
|
||||
GeneralUtility::deprecationLog(
|
||||
'Please don\'t use {page.mediaFiles} anymore in your pw_teaser templates. Use {page.media} instead.'
|
||||
);
|
||||
return $this->getMedia()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for newUntil
|
||||
*
|
||||
* @param integer $newUntil newUntil
|
||||
* @return void
|
||||
*/
|
||||
public function setNewUntil($newUntil)
|
||||
{
|
||||
$this->newUntil = $newUntil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for newUntil
|
||||
*
|
||||
* @return integer newUntil
|
||||
*/
|
||||
public function getNewUntil()
|
||||
{
|
||||
return $this->newUntil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TRUE if the page is marked as new
|
||||
*
|
||||
* @return boolean TRUE if the page is marked as new, otherwise FALSE
|
||||
*/
|
||||
public function getIsNew()
|
||||
{
|
||||
if (!empty($this->newUntil) && $this->newUntil !== 0) {
|
||||
return $this->newUntil < time();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for creationDate (crdate)
|
||||
*
|
||||
* @param integer $creationDate creationDate
|
||||
* @return void
|
||||
*/
|
||||
public function setCreationDate($creationDate)
|
||||
{
|
||||
$this->creationDate = $creationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for creationDate (crdate)
|
||||
*
|
||||
* @return integer creationDate
|
||||
*/
|
||||
public function getCreationDate()
|
||||
{
|
||||
return $this->creationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for tstamp
|
||||
*
|
||||
* @param integer $tstamp tstamp
|
||||
* @return void
|
||||
*/
|
||||
public function setTstamp($tstamp)
|
||||
{
|
||||
$this->tstamp = $tstamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for tstamp
|
||||
*
|
||||
* @return integer tstamp
|
||||
*/
|
||||
public function getTstamp()
|
||||
{
|
||||
return $this->tstamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for lastUpdated
|
||||
*
|
||||
* @param integer $lastUpdated lastUpdated
|
||||
* @return void
|
||||
*/
|
||||
public function setLastUpdated($lastUpdated)
|
||||
{
|
||||
$this->lastUpdated = $lastUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for lastUpdated
|
||||
*
|
||||
* @return integer lastUpdated
|
||||
*/
|
||||
public function getLastUpdated()
|
||||
{
|
||||
return $this->lastUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for starttime
|
||||
*
|
||||
* @param integer $starttime
|
||||
* @return void
|
||||
*/
|
||||
public function setStarttime($starttime)
|
||||
{
|
||||
$this->starttime = $starttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for starttime
|
||||
*
|
||||
* @return integer starttime
|
||||
*/
|
||||
public function getStarttime()
|
||||
{
|
||||
return $this->starttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for endtime
|
||||
*
|
||||
* @return integer endtime
|
||||
*/
|
||||
public function getEndtime()
|
||||
{
|
||||
return $this->endtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for endtime
|
||||
*
|
||||
* @param integer $endtime endtime
|
||||
* @return void
|
||||
*/
|
||||
public function setEndtime($endtime)
|
||||
{
|
||||
$this->endtime = $endtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for author
|
||||
*
|
||||
* @return string author
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for author
|
||||
*
|
||||
* @param string $author author
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthor($author)
|
||||
{
|
||||
$this->author = $author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for doktype
|
||||
*
|
||||
* @return integer the doktype
|
||||
*/
|
||||
public function getDoktype()
|
||||
{
|
||||
return $this->doktype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for doktype
|
||||
*
|
||||
* @param integer $doktype the doktype
|
||||
* @return void
|
||||
*/
|
||||
public function setDoktype($doktype)
|
||||
{
|
||||
$this->doktype = $doktype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for l18nConfiguration
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getL18nConfiguration()
|
||||
{
|
||||
return $this->l18nConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for l18nConfiguration
|
||||
*
|
||||
* @param integer $l18nCfg
|
||||
* @return void
|
||||
*/
|
||||
public function setL18nConfiguration($l18nCfg)
|
||||
{
|
||||
$this->l18nConfiguration = $l18nCfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for categories
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for categories
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories
|
||||
* @return void
|
||||
*/
|
||||
public function setCategories($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
|
||||
{
|
||||
$this->categories->attach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove category
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
|
||||
* @return void
|
||||
*/
|
||||
public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
|
||||
{
|
||||
$this->categories->detach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns rootLine of this page
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRootLine()
|
||||
{
|
||||
$context = GeneralUtility::makeInstance(Context::class);
|
||||
/** @var RootlineUtility $rootline */
|
||||
$rootline = GeneralUtility::makeInstance(RootlineUtility::class, $this->getUid(), '', $context);
|
||||
return $rootline->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns amount of parent pages, including this page itself.
|
||||
* The root page (not id=0) got depth 1.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getRootLineDepth()
|
||||
{
|
||||
return count($this->getRootLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string of sortings of all root pages including this page.
|
||||
*
|
||||
* @return string String with orderings of this page and all root pages
|
||||
*/
|
||||
public function getRecursiveRootLineOrdering()
|
||||
{
|
||||
$recursiveOrdering = [];
|
||||
foreach ($this->getRootLine() as $pageRootPart) {
|
||||
array_unshift($recursiveOrdering, str_pad($pageRootPart['sorting'], 11, '0', STR_PAD_LEFT));
|
||||
}
|
||||
return implode('-', $recursiveOrdering);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the complete page row (from database) as array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPageRow()
|
||||
{
|
||||
return $this->pageRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for sorting
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getSorting()
|
||||
{
|
||||
return $this->sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for sorting
|
||||
*
|
||||
* @param integer $sorting
|
||||
* @return void
|
||||
*/
|
||||
public function setSorting($sorting)
|
||||
{
|
||||
$this->sorting = $sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for child pages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChildPages()
|
||||
{
|
||||
return $this->childPages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for child pages
|
||||
*
|
||||
* @param array <Page> $childPages
|
||||
* @return void
|
||||
*/
|
||||
public function setChildPages(array $childPages)
|
||||
{
|
||||
$this->childPages = $childPages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
namespace PwTeaserTeam\PwTeaser\Domain\Repository;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
|
||||
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
|
||||
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
|
||||
*
|
||||
* 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 2 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!
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Repository for Content model
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
|
||||
*/
|
||||
class ContentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
||||
{
|
||||
|
||||
/**
|
||||
* Initializes the repository.
|
||||
*
|
||||
* @return void
|
||||
* @see \TYPO3\CMS\Extbase\Persistence\Repository::initializeObject()
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings */
|
||||
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface');
|
||||
$querySettings->setRespectStoragePage(false);
|
||||
$this->setDefaultQuerySettings($querySettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which matches the given pid. This
|
||||
* overwritten method exists, to perform sorting
|
||||
*
|
||||
* @param integer $pid Pid to search for
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult All found objects, will be
|
||||
* empty if there are no objects
|
||||
*/
|
||||
public function findByPid($pid)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
$query->matching($query->equals('pid', $pid));
|
||||
$query->setOrderings(
|
||||
[
|
||||
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
|
||||
]
|
||||
);
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which are located inside the
|
||||
* given pages
|
||||
*
|
||||
* @param array <\PwTeaserTeam\PwTeaser\Domain\Model\Page> $pages Pages to get content elements
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult All found objects, will be
|
||||
* empty if there are no objects
|
||||
*/
|
||||
public function findByPages($pages)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
$constraint = [];
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$constraint[] = $query->equals('pid', $page->getUid());
|
||||
}
|
||||
|
||||
$query->matching($query->logicalOr($constraint));
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
namespace PwTeaserTeam\PwTeaser\Domain\Repository;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2011-2020 Armin Vieweg <armin@v.ieweg.de>
|
||||
* 2016 Tim Klein-Hitpass <tim.klein-hitpass@diemedialen.de>
|
||||
* Kai Ratzeburg <kai.ratzeburg@diemedialen.de>
|
||||
*
|
||||
* 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 2 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 PwTeaserTeam\PwTeaser\Domain\Model\Page;
|
||||
use TYPO3\CMS\Core\Context\Context;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Repository for Page model
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
|
||||
*/
|
||||
class PageRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
||||
{
|
||||
/** Category Mode: Or */
|
||||
const CATEGORY_MODE_OR = 1;
|
||||
/** Category Mode: And */
|
||||
const CATEGORY_MODE_AND = 2;
|
||||
/** Category Mode: Or Not */
|
||||
const CATEGORY_MODE_OR_NOT = 3;
|
||||
/** Category Mode: And Not */
|
||||
const CATEGORY_MODE_AND_NOT = 4;
|
||||
|
||||
/**
|
||||
* page attribute to order by
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $orderBy = 'uid';
|
||||
|
||||
/**
|
||||
* Direction to order. Default is ascending.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
|
||||
*/
|
||||
protected $query = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $queryConstraints = [];
|
||||
|
||||
/**
|
||||
* Initializes the repository.
|
||||
*
|
||||
* @return void
|
||||
* @see \TYPO3\CMS\Extbase\Persistence\Repository::initializeObject()
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings */
|
||||
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface');
|
||||
$querySettings->setRespectStoragePage(false);
|
||||
$this->setDefaultQuerySettings($querySettings);
|
||||
$this->query = $this->createQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which match the pid
|
||||
*
|
||||
* @param integer $pid the pid to search for
|
||||
* @return array All found pages, will be empty if the result is empty
|
||||
*/
|
||||
public function findByPid($pid)
|
||||
{
|
||||
$this->addQueryConstraint($this->query->equals('pid', $pid));
|
||||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which are children of the matched
|
||||
* pid (recursively)
|
||||
*
|
||||
* @param integer $pid the pid to search for recursively
|
||||
* @param integer $recursionDepthFrom Start of recursion depth
|
||||
* @param integer $recursionDepth Depth of recursion
|
||||
* @return array All found pages, will be empty if the result is empty
|
||||
*/
|
||||
public function findByPidRecursively($pid, $recursionDepthFrom, $recursionDepth)
|
||||
{
|
||||
return $this->findChildrenRecursivelyByPidList($pid, $recursionDepthFrom, $recursionDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which are in the pidlist
|
||||
*
|
||||
* @param string $pidlist comma seperated list of pids to search for
|
||||
* @param boolean $orderByPlugin setting of ordering by plugin
|
||||
* @return array All found pages, will be empty if the result is empty
|
||||
*/
|
||||
public function findByPidList($pidlist, $orderByPlugin = false)
|
||||
{
|
||||
$pagePids = GeneralUtility::intExplode(',', $pidlist, true);
|
||||
|
||||
// early return when list is empty to prevent sql exception
|
||||
if (empty($pagePids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$query = $this->query;
|
||||
$this->addQueryConstraint($query->in('uid', $pagePids));
|
||||
$query->matching($query->logicalAnd($this->queryConstraints));
|
||||
|
||||
if ($orderByPlugin == false) {
|
||||
$this->handleOrdering($query);
|
||||
$results = $query->execute();
|
||||
$this->resetQuery();
|
||||
return $this->handlePageLocalization($results);
|
||||
} else {
|
||||
$results = $query->execute();
|
||||
$this->resetQuery();
|
||||
return $this->orderByPlugin($pagePids, $this->handlePageLocalization($results));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates array of result items, with the order of given pagePids
|
||||
*
|
||||
* @param array $pagePids pagePids to order for
|
||||
* @param array $results results to reorder
|
||||
* @return array results ordered by plugin
|
||||
*/
|
||||
protected function orderByPlugin(array $pagePids, array $results)
|
||||
{
|
||||
$sortedResults = [];
|
||||
foreach ($pagePids as $pagePid) {
|
||||
foreach ($results as $result) {
|
||||
if ($pagePid === $result->getUid()) {
|
||||
$sortedResults[] = $result;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sortedResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which are in the pidlist
|
||||
*
|
||||
* @param string $pidlist comma seperated list of pids to search for
|
||||
* @return array All found pages, will be empty if the result is empty
|
||||
*/
|
||||
public function findChildrenByPidList($pidlist)
|
||||
{
|
||||
$pagePids = GeneralUtility::intExplode(',', $pidlist, true);
|
||||
|
||||
// early return when list is empty to prevent sql exception
|
||||
if (empty($pagePids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->addQueryConstraint($this->query->in('pid', $pagePids));
|
||||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects of this repository which are children of pages in the
|
||||
* pidlist (recursively)
|
||||
*
|
||||
* @param string $pidlist comma seperated list of pids to search for
|
||||
* @param integer $recursionDepthFrom Start level for recursion
|
||||
* @param integer $recursionDepth Depth of recursion
|
||||
* @return array All found pages, will be empty if the result is empty
|
||||
*/
|
||||
public function findChildrenRecursivelyByPidList($pidlist, $recursionDepthFrom, $recursionDepth)
|
||||
{
|
||||
$pagePids = $this->getRecursivePageList($pidlist, $recursionDepthFrom, $recursionDepth);
|
||||
|
||||
$this->addQueryConstraint($this->query->in(($recursionDepthFrom === 0) ? 'pid' : 'uid', $pagePids));
|
||||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds query constraint to array
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint Constraint to add
|
||||
* @return void
|
||||
*/
|
||||
protected function addQueryConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
|
||||
{
|
||||
$this->queryConstraints[] = $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category constraint
|
||||
*
|
||||
* @param array $categories
|
||||
* @param boolean $isAnd If TRUE categories get a logicalAnd. Otherwise a logicalOr.
|
||||
* @param boolean $isNot If TRUE categories get a logicalNot operator. Otherwise not.
|
||||
* @return void
|
||||
*/
|
||||
public function addCategoryConstraint(array $categories, $isAnd = true, $isNot = false)
|
||||
{
|
||||
if ($isAnd === true && $isNot === false) {
|
||||
$this->queryConstraints[] = $this->query->logicalAnd($this->buildCategoryConstraint($categories));
|
||||
}
|
||||
if ($isAnd === true && $isNot === true) {
|
||||
$this->queryConstraints[] = $this->query->logicalNot(
|
||||
$this->query->logicalAnd(
|
||||
$this->buildCategoryConstraint($categories)
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($isAnd === false && $isNot === false) {
|
||||
$this->queryConstraints[] = $this->query->logicalOr($this->buildCategoryConstraint($categories));
|
||||
}
|
||||
if ($isAnd === false && $isNot === true) {
|
||||
$this->queryConstraints[] = $this->query->logicalNot(
|
||||
$this->query->logicalOr(
|
||||
$this->buildCategoryConstraint($categories)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build category constraint for each category (contains)
|
||||
*
|
||||
* @param array $categories
|
||||
* @return array
|
||||
*/
|
||||
protected function buildCategoryConstraint(array $categories)
|
||||
{
|
||||
$contraints = [];
|
||||
foreach ($categories as $category) {
|
||||
$contraints[] = $this->query->contains('categories', $category);
|
||||
}
|
||||
return $contraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize given query constraints and executes the query
|
||||
*
|
||||
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface Result of query
|
||||
*/
|
||||
protected function executeQuery()
|
||||
{
|
||||
$query = $this->query;
|
||||
$query->matching($query->logicalAnd($this->queryConstraints));
|
||||
$this->handleOrdering($query);
|
||||
|
||||
$queryResult = $query->execute();
|
||||
$this->resetQuery();
|
||||
|
||||
$queryResult = $this->handlePageLocalization($queryResult);
|
||||
return $queryResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles page localization
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $pages
|
||||
* @return array<\PwTeaserTeam\PwTeaser\Domain\Model\Page>
|
||||
*/
|
||||
protected function handlePageLocalization(\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $pages)
|
||||
{
|
||||
/** @var Context $context */
|
||||
$context = GeneralUtility::makeInstance(Context::class);
|
||||
$currentLangUid = $context->getPropertyFromAspect('language', 'id');
|
||||
$displayedPages = [];
|
||||
|
||||
/** @var Page $page */
|
||||
foreach ($pages as $page) {
|
||||
if ($currentLangUid === 0) {
|
||||
if ($page->getL18nConfiguration() !== Page::L18N_HIDE_DEFAULT_LANGUAGE &&
|
||||
$page->getL18nConfiguration() !== Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) {
|
||||
$displayedPages[] = $page;
|
||||
}
|
||||
} else {
|
||||
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageSelect */
|
||||
$pageSelect = $GLOBALS['TSFE']->sys_page;
|
||||
$pageRowWithOverlays = $pageSelect->getPage($page->getUid());
|
||||
|
||||
if ((boolean)$GLOBALS['TYPO3_CONF_VARS']['FE']['hidePagesIfNotTranslatedByDefault'] === false) {
|
||||
if (!($page->getL18nConfiguration() === Page::L18N_HIDE_IF_NO_TRANSLATION_EXISTS ||
|
||||
$page->getL18nConfiguration() === Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) ||
|
||||
isset($pageRowWithOverlays['_PAGES_OVERLAY'])) {
|
||||
$displayedPages[] = $page;
|
||||
}
|
||||
} else {
|
||||
if (($page->getL18nConfiguration() === Page::L18N_HIDE_IF_NO_TRANSLATION_EXISTS ||
|
||||
$page->getL18nConfiguration() === Page::L18N_HIDE_ALWAYS_BUT_TRANSLATION_EXISTS) &&
|
||||
!isset($pageRowWithOverlays['_PAGES_OVERLAY']) ||
|
||||
isset($pageRowWithOverlays['_PAGES_OVERLAY'])) {
|
||||
$displayedPages[] = $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $displayedPages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subpages recursivley of given pid(s).
|
||||
*
|
||||
* @param string $pidlist List of pageUids to get subpages of. May contain a single uid.
|
||||
* @param integer $recursionDepthFrom Start of recursion depth
|
||||
* @param integer $recursionDepth Depth of recursion
|
||||
* @return array Found subpages, recursivley
|
||||
*/
|
||||
protected function getRecursivePageList($pidlist, $recursionDepthFrom, $recursionDepth)
|
||||
{
|
||||
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer */
|
||||
$contentObjectRenderer = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
|
||||
|
||||
$pagePids = [];
|
||||
$pids = GeneralUtility::intExplode(',', $pidlist, true);
|
||||
foreach ($pids as $pid) {
|
||||
$pageList = GeneralUtility::intExplode(
|
||||
',',
|
||||
$contentObjectRenderer->getTreeList($pid, $recursionDepth, $recursionDepthFrom),
|
||||
true
|
||||
);
|
||||
$pagePids = array_merge($pagePids, $pageList);
|
||||
if ($recursionDepthFrom === 0) {
|
||||
array_unshift($pagePids, $pid);
|
||||
}
|
||||
}
|
||||
return array_unique($pagePids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the order by which is used by all find methods
|
||||
*
|
||||
* @param string $orderBy property to order by
|
||||
* @return void
|
||||
*/
|
||||
public function setOrderBy($orderBy)
|
||||
{
|
||||
if ($orderBy !== 'random') {
|
||||
$this->orderBy = $orderBy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the order direction which is used by all find methods
|
||||
*
|
||||
* @param string $orderDirection the direction to order, may be desc or asc
|
||||
* @return void
|
||||
*/
|
||||
public function setOrderDirection($orderDirection)
|
||||
{
|
||||
if ($orderDirection == 'desc' || $orderDirection == 1) {
|
||||
$this->orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
|
||||
} else {
|
||||
$this->orderDirection = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query limit
|
||||
*
|
||||
* @param integer $limit The limit of elements to show
|
||||
* @return void
|
||||
*/
|
||||
public function setLimit($limit)
|
||||
{
|
||||
$this->query->setLimit($limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the nav_hide_state flag
|
||||
*
|
||||
* @param boolean $showNavHiddenItems If TRUE lets show items which should not be visible in navigation.
|
||||
* Default is FALSE.
|
||||
* @return void
|
||||
*/
|
||||
public function setShowNavHiddenItems($showNavHiddenItems)
|
||||
{
|
||||
if ($showNavHiddenItems === true) {
|
||||
$this->addQueryConstraint($this->query->in('nav_hide', [0, 1]));
|
||||
} else {
|
||||
$this->addQueryConstraint($this->query->in('nav_hide', [0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets doktypes to filter for
|
||||
*
|
||||
* @param array $dokTypesToFilterFor doktypes as array, may be empty
|
||||
* @return void
|
||||
*/
|
||||
public function setFilteredDokType(array $dokTypesToFilterFor)
|
||||
{
|
||||
if (count($dokTypesToFilterFor) > 0) {
|
||||
$this->addQueryConstraint($this->query->in('doktype', $dokTypesToFilterFor));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores given uid
|
||||
*
|
||||
* @param integer $currentPageUid Uid to ignore
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoreOfUid($currentPageUid)
|
||||
{
|
||||
$this->addQueryConstraint($this->query->logicalNot($this->query->equals('uid', $currentPageUid)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds handle of ordering to query object
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
|
||||
* @return void
|
||||
*/
|
||||
protected function handleOrdering(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query)
|
||||
{
|
||||
$query->setOrderings([$this->orderBy => $this->orderDirection]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets query and queryConstraints after execution
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function resetQuery()
|
||||
{
|
||||
unset($this->query);
|
||||
$this->query = $this->createQuery();
|
||||
unset($this->queryConstraints);
|
||||
$this->queryConstraints = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user