Skip to content

Commit

Permalink
Merge branch 'release/34.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Sep 20, 2023
2 parents d1d40ae + 945e34f commit 09e781a
Show file tree
Hide file tree
Showing 76 changed files with 1,251 additions and 470 deletions.
125 changes: 125 additions & 0 deletions Classes/Backend/Units/AbstractUnit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units;

use In2code\Lux\Domain\Cache\CacheLayer;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\ObjectUtility;
use In2code\Lux\Utility\StringUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

abstract class AbstractUnit
{
protected array $arguments = [];
protected ?FilterDto $filter = null;
protected ?CacheLayer $cacheLayer = null;
protected string $templateRootPath = 'EXT:lux/Resources/Private/Templates/Backend/Units';
protected string $partialRootPath = 'EXT:lux/Resources/Private/Partials';
protected string $classPrefix = 'In2code\Lux\Backend\Units\\';

/**
* Optional string for cacheLayer
*
* @var string
*/
protected string $cacheLayerClass = '';

/**
* Optional string for cacheLayer
*
* @var string
*/
protected string $cacheLayerFunction = '';

/**
* Optional string for filter from session
*
* @var string
*/
protected string $filterClass = '';

/**
* Optional string for filter from session
*
* @var string
*/
protected string $filterFunction = '';

public function __construct(array $arguments = [])
{
$this->arguments = $arguments;
}

public function get(): string
{
$this->initialize();
return $this->getHtml();
}

protected function initialize(): void
{
$this->initializeFilter();
$this->initializeCacheLayer();
}

protected function initializeFilter(): void
{
$filter = ObjectUtility::getFilterDto();
if ($this->filterClass !== '' && $this->filterFunction !== '') {
$filterFromSession = BackendUtility::getSessionValue('filter', $this->filterFunction, $this->filterClass);
if (is_a($filterFromSession, FilterDto::class)) {
$filter = $filterFromSession;
}
}
$this->filter = $filter;
}

protected function initializeCacheLayer(): void
{
if ($this->cacheLayerClass !== '' && $this->cacheLayerFunction !== '') {
$this->cacheLayer = GeneralUtility::makeInstance(CacheLayer::class);
$this->cacheLayer->initialize($this->cacheLayerClass, $this->cacheLayerFunction);
}
}

protected function getHtml(): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths([$this->templateRootPath]);
$view->setPartialRootPaths([$this->partialRootPath]);
$view->setTemplate($this->getTemplatePath());
$view->assignMultiple([
'cacheLayerClass' => $this->cacheLayerClass,
'cacheLayerFunction' => $this->cacheLayerFunction,
'filterClass' => $this->filterClass,
'filterFunction' => $this->filterFunction,
'cacheLayer' => $this->cacheLayer,
'filter' => $this->filter,
'arguments' => $this->arguments,
] + $this->assignAdditionalVariables());
return $view->render();
}

protected function assignAdditionalVariables(): array
{
return [];
}

protected function getArgument(string $key): string
{
if (array_key_exists($key, $this->arguments)) {
return (string)$this->arguments[$key];
}
return '';
}

protected function getTemplatePath(): string
{
$path = StringUtility::removeStringPrefix(static::class, $this->classPrefix);
return str_replace('\\', '/', $path);
}
}
29 changes: 29 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Browser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\DataProvider\BrowserAmountDataProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Browser extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/Browser/' . $this->filter->getHash())) {
return [];
}
return [
'browserData' => GeneralUtility::makeInstance(BrowserAmountDataProvider::class, $this->filter),
];
}
}
29 changes: 29 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Downloads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\DataProvider\DownloadsDataProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Downloads extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/Downloads/' . $this->filter->getHash())) {
return [];
}
return [
'numberOfDownloadsData' => GeneralUtility::makeInstance(DownloadsDataProvider::class, $this->filter),
];
}
}
29 changes: 29 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Pagevisits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\DataProvider\PagevisistsDataProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Pagevisits extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/Pagevisits/' . $this->filter->getHash())) {
return [];
}
return [
'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class),
];
}
}
27 changes: 27 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Pagevisitsleads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\Repository\PagevisitRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Pagevisitsleads extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
$pagevisitsRepository = GeneralUtility::makeInstance(PagevisitRepository::class);
return [
'latestPagevisits' => $pagevisitsRepository->findLatestPagevisits($this->filter),
];
}
}
29 changes: 29 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Socialmedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\DataProvider\SocialMediaDataProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Socialmedia extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/SocialMedia/' . $this->filter->getHash())) {
return [];
}
return [
'socialMediaData' => GeneralUtility::makeInstance(SocialMediaDataProvider::class, $this->filter),
];
}
}
30 changes: 30 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Top/Downloads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard\Top;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\Repository\DownloadRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Downloads extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/TopDownloads/' . $this->filter->getHash())) {
return [];
}
$downloadRepository = GeneralUtility::makeInstance(DownloadRepository::class);
return [
'downloads' => $downloadRepository->findCombinedByHref($this->filter),
];
}
}
30 changes: 30 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Top/News.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard\Top;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\Repository\NewsvisitRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class News extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/TopNews/' . $this->filter->getHash())) {
return [];
}
$newsvisitRepository = GeneralUtility::makeInstance(NewsvisitRepository::class);
return [
'news' => $newsvisitRepository->findCombinedByNewsIdentifier($this->filter),
];
}
}
30 changes: 30 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Top/Pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard\Top;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\Repository\PagevisitRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Pages extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/TopPages/' . $this->filter->getHash())) {
return [];
}
$pagevisitsRepository = GeneralUtility::makeInstance(PagevisitRepository::class);
return [
'pages' => $pagevisitsRepository->findCombinedByPageIdentifier($this->filter),
];
}
}
30 changes: 30 additions & 0 deletions Classes/Backend/Units/Analysis/Dashboard/Top/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace In2code\Lux\Backend\Units\Analysis\Dashboard\Top;

use In2code\Lux\Backend\Units\AbstractUnit;
use In2code\Lux\Backend\Units\UnitInterface;
use In2code\Lux\Controller\AnalysisController;
use In2code\Lux\Domain\Repository\SearchRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class Search extends AbstractUnit implements UnitInterface
{
protected string $cacheLayerClass = AnalysisController::class;
protected string $cacheLayerFunction = 'dashboardAction';
protected string $filterClass = 'Analysis';
protected string $filterFunction = 'dashboard';

protected function assignAdditionalVariables(): array
{
if ($this->cacheLayer->isCacheAvailable('Box/Analysis/TopSearch/' . $this->filter->getHash())) {
return [];
}
$searchRepository = GeneralUtility::makeInstance(SearchRepository::class);
return [
'searchterms' => $searchRepository->findCombinedBySearchIdentifier($this->filter),
];
}
}
Loading

0 comments on commit 09e781a

Please sign in to comment.