Skip to content
Snippets Groups Projects
Commit ce7ebb87 authored by Fabian Galinski's avatar Fabian Galinski :pouting_cat:
Browse files

[TASK] Integration of languagevisibility into sg_news

parent b83c58d4
No related branches found
No related tags found
1 merge request!1Task apply language visibility to the news
......@@ -55,10 +55,12 @@ class LatestController extends AbstractController {
/**
* Renders the news overview
*
* @param array $newsMetaData
* @param int $offset
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction() {
public function indexAction(array $newsMetaData = [], $offset = 0) {
$limit = ((int) $this->settings['limit']);
$limit = ($limit < 1 ? 1 : $limit);
......@@ -69,10 +71,9 @@ class LatestController extends AbstractController {
}
$latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
$limit, FALSE, $categoryUids, 0, TRUE, $this->settings['sortBy'], $tagUids
$limit, FALSE, $categoryUids, $offset, TRUE, $this->settings['sortBy'], $tagUids
);
$newsMetaData = [];
$categories = [];
foreach ($latestNewsEntries as $latestNewsEntry) {
/** @var News $latestNewsEntry */
......@@ -88,8 +89,25 @@ class LatestController extends AbstractController {
}
$newsMetaData[] = $this->getMetaDataForNews($latestNewsEntry, $category);
// Make sure, that the amount is the same as the configured limit.
if (count($newsMetaData) >= $limit) {
break;
}
}
// Redo this function, until $newsMetaData gets the $limit. Needed because of languagevisibility.
if (count($newsMetaData) < $limit) {
$offset += $limit;
$maxCount = $this->newsRepository->getCountOfLastUpdatedOrHighlightedNewsByCategories(
FALSE, $categoryUids, TRUE, $this->settings['sortBy'], $tagUids
);
if ($offset < $maxCount) {
$this->indexAction($newsMetaData, $offset);
return;
}
}
$this->view->assign('newsMetaData', $newsMetaData);
}
}
......@@ -55,10 +55,11 @@ class ListByCategoryController extends AbstractController {
/**
* Renders the news list of a category
*
* @param array $newsMetaData
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction() {
public function indexAction(array $newsMetaData = []) {
$filterByCategories = FALSE;
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories']);
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
......@@ -87,7 +88,6 @@ class ListByCategoryController extends AbstractController {
$newsCount = $this->newsRepository->newsCountByCategories($categoryUids, $tagUids);
$numberOfPages = ($newsPerPage <= 0 ? 0 : ceil($newsCount / $newsPerPage));
$newsMetaData = [];
$headerSet = FALSE;
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryUids, $newsPerPage, $offset, $this->settings['sortBy'], $tagUids
......@@ -108,6 +108,16 @@ class ListByCategoryController extends AbstractController {
}
}
// Redo this function, until one variable get the amount of $newsPerPage. Reduces the amount of ajax calls. Needed because of languagevisibility.
if (count($newsMetaData) < $newsPerPage) {
$nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]);
$this->indexAction($newsMetaData);
return;
}
}
$this->view->assign('numberOfPages', $numberOfPages);
$this->view->assign('newsMetaData', $newsMetaData);
$this->view->assign('categories', $categories);
......
......@@ -111,10 +111,12 @@ class OverviewController extends AbstractController {
/**
* Renders the news overview grouped by categories
*
* @param array $newsByCategory
* @param array $allNews
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function overviewWithCategories() {
protected function overviewWithCategories(array $newsByCategory = [], array $allNews = []) {
$newsLimitPerCategory = (int) $this->settings['newsLimit'];
$this->categoryRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]);
......@@ -147,24 +149,35 @@ class OverviewController extends AbstractController {
/** @var News $newsEntry */
$categoryId = $newsEntry->getPid();
$category = $categoriesById[$categoryId];
if (!$category) {
// Category isn't visible.
continue;
}
$data = $this->getMetaDataForNews($newsEntry, $category);
$newsMetaData[$categoryId][] = $data;
}
}
$newsByCategory = [];
$maxNewsPerCategory = 0;
foreach ($categoriesById as $categoryId => $category) {
/** @var $category Category */
$newsByCategory[$categoryId] = [
'record' => $category,
'recordId' => $categoryId,
'recordType' => 'category',
'newsMetaData' => $newsMetaData[$categoryId]
];
if (isset($newsByTag[$categoryId])) {
/** @var $category Category */
$newsByCategory[$categoryId]['newsMetaData'] =
array_merge($newsByCategory[$categoryId]['newsMetaData'], $newsMetaData[$categoryId]);
} else {
$newsByCategory[$categoryId] = [
'record' => $category,
'recordId' => $categoryId,
'recordType' => 'category',
'newsMetaData' => $newsMetaData[$categoryId]
];
}
$maxNewsPerCategory = max($newsByCategory, count($newsByTag[$categoryId]['newsMetaData']));
}
$allNews = [];
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimitPerCategory, $offset, $this->settings['sortBy']
);
......@@ -172,6 +185,10 @@ class OverviewController extends AbstractController {
/** @var News $newsEntry */
$categoryId = $newsEntry->getPid();
$category = $categoriesById[$categoryId];
if (!$category) {
// Category isn't visible.
continue;
}
$data = $this->getMetaDataForNews($newsEntry, $category);
$allNews[] = $data;
......@@ -181,6 +198,16 @@ class OverviewController extends AbstractController {
$newsCount = $this->newsRepository->newsCountByCategories($categoryIds);
$numberOfPages = ($newsLimitPerCategory <= 0 ? 0 : ceil($newsCount / $newsLimitPerCategory));
// Redo this function, until one variable get the amount of newsLimitPerTag. Reduces the amount of ajax calls. Needed because of languagevisibility.
if ($maxNewsPerCategory < $newsLimitPerCategory && count($allNews) < $newsLimitPerCategory) {
$nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]);
$this->overviewWithCategories($newsByCategory, $allNews);
return;
}
}
$this->view->assign('numberOfPages', $numberOfPages);
$this->view->assign('newsItems', $newsByCategory);
$this->view->assign('groupBy', 'category');
......@@ -190,10 +217,12 @@ class OverviewController extends AbstractController {
/**
* Renders the news overview grouped by tags
*
* @param array $newsByTag
* @param array $allNews
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function overviewWithTags() {
protected function overviewWithTags(array $newsByTag = [], array $allNews = []) {
$newsLimitPerTag = (int) $this->settings['newsLimit'];
$this->tagRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]);
......@@ -234,24 +263,40 @@ class OverviewController extends AbstractController {
$categoriesById[$categoryId] = $this->categoryRepository->findByUid($categoryId);
}
$category = $categoriesById[$categoryId];
if (!$category) {
// Category isn't visible.
continue;
}
$data = $this->getMetaDataForNews($newsEntry, $category);
$newsMetaData[$tagId][] = $data;
}
}
$newsByTag = [];
$maxNewsPerTag = 0;
foreach ($tagsById as $tagId => $tag) {
/** @var $category Category */
$newsByTag[$tagId] = [
'record' => $tag,
'recordId' => $tagId,
'recordType' => 'tag',
'newsMetaData' => $newsMetaData[$tagId]
];
if (count($newsMetaData[$tagId]) <= 0) {
// Hide empty tags.
continue;
}
if (isset($newsByTag[$tagId])) {
/** @var $category Category */
$newsByTag[$tagId]['newsMetaData'] =
array_merge($newsByTag[$tagId]['newsMetaData'], $newsMetaData[$tagId]);
} else {
/** @var $category Category */
$newsByTag[$tagId] = [
'record' => $tag,
'recordId' => $tagId,
'recordType' => 'tag',
'newsMetaData' => $newsMetaData[$tagId]
];
}
$maxNewsPerTag = max($maxNewsPerTag, count($newsByTag[$tagId]['newsMetaData']));
}
$allNews = [];
$news = $this->newsRepository->findAllSortedNewsByCategories(
NULL, $newsLimitPerTag, $offset, $this->settings['sortBy'], $tagIds
);
......@@ -262,6 +307,10 @@ class OverviewController extends AbstractController {
$categoriesById[$categoryId] = $this->categoryRepository->findByUid($categoryId);
}
$category = $categoriesById[$categoryId];
if (!$category) {
// Category isn't visible.
continue;
}
$data = $this->getMetaDataForNews($newsEntry, $category);
$allNews[] = $data;
......@@ -271,6 +320,16 @@ class OverviewController extends AbstractController {
$newsCount = $this->newsRepository->newsCountByCategories([], $tagIds);
$numberOfPages = ($newsLimitPerTag <= 0 ? 0 : ceil($newsCount / $newsLimitPerTag));
// Redo this function, until one variable get the amount of newsLimitPerTag. Reduces the amount of ajax calls. Needed because of languagevisibility.
if ($maxNewsPerTag < $newsLimitPerTag && count($allNews) < $newsLimitPerTag) {
$nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]);
$this->overviewWithTags($newsByTag, $allNews);
return;
}
}
$this->view->assign('numberOfPages', $numberOfPages);
$this->view->assign('newsItems', $newsByTag);
$this->view->assign('groupBy', 'tag');
......@@ -280,10 +339,11 @@ class OverviewController extends AbstractController {
/**
* Renders the news in a paginated list
*
* @param array $newsMetaData
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function overviewWithoutCategoriesAction() {
protected function overviewWithoutCategoriesAction(array $newsMetaData = []) {
$offset = 0;
$newsPerPage = (int) $this->settings['newsLimit'];
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
......@@ -318,7 +378,6 @@ class OverviewController extends AbstractController {
}
}
$newsMetaData = [];
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsPerPage, $offset, $this->settings['sortBy']
);
......@@ -331,6 +390,16 @@ class OverviewController extends AbstractController {
$this->highlightBestFitNews($categoryIds);
$numberOfPages = ($newsPerPage <= 0 ? 0 : ceil($newsCount / $newsPerPage));
// Redo this function, until one variable get the amount of newsLimitPerTag. Reduces the amount of ajax calls. Needed because of languagevisibility.
if (count($newsMetaData) < $newsPerPage) {
$nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]);
$this->overviewWithoutCategoriesAction($newsMetaData);
return;
}
}
$this->view->assign('numberOfPages', $numberOfPages);
$this->view->assign('newsMetaData', $newsMetaData);
}
......
......@@ -155,6 +155,49 @@ class NewsRepository extends AbstractRepository {
public function findLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL
) {
return $this->getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit, $onlyHighlighted, $categoryIds, $offset, $hideNeverHighlightedNews, $sortBy, $tagIds
)->execute();
}
/**
* Returns the count of all possible last news.
*
* @param bool $onlyHighlighted
* @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid.
* @param int $offset
* @param bool $hideNeverHighlightedNews
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @return int
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function getCountOfLastUpdatedOrHighlightedNewsByCategories(
$onlyHighlighted = FALSE, array $categoryIds = NULL, $hideNeverHighlightedNews = FALSE, $sortBy = 'date',
array $tagIds = NULL
) {
return $this->getQueryForLastUpdatedOrHighlightedNewsByCategories(
0, $onlyHighlighted, $categoryIds, 0, $hideNeverHighlightedNews, $sortBy, $tagIds
)->count();
}
/**
* Returns the query object of the LastUpdatedOrHighlightedNewsByCategories.
*
* @param int $limit
* @param bool $onlyHighlighted
* @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid.
* @param int $offset
* @param bool $hideNeverHighlightedNews
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @return QueryInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL
) {
$query = $this->createQuery();
$constraints = NULL;
......@@ -215,7 +258,7 @@ class NewsRepository extends AbstractRepository {
$query->setOffset($offset);
}
return $query->matching($constraints)->execute();
return $query->matching($constraints);
}
// /**
......
......@@ -26,7 +26,10 @@ namespace SGalinski\SgNews\Xclass;
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
use TYPO3\Languagevisibility\Service\FrontendServices;
/**
* Xclass for the TYPO3 db backend, which handles, that the l18n_cfg parameters are used for pages in Extbase.
......@@ -85,6 +88,7 @@ class Typo3DbBackend extends \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo
}
}
$isLanguagevisibilityLoaded = ExtensionManagementUtility::isLoaded('languagevisibility');
$overlaidRows = array();
foreach ($rows as $row) {
// If current row is a translation select its parent
......@@ -106,12 +110,23 @@ class Typo3DbBackend extends \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo
}
$pageRepository->versionOL($tableName, $row, true);
if ($tableName == 'pages') {
// Start of the patch
// Applies the language visibility logic.
if ($isLanguagevisibilityLoaded && is_object($GLOBALS['TSFE'])) {
$sysLanguageUid = $GLOBALS['TSFE']->sys_language_uid;
if (!FrontendServices::checkVisiblityForElement((int) $row['uid'], $tableName, $sysLanguageUid)) {
// Page not visible
continue;
}
}
// End of the patch
$row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
if ($row === null || !is_array($row)) {
continue;
}
// Start of the patch
$l18nConfiguration = $row['l18n_cfg'];
if ($l18nConfiguration > 0) {
......
......@@ -3,35 +3,50 @@
{namespace sg=SGalinski\SgNews\ViewHelpers}
<f:section name="main">
<f:if condition="{newsItems}">
<div class="tx-sgnews-categories">
<ul class="nav nav-tabs">
<li class="tx-sgnews-category active">
<a data-toggle="tab" href="#sgnewsTab0">
<f:translate key="frontend.overview.allTabLabel" />
<div class="tx-sgnews-categories">
<ul class="nav nav-tabs">
<li class="tx-sgnews-category active">
<a data-toggle="tab" href="#sgnewsTab0">
<f:translate key="frontend.overview.allTabLabel" />
</a>
</li>
<f:for each="{newsItems}" as="dataItems">
<li class="tx-sgnews-category">
<a data-toggle="tab" href="#sgnewsTab{dataItems.record.uid}">
<f:if condition="{dataItems.recordType} == 'category'">
<f:then>
{dataItems.record.subtitleWithFallbackToTitle}
</f:then>
<f:else>
{dataItems.record.title}
</f:else>
</f:if>
</a>
</li>
<f:for each="{newsItems}" as="dataItems">
<li class="tx-sgnews-category">
<a data-toggle="tab" href="#sgnewsTab{dataItems.record.uid}">
<f:if condition="{dataItems.recordType} == 'category'">
<f:then>
{dataItems.record.subtitleWithFallbackToTitle}
</f:then>
<f:else>
{dataItems.record.title}
</f:else>
</f:if>
</a>
</li>
</f:for>
</ul>
</f:for>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="sgnewsTab0">
<h4 class="tx-sgnews-tab-title"><f:translate key="frontend.overview.allTabLabel" /></h4>
<ul class="tx-sgnews-list tx-sgnews-list-0 row" data-record="0">
<f:for each="{allNews}" as="newsMetaDataEntry">
<div class="tab-content">
<div class="tab-pane active" id="sgnewsTab0">
<h4 class="tx-sgnews-tab-title"><f:translate key="frontend.overview.allTabLabel" /></h4>
<ul class="tx-sgnews-list tx-sgnews-list-0 row" data-record="0">
<f:for each="{allNews}" as="newsMetaDataEntry">
<li class="col-md-4 col-sm-6 col-xs-12">
<f:render partial="Teaser" arguments="{
newsMetaData: newsMetaDataEntry,
headerTag: '<h2>',
closingHeaderTag: '</h2>',
showCategory: '{f:if(condition: \'{groupBy} == \"category\"\', then: 0, else: 1)}'
}" />
</li>
</f:for>
</ul>
</div>
<f:for each="{newsItems}" as="dataItems">
<div class="tab-pane" id="sgnewsTab{dataItems.record.uid}">
<h4 class="tx-sgnews-tab-title">{dataItems.record.title}</h4>
<ul class="tx-sgnews-list tx-sgnews-list-{dataItems.record.uid} row" data-record="{dataItems.record.uid}">
<f:for each="{dataItems.newsMetaData}" as="newsMetaDataEntry">
<li class="col-md-4 col-sm-6 col-xs-12">
<f:render partial="Teaser" arguments="{
newsMetaData: newsMetaDataEntry,
......@@ -42,35 +57,18 @@
</li>
</f:for>
</ul>
</div>
<f:for each="{newsItems}" as="dataItems">
<div class="tab-pane" id="sgnewsTab{dataItems.record.uid}">
<h4 class="tx-sgnews-tab-title">{dataItems.record.title}</h4>
<ul class="tx-sgnews-list tx-sgnews-list-{dataItems.record.uid} row" data-record="{dataItems.record.uid}">
<f:for each="{dataItems.newsMetaData}" as="newsMetaDataEntry">
<li class="col-md-4 col-sm-6 col-xs-12">
<f:render partial="Teaser" arguments="{
newsMetaData: newsMetaDataEntry,
headerTag: '<h2>',
closingHeaderTag: '</h2>',
showCategory: '{f:if(condition: \'{groupBy} == \"category\"\', then: 0, else: 1)}'
}" />
</li>
</f:for>
</ul>
<f:if condition="{dataItems.recordType} == 'category'">
<div class="text-center">
<a class="btn btn-md btn-success category-{dataByCategory.category.uid}" href="{f:uri.page(pageUid: '{dataByCategory.category.uid}')}">
<f:translate key="frontend.overview.showAllEntries" />
</a>
</div>
</f:if>
</div>
</f:for>
</div>
<f:if condition="{dataItems.recordType} == 'category'">
<div class="text-center">
<a class="btn btn-md btn-success category-{dataByCategory.category.uid}" href="{f:uri.page(pageUid: '{dataByCategory.category.uid}')}">
<f:translate key="frontend.overview.showAllEntries" />
</a>
</div>
</f:if>
</div>
</f:for>
</div>
</div>
<sg:pageBrowser numberOfPages="{numberOfPages}" />
</f:if>
<sg:pageBrowser numberOfPages="{numberOfPages}" />
</f:section>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment