Skip to content

Commit

Permalink
[FEATURE] First draft
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 18, 2024
1 parent 49c3008 commit be2842e
Show file tree
Hide file tree
Showing 17 changed files with 596 additions and 135 deletions.
4 changes: 4 additions & 0 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use In2code\Lux\Domain\Repository\SearchRepository;
use In2code\Lux\Domain\Repository\UtmRepository;
use In2code\Lux\Domain\Repository\VisitorRepository;
use In2code\Lux\Domain\Service\IndividualAnalyseView\Helper;
use In2code\Lux\Domain\Service\RenderingTimeService;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\ConfigurationUtility;
Expand Down Expand Up @@ -61,6 +62,7 @@ abstract class AbstractController extends ActionController
protected ?CompanyRepository $companyRepository = null;
protected ?WiredmindsRepository $wiredmindsRepository = null;
protected ?RenderingTimeService $renderingTimeService = null;
protected ?Helper $individualAnalyseViewHelper = null;
protected ?CacheLayer $cacheLayer = null;
protected ModuleTemplateFactory $moduleTemplateFactory;
protected ModuleTemplate $moduleTemplate;
Expand All @@ -83,6 +85,7 @@ public function __construct(
CompanyRepository $companyRepository,
WiredmindsRepository $wiredmindsRepository,
RenderingTimeService $renderingTimeService,
Helper $individualAnalyseViewHelper,
CacheLayer $cacheLayer,
ModuleTemplateFactory $moduleTemplateFactory
) {
Expand All @@ -103,6 +106,7 @@ public function __construct(
$this->companyRepository = $companyRepository;
$this->wiredmindsRepository = $wiredmindsRepository;
$this->renderingTimeService = $renderingTimeService;
$this->individualAnalyseViewHelper = $individualAnalyseViewHelper;
$this->cacheLayer = $cacheLayer;
$this->moduleTemplateFactory = $moduleTemplateFactory;
}
Expand Down
233 changes: 131 additions & 102 deletions Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use In2code\Lux\Domain\Model\News;
use In2code\Lux\Domain\Model\Page;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Exception\ConfigurationException;
use In2code\Lux\Utility\FileUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
Expand Down Expand Up @@ -134,52 +135,81 @@ public function contentCsvAction(FilterDto $filter): ResponseInterface
* @return void
* @throws NoSuchArgumentException
*/
public function initializeNewsAction(): void
public function initializeIndividualAnalyseViewAction(): void
{
$this->setFilter();
}

/**
* @param FilterDto $filter
* @param string $export
* @return ResponseInterface
* @throws Exception
* @throws ExceptionDbalDriver
*/
public function newsAction(FilterDto $filter, string $export = ''): ResponseInterface
public function individualAnalyseViewAction(FilterDto $filter, string $export = ''): ResponseInterface
{
if ($export === 'csv') {
die(__CLASS__ . ':' . __LINE__); // TOdo: ...
return (new ForwardResponse('newsCsv'))->withArguments(['filter' => $filter]);
}

$this->view->assignMultiple([
'filter' => $filter,
'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
'domains' => $this->newsvisitRepository->getAllDomains($filter),
'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter),
'languageData' => GeneralUtility::makeInstance(LanguagesNewsDataProvider::class, $filter),
'domainData' => GeneralUtility::makeInstance(DomainNewsDataProvider::class, $filter),
'domains' => $this->newsvisitRepository->getAllDomains($filter),
]);

$this->addDocumentHeaderForCurrentController();
return $this->defaultRendering();
}

/**
* @return void
* @throws NoSuchArgumentException
*/
// public function initializeNewsAction(): void
// {
// $this->setFilter();
// }

/**
* @param FilterDto $filter
* @param string $export
* @return ResponseInterface
* @throws Exception
* @throws ExceptionDbalDriver
*/
// public function newsAction(FilterDto $filter, string $export = ''): ResponseInterface
// {
// if ($export === 'csv') {
// return (new ForwardResponse('newsCsv'))->withArguments(['filter' => $filter]);
// }
//
// $this->view->assignMultiple([
// 'filter' => $filter,
// 'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
// 'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
// 'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter),
// 'languageData' => GeneralUtility::makeInstance(LanguagesNewsDataProvider::class, $filter),
// 'domainData' => GeneralUtility::makeInstance(DomainNewsDataProvider::class, $filter),
// 'domains' => $this->newsvisitRepository->getAllDomains($filter),
// ]);
//
// $this->addDocumentHeaderForCurrentController();
// return $this->defaultRendering();
// }

/**
* @param FilterDto $filter
* @return ResponseInterface
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
* @throws DBALException
*/
public function newsCsvAction(FilterDto $filter): ResponseInterface
{
$this->view->assignMultiple([
'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter),
]);
return $this->csvResponse();
}
// public function newsCsvAction(FilterDto $filter): ResponseInterface
// {
// $this->view->assignMultiple([
// 'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter),
// ]);
// return $this->csvResponse();
// }

/**
* @return void
Expand Down Expand Up @@ -298,18 +328,18 @@ public function initializeSearchAction(): void
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function searchAction(FilterDto $filter): ResponseInterface
{
$this->view->assignMultiple([
'filter' => $filter,
'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
'search' => $this->searchRepository->findCombinedBySearchIdentifier($filter),
]);

$this->addDocumentHeaderForCurrentController();
return $this->defaultRendering();
}
// public function searchAction(FilterDto $filter): ResponseInterface
// {
// $this->view->assignMultiple([
// 'filter' => $filter,
// 'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
// 'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
// 'search' => $this->searchRepository->findCombinedBySearchIdentifier($filter),
// ]);
//
// $this->addDocumentHeaderForCurrentController();
// return $this->defaultRendering();
// }

/**
* @param Linklistener $linkListener
Expand Down Expand Up @@ -348,18 +378,18 @@ public function detailPageAction(Page $page): ResponseInterface
* @throws ExceptionDbal
* @throws DBALException
*/
public function detailNewsAction(News $news): ResponseInterface
{
$filter = ObjectUtility::getFilterDto()->setSearchterm((string)$news->getUid());
$this->view->assignMultiple([
'news' => $news,
'newsvisits' => $this->newsvisitRepository->findByNews($news, 100),
'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
]);

$this->addDocumentHeaderForCurrentController();
return $this->defaultRendering();
}
// public function detailNewsAction(News $news): ResponseInterface
// {
// $filter = ObjectUtility::getFilterDto()->setSearchterm((string)$news->getUid());
// $this->view->assignMultiple([
// 'news' => $news,
// 'newsvisits' => $this->newsvisitRepository->findByNews($news, 100),
// 'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
// ]);
//
// $this->addDocumentHeaderForCurrentController();
// return $this->defaultRendering();
// }

/**
* @param string $href
Expand Down Expand Up @@ -404,18 +434,18 @@ public function detailLinkListenerAction(Linklistener $linkListener): ResponseIn
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function detailSearchAction(string $searchterm): ResponseInterface
{
$filter = ObjectUtility::getFilterDto()->setSearchterm($searchterm);
$this->view->assignMultiple([
'searchterm' => $searchterm,
'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
'searches' => $this->searchRepository->findBySearchterm(urldecode($searchterm)),
]);

$this->addDocumentHeaderForCurrentController();
return $this->defaultRendering();
}
// public function detailSearchAction(string $searchterm): ResponseInterface
// {
// $filter = ObjectUtility::getFilterDto()->setSearchterm($searchterm);
// $this->view->assignMultiple([
// 'searchterm' => $searchterm,
// 'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
// 'searches' => $this->searchRepository->findBySearchterm(urldecode($searchterm)),
// ]);
//
// $this->addDocumentHeaderForCurrentController();
// return $this->defaultRendering();
// }

/**
* AJAX action to show a detail view
Expand Down Expand Up @@ -456,27 +486,27 @@ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterfa
* @throws ExceptionDbalDriver
* @throws DBALException
*/
public function detailNewsAjaxPage(ServerRequestInterface $request): ResponseInterface
{
$filter = $this->getFilterFromSessionForAjaxRequests('news', (string)$request->getQueryParams()['news']);
/** @var News $news */
$news = $this->newsRepository->findByIdentifier((int)$request->getQueryParams()['news']);
$standaloneView = ObjectUtility::getStandaloneView();
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:lux/Resources/Private/Templates/Analysis/NewsDetailPageAjax.html'
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$standaloneView->assignMultiple([
'news' => $news,
'newsvisits' => $news !== null ? $this->newsvisitRepository->findByNews($news, 10) : null,
'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
]);
$response = GeneralUtility::makeInstance(JsonResponse::class);
/** @var StreamInterface $stream */
$stream = $response->getBody();
$stream->write(json_encode(['html' => $standaloneView->render()]));
return $response;
}
// public function detailNewsAjaxPage(ServerRequestInterface $request): ResponseInterface
// {
// $filter = $this->getFilterFromSessionForAjaxRequests('news', (string)$request->getQueryParams()['news']);
// /** @var News $news */
// $news = $this->newsRepository->findByIdentifier((int)$request->getQueryParams()['news']);
// $standaloneView = ObjectUtility::getStandaloneView();
// $standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
// 'EXT:lux/Resources/Private/Templates/Analysis/NewsDetailPageAjax.html'
// ));
// $standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
// $standaloneView->assignMultiple([
// 'news' => $news,
// 'newsvisits' => $news !== null ? $this->newsvisitRepository->findByNews($news, 10) : null,
// 'newsvisitsData' => GeneralUtility::makeInstance(NewsvisistsDataProvider::class, $filter),
// ]);
// $response = GeneralUtility::makeInstance(JsonResponse::class);
// /** @var StreamInterface $stream */
// $stream = $response->getBody();
// $stream->write(json_encode(['html' => $standaloneView->render()]));
// return $response;
// }

/**
* AJAX action to show a detail view for utm
Expand All @@ -498,25 +528,25 @@ public function detailUtmAjaxPage(ServerRequestInterface $request): ResponseInte
* @return ResponseInterface
* @noinspection PhpUnused
*/
public function detailSearchAjaxPage(ServerRequestInterface $request): ResponseInterface
{
$standaloneView = ObjectUtility::getStandaloneView();
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:lux/Resources/Private/Templates/Analysis/SearchDetailPageAjax.html'
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$standaloneView->assignMultiple([
'searches' => $this->searchRepository->findBySearchterm(
urldecode($request->getQueryParams()['searchterm'])
),
'searchterm' => $request->getQueryParams()['searchterm'],
]);
$response = GeneralUtility::makeInstance(JsonResponse::class);
/** @var StreamInterface $stream */
$stream = $response->getBody();
$stream->write(json_encode(['html' => $standaloneView->render()]));
return $response;
}
// public function detailSearchAjaxPage(ServerRequestInterface $request): ResponseInterface
// {
// $standaloneView = ObjectUtility::getStandaloneView();
// $standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
// 'EXT:lux/Resources/Private/Templates/Analysis/SearchDetailPageAjax.html'
// ));
// $standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
// $standaloneView->assignMultiple([
// 'searches' => $this->searchRepository->findBySearchterm(
// urldecode($request->getQueryParams()['searchterm'])
// ),
// 'searchterm' => $request->getQueryParams()['searchterm'],
// ]);
// $response = GeneralUtility::makeInstance(JsonResponse::class);
// /** @var StreamInterface $stream */
// $stream = $response->getBody();
// $stream->write(json_encode(['html' => $standaloneView->render()]));
// return $response;
// }

/**
* AJAX action to show a detail view
Expand Down Expand Up @@ -579,18 +609,11 @@ public function detailAjaxLinklistener(ServerRequestInterface $request): Respons

/**
* @return void
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
* @throws ConfigurationException
*/
protected function addDocumentHeaderForCurrentController(): void
{
$actions = ['dashboard', 'content', 'utm', 'linkListener'];
if ($this->newsvisitRepository->isTableFilled()) {
$actions[] = 'news';
}
if ($this->searchRepository->isTableFilled()) {
$actions[] = 'search';
}
$menuConfiguration = [];
foreach ($actions as $action) {
$menuConfiguration[] = [
Expand All @@ -600,6 +623,12 @@ protected function addDocumentHeaderForCurrentController(): void
),
];
}
foreach ($this->individualAnalyseViewHelper->getActivatedViews() as $configuration) {
$menuConfiguration[] = [
'action' => 'individualAnalyseView',
'label' => LocalizationUtility::translate($configuration['label']),
];
}
$this->addDocumentHeader($menuConfiguration);
}
}
Loading

0 comments on commit be2842e

Please sign in to comment.