From 87c6aa85e7d3a27f55e05fee15693f0a6033e987 Mon Sep 17 00:00:00 2001 From: Fabian Galinski <fabian@sgalinski.de> Date: Wed, 9 Oct 2019 17:12:35 +0200 Subject: [PATCH] [FEATURE] Some improvements and new functions for the author news --- Classes/Controller/NewsByAuthorController.php | 9 +- Classes/Domain/Model/Author.php | 6 +- .../RenderAuthorNewsViewHelper.php | 97 +++++++++++++++++++ Configuration/FlexForms/NewsByAuthor.xml | 14 +++ .../Private/Language/de.locallang_db.xlf | 4 + Resources/Private/Language/locallang_db.xlf | 3 + 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 Classes/ViewHelpers/RenderAuthorNewsViewHelper.php diff --git a/Classes/Controller/NewsByAuthorController.php b/Classes/Controller/NewsByAuthorController.php index 9d72e1e..24e0f56 100644 --- a/Classes/Controller/NewsByAuthorController.php +++ b/Classes/Controller/NewsByAuthorController.php @@ -50,7 +50,6 @@ class NewsByAuthorController extends AbstractController { return; } - $news = []; $authors = []; $authorRepository = $this->objectManager->get(AuthorRepository::class); foreach ($newsAuthorsIds as $newsAuthorsId) { @@ -72,11 +71,15 @@ class NewsByAuthorController extends AbstractController { return; } - $categories = []; + $categories = $newsMetaData = []; $categoryRepository = $this->objectManager->get(CategoryRepository::class); - $newsMetaData = []; + $excludedNewsIds = GeneralUtility::intExplode(',', $this->settings['excludedNews']); foreach ($news as $newsEntry) { /** @var News $newsEntry */ + if (in_array($newsEntry->getUid(), $excludedNewsIds, TRUE)) { + continue; + } + $categoryId = $newsEntry->getPid(); if (!isset($categories[$categoryId])) { $category = $categoryRepository->findByUid($categoryId); diff --git a/Classes/Domain/Model/Author.php b/Classes/Domain/Model/Author.php index 75e64ae..2038942 100644 --- a/Classes/Domain/Model/Author.php +++ b/Classes/Domain/Model/Author.php @@ -182,6 +182,10 @@ class Author extends AbstractEntity { } } - return $this->email; + if ($this->image instanceof LazyLoadingProxy) { + $this->image->_loadRealInstance(); + } + + return $this->image; } } diff --git a/Classes/ViewHelpers/RenderAuthorNewsViewHelper.php b/Classes/ViewHelpers/RenderAuthorNewsViewHelper.php new file mode 100644 index 0000000..d5980cc --- /dev/null +++ b/Classes/ViewHelpers/RenderAuthorNewsViewHelper.php @@ -0,0 +1,97 @@ +<?php + +namespace SGalinski\SgNews\ViewHelpers; + +/*************************************************************** + * Copyright notice + * + * (c) sgalinski Internet Services (http://www.sgalinski.de) + * + * All rights reserved + * + * This script is part of the AY project. The AY 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\Core\Bootstrap; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; + +/** + * Example: + * {namespace sgnews=SGalinski\SgNews\ViewHelpers} + * <sgnews:renderAuthorNews newsAuthors="123,321" excludedNews="123,423" /> + */ +class RenderAuthorNewsViewHelper extends AbstractViewHelper { + /** + * Extbase Bootstrap + * + * @var Bootstrap + */ + protected $bootstrap; + + /** + * @param Bootstrap $bootstrap + * @return void + */ + public function injectBootstrap(Bootstrap $bootstrap) { + $this->bootstrap = $bootstrap; + } + + /** + * CommentThreadViewHelper constructor. + */ + public function __construct() { + $this->escapeOutput = FALSE; + $this->escapeChildren = FALSE; + } + + /** + * Initialize arguments. + * + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception + * @return void + * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception + */ + public function initializeArguments() { + $this->registerArgument('newsAuthors', 'string', 'A list with author uids', TRUE); + $this->registerArgument('excludedNews', 'string', 'A list with excluded news uids'); + } + + /** + * Renders the Comment plugin. The view helper arguments configures the behavior. + * + * @return mixed + */ + public function render() { + $configuration = [ + 'extensionName' => 'SgNews', + 'vendorName' => 'SGalinski', + 'pluginName' => 'NewsByAuthor', + 'controllerName' => 'NewsByAuthor', + 'action' => 'list' + ]; + + if ($this->arguments['newsAuthors']) { + $configuration['settings']['newsAuthors'] = $this->arguments['newsAuthors']; + } + + if ($this->arguments['excludedNews']) { + $configuration['settings']['excludedNews'] = $this->arguments['excludedNews']; + } + + return $this->bootstrap->run('', $configuration); + } +} diff --git a/Configuration/FlexForms/NewsByAuthor.xml b/Configuration/FlexForms/NewsByAuthor.xml index 18e816f..14a87eb 100644 --- a/Configuration/FlexForms/NewsByAuthor.xml +++ b/Configuration/FlexForms/NewsByAuthor.xml @@ -28,6 +28,20 @@ </config> </TCEforms> </settings.newsAuthors> + + <settings.excludedNews> + <TCEforms> + <label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.excludedNews</label> + <config> + <type>select</type> + <renderType>selectMultipleSideBySide</renderType> + <size>5</size> + <maxitems>99</maxitems> + <foreign_table>pages</foreign_table> + <foreign_table_where>AND pages.sys_language_uid IN (-1, 0) AND pages.doktype = 116 ORDER BY pages.title</foreign_table_where> + </config> + </TCEforms> + </settings.excludedNews> </el> </ROOT> </main> diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf index d2d570c..afd03d0 100644 --- a/Resources/Private/Language/de.locallang_db.xlf +++ b/Resources/Private/Language/de.locallang_db.xlf @@ -101,6 +101,10 @@ <source><![CDATA[Only show news published before]]></source> <target><![CDATA[Zeige nur News veröffentlicht vor]]></target> </trans-unit> + <trans-unit id="plugin.flexForm.excludedNews" approved="yes"> + <source><![CDATA[News which are excluded from the list]]></source> + <target><![CDATA[News, welche nicht in der Liste dargestellt werden]]></target> + </trans-unit> <trans-unit id="plugin.flexForm.newsAuthor" approved="yes"> <source><![CDATA[News Author]]></source> <target><![CDATA[News Autor]]></target> diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index deb3023..71c34dc 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -78,6 +78,9 @@ <trans-unit id="plugin.flexForm.endtime"> <source><![CDATA[Only show news published before]]></source> </trans-unit> + <trans-unit id="plugin.flexForm.excludedNews"> + <source><![CDATA[News which are excluded from the list]]></source> + </trans-unit> <trans-unit id="plugin.flexForm.newsAuthor"> <source><![CDATA[News Author]]></source> </trans-unit> -- GitLab