Skip to content

Commit 012fbbe

Browse files
committed
[FEATURE] Add source view in backend
1 parent 6261e76 commit 012fbbe

File tree

26 files changed

+1216
-27
lines changed

26 files changed

+1216
-27
lines changed

Classes/Controller/AnalysisController.php

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
use In2code\Lux\Domain\DataProvider\LanguagesNewsDataProvider;
1414
use In2code\Lux\Domain\DataProvider\LinkclickDataProvider;
1515
use In2code\Lux\Domain\DataProvider\NewsvisistsDataProvider;
16+
use In2code\Lux\Domain\DataProvider\PagevisistsBySourceDataProvider;
1617
use In2code\Lux\Domain\DataProvider\PagevisistsDataProvider;
1718
use In2code\Lux\Domain\DataProvider\ReferrerAmountDataProvider;
19+
use In2code\Lux\Domain\DataProvider\ReferrerCategoryDataProvider;
1820
use In2code\Lux\Domain\DataProvider\SearchDataProvider;
1921
use In2code\Lux\Domain\DataProvider\SocialMediaDataProvider;
2022
use In2code\Lux\Domain\DataProvider\UtmCampaignDataProvider;
@@ -25,6 +27,7 @@
2527
use In2code\Lux\Domain\Model\News;
2628
use In2code\Lux\Domain\Model\Page;
2729
use In2code\Lux\Domain\Model\Transfer\FilterDto;
30+
use In2code\Lux\Domain\Service\Referrer\Readable;
2831
use In2code\Lux\Exception\ArgumentsException;
2932
use In2code\Lux\Exception\AuthenticationException;
3033
use In2code\Lux\Utility\BackendUtility;
@@ -225,6 +228,54 @@ public function utmCsvAction(FilterDto $filter): ResponseInterface
225228
return $this->csvResponse();
226229
}
227230

231+
/**
232+
* @return void
233+
* @throws NoSuchArgumentException
234+
*/
235+
public function initializeSourcesAction(): void
236+
{
237+
$this->setFilter();
238+
}
239+
240+
/**
241+
* Sources with referrers
242+
*
243+
* @param FilterDto $filter
244+
* @param string $export
245+
* @return ResponseInterface
246+
* @throws ExceptionDbal
247+
*/
248+
public function sourcesAction(FilterDto $filter, string $export = ''): ResponseInterface
249+
{
250+
if ($export === 'csv') {
251+
return (new ForwardResponse('sourcesCsv'))->withArguments(['filter' => $filter]);
252+
}
253+
254+
$values = [
255+
'filter' => $filter,
256+
'referrers' => $this->pagevisitsRepository->getReferrers($filter),
257+
'sourceCategories' => GeneralUtility::makeInstance(Readable::class)->getAllKeys(),
258+
'categoryData' => GeneralUtility::makeInstance(ReferrerCategoryDataProvider::class, $filter),
259+
];
260+
$this->moduleTemplate->assignMultiple($values);
261+
262+
$this->addDocumentHeaderForCurrentController();
263+
return $this->defaultRendering();
264+
}
265+
266+
/**
267+
* @param FilterDto $filter
268+
* @return ResponseInterface
269+
* @throws ExceptionDbal
270+
*/
271+
public function sourcesCsvAction(FilterDto $filter): ResponseInterface
272+
{
273+
$this->view->assignMultiple([
274+
'referrers' => $this->pagevisitsRepository->getReferrers($filter),
275+
]);
276+
return $this->csvResponse();
277+
}
278+
228279
/**
229280
* @return void
230281
* @throws NoSuchArgumentException
@@ -443,6 +494,31 @@ public function detailSearchAction(string $searchterm): ResponseInterface
443494
return $this->defaultRendering();
444495
}
445496

497+
/**
498+
* @param string $referrerDomain
499+
* @return ResponseInterface
500+
* @throws ArgumentsException
501+
* @throws ExceptionDbal
502+
*/
503+
public function detailSourceAction(string $referrerDomain): ResponseInterface
504+
{
505+
$filter = BackendUtility::getFilterFromSession(
506+
'sources',
507+
$this->getControllerName(),
508+
['searchterm' => $referrerDomain, 'limit' => 100]
509+
);
510+
$this->moduleTemplate->assignMultiple([
511+
'filter' => $filter,
512+
'referrerDomain' => $referrerDomain,
513+
'pagevisits' => $this->pagevisitsRepository->findByReferrerDomain($filter),
514+
// 'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
515+
// 'searches' => $this->searchRepository->findByFilter($filter),
516+
]);
517+
518+
$this->addDocumentHeaderForCurrentController();
519+
return $this->defaultRendering();
520+
}
521+
446522
/**
447523
* AJAX action to show a detail view coming from contentAction
448524
*
@@ -475,6 +551,39 @@ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterfa
475551
return $response;
476552
}
477553

554+
/**
555+
* AJAX action to show a detail view coming from sourceAction
556+
*
557+
* @param ServerRequestInterface $request
558+
* @return ResponseInterface
559+
* @noinspection PhpUnused
560+
* @throws ExceptionDbal
561+
* @throws ArgumentsException
562+
*/
563+
public function detailAjaxSource(ServerRequestInterface $request): ResponseInterface
564+
{
565+
$filter = BackendUtility::getFilterFromSession(
566+
'sources',
567+
'Analysis',
568+
['searchterm' => (string)$request->getQueryParams()['referrerDomain'], 'limit' => 10]
569+
);
570+
$standaloneView = ObjectUtility::getStandaloneView();
571+
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
572+
'EXT:lux/Resources/Private/Templates/Analysis/SourcesDetailAjax.html'
573+
));
574+
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
575+
$standaloneView->assignMultiple([
576+
'filter' => $filter,
577+
'pagevisits' => $this->pagevisitsRepository->findByReferrerDomain($filter),
578+
'pagevisitsBySourceData' => GeneralUtility::makeInstance(PagevisistsBySourceDataProvider::class, $filter),
579+
]);
580+
$response = GeneralUtility::makeInstance(JsonResponse::class);
581+
/** @var StreamInterface $stream */
582+
$stream = $response->getBody();
583+
$stream->write(json_encode(['html' => $standaloneView->render()]));
584+
return $response;
585+
}
586+
478587
/**
479588
* AJAX action to show a detail view for news
480589
*
@@ -627,7 +736,7 @@ protected function addDocumentHeaderForCurrentController(): void
627736
if ($this->searchRepository->isTableFilled()) {
628737
$actions[] = 'search';
629738
}
630-
$actions = array_merge($actions, ['utm', 'linkListener']);
739+
$actions = array_merge($actions, ['utm', 'sources', 'linkListener']);
631740
$menuConfiguration = [];
632741
foreach ($actions as $action) {
633742
$menuConfiguration[] = [
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
namespace In2code\Lux\Domain\DataProvider;
5+
6+
use Doctrine\DBAL\Exception as ExceptionDbal;
7+
use In2code\Lux\Domain\Repository\PagevisitRepository;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
9+
10+
class PagevisistsBySourceDataProvider extends AbstractDynamicFilterDataProvider
11+
{
12+
/**
13+
* Set values like:
14+
* [
15+
* 'amounts' => [
16+
* 50,
17+
* 88,
18+
* 33
19+
* ],
20+
* 'titles' => [
21+
* 'Th',
22+
* 'Fr',
23+
* 'Now'
24+
* ]
25+
* ]
26+
*
27+
* @return void
28+
* @throws ExceptionDbal
29+
*/
30+
public function prepareData(): void
31+
{
32+
$pagevisitRepository = GeneralUtility::makeInstance(PagevisitRepository::class);
33+
$intervals = $this->filter->getIntervals();
34+
$frequency = (string)$intervals['frequency'];
35+
foreach ($intervals['intervals'] as $interval) {
36+
$this->data['amounts'][] = $pagevisitRepository->getNumberOfVisitsInTimeFrameBySource(
37+
$interval['start'],
38+
$interval['end'],
39+
$this->filter
40+
);
41+
$this->data['titles'][] = $this->getLabelForFrequency($frequency, $interval['start']);
42+
}
43+
$this->overruleLatestTitle($frequency);
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
namespace In2code\Lux\Domain\DataProvider;
5+
6+
use In2code\Lux\Domain\Repository\PagevisitRepository;
7+
use In2code\Lux\Utility\LocalizationUtility;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
9+
10+
class ReferrerCategoryDataProvider extends AbstractDataProvider
11+
{
12+
/**
13+
* Set values like:
14+
* [
15+
* 'amounts' => [
16+
* 120,
17+
* 88
18+
* ],
19+
* 'titles' => [
20+
* 'socialMedia',
21+
* 'aiChats',
22+
* ]
23+
* ]
24+
*
25+
* @return void
26+
*/
27+
public function prepareData(): void
28+
{
29+
/** @var PagevisitRepository $pagevisitRepository */
30+
$pagevisitRepository = GeneralUtility::makeInstance(PagevisitRepository::class);
31+
$titles = $amounts = [];
32+
$counter = 0;
33+
foreach ($pagevisitRepository->getReferrerCategoryAmounts($this->filter) as $sourceKey => $amount) {
34+
$titles[] = LocalizationUtility::translateByKey('readablereferrer.' . $sourceKey);
35+
$amounts[] = $amount;
36+
if ($counter >= 5) {
37+
break;
38+
}
39+
$counter++;
40+
}
41+
$this->data = ['amounts' => $amounts, 'titles' => $titles];
42+
}
43+
}

0 commit comments

Comments
 (0)