Skip to content

Commit 3bab442

Browse files
committed
Merge branch 'feature/sourceview' into develop
2 parents c9a1c2f + 248b124 commit 3bab442

File tree

58 files changed

+1710
-1007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1710
-1007
lines changed

.project/TYPO3/additional.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
],
2121
],
2222
],
23+
'EXTCONF' => [
24+
'lang' => [
25+
'availableLanguages' => [
26+
'de',
27+
],
28+
],
29+
],
2330
'EXTENSIONS' => [
2431
'lux' => [
2532
'anonymizeIp' => '1',

Classes/Controller/AnalysisController.php

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
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;
20+
use In2code\Lux\Domain\DataProvider\ReferrerTopDataProvider;
1821
use In2code\Lux\Domain\DataProvider\SearchDataProvider;
1922
use In2code\Lux\Domain\DataProvider\SocialMediaDataProvider;
2023
use In2code\Lux\Domain\DataProvider\UtmCampaignDataProvider;
@@ -25,6 +28,7 @@
2528
use In2code\Lux\Domain\Model\News;
2629
use In2code\Lux\Domain\Model\Page;
2730
use In2code\Lux\Domain\Model\Transfer\FilterDto;
31+
use In2code\Lux\Domain\Service\Referrer\SourceHelper;
2832
use In2code\Lux\Exception\ArgumentsException;
2933
use In2code\Lux\Exception\AuthenticationException;
3034
use In2code\Lux\Utility\BackendUtility;
@@ -225,6 +229,55 @@ public function utmCsvAction(FilterDto $filter): ResponseInterface
225229
return $this->csvResponse();
226230
}
227231

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

499+
/**
500+
* @param string $referrerDomain
501+
* @return ResponseInterface
502+
* @throws ArgumentsException
503+
* @throws ExceptionDbal
504+
*/
505+
public function detailSourceAction(string $referrerDomain): ResponseInterface
506+
{
507+
$filter = BackendUtility::getFilterFromSession(
508+
'sources',
509+
$this->getControllerName(),
510+
['searchterm' => $referrerDomain, 'limit' => 100]
511+
);
512+
$this->moduleTemplate->assignMultiple([
513+
'filter' => $filter,
514+
'referrerDomain' => $referrerDomain,
515+
'pagevisits' => $this->pagevisitsRepository->findByReferrerDomain($filter),
516+
'pagevisitsBySourceData' => GeneralUtility::makeInstance(PagevisistsBySourceDataProvider::class, $filter),
517+
]);
518+
519+
$this->addDocumentHeaderForCurrentController();
520+
return $this->defaultRendering();
521+
}
522+
446523
/**
447524
* AJAX action to show a detail view coming from contentAction
448525
*
@@ -475,6 +552,39 @@ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterfa
475552
return $response;
476553
}
477554

555+
/**
556+
* AJAX action to show a detail view coming from sourceAction
557+
*
558+
* @param ServerRequestInterface $request
559+
* @return ResponseInterface
560+
* @noinspection PhpUnused
561+
* @throws ExceptionDbal
562+
* @throws ArgumentsException
563+
*/
564+
public function detailAjaxSource(ServerRequestInterface $request): ResponseInterface
565+
{
566+
$filter = BackendUtility::getFilterFromSession(
567+
'sources',
568+
'Analysis',
569+
['searchterm' => (string)$request->getQueryParams()['referrerDomain'], 'limit' => 10]
570+
);
571+
$standaloneView = ObjectUtility::getStandaloneView();
572+
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
573+
'EXT:lux/Resources/Private/Templates/Analysis/SourcesDetailAjax.html'
574+
));
575+
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
576+
$standaloneView->assignMultiple([
577+
'filter' => $filter,
578+
'pagevisits' => $this->pagevisitsRepository->findByReferrerDomain($filter),
579+
'pagevisitsBySourceData' => GeneralUtility::makeInstance(PagevisistsBySourceDataProvider::class, $filter),
580+
]);
581+
$response = GeneralUtility::makeInstance(JsonResponse::class);
582+
/** @var StreamInterface $stream */
583+
$stream = $response->getBody();
584+
$stream->write(json_encode(['html' => $standaloneView->render()]));
585+
return $response;
586+
}
587+
478588
/**
479589
* AJAX action to show a detail view for news
480590
*
@@ -627,7 +737,7 @@ protected function addDocumentHeaderForCurrentController(): void
627737
if ($this->searchRepository->isTableFilled()) {
628738
$actions[] = 'search';
629739
}
630-
$actions = array_merge($actions, ['utm', 'linkListener']);
740+
$actions = array_merge($actions, ['utm', 'sources', 'linkListener']);
631741
$menuConfiguration = [];
632742
foreach ($actions as $action) {
633743
$menuConfiguration[] = [

Classes/Domain/DataProvider/PageOverview/GotinExternalDataProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use In2code\Lux\Domain\Model\Pagevisit;
88
use In2code\Lux\Domain\Model\Transfer\FilterDto;
99
use In2code\Lux\Domain\Repository\PagevisitRepository;
10-
use In2code\Lux\Domain\Service\Referrer\Readable;
10+
use In2code\Lux\Domain\Service\Referrer\SourceHelper;
1111
use In2code\Lux\Utility\DatabaseUtility;
1212
use In2code\Lux\Utility\FrontendUtility;
1313
use TYPO3\CMS\Core\Site\SiteFinder;
@@ -45,8 +45,8 @@ public function get(): array
4545
{
4646
$result = [];
4747
foreach ($this->getExternalGotinToPagevisit() as $referrer) {
48-
$readable = GeneralUtility::makeInstance(Readable::class, $referrer['referrer']);
49-
$domainName = $readable->getReadableReferrer();
48+
$sourceHelper = GeneralUtility::makeInstance(SourceHelper::class, $referrer['referrer']);
49+
$domainName = $sourceHelper->getReadableReferrer();
5050
if (array_key_exists($domainName, $result)) {
5151
$result[$domainName]++;
5252
} else {
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+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 ReferrerTopDataProvider extends AbstractDataProvider
11+
{
12+
/**
13+
* Set values like:
14+
* [
15+
* 'amounts' => [
16+
* 120,
17+
* 88
18+
* ],
19+
* 'titles' => [
20+
* 'www.foo.com',
21+
* 'www.bar.com',
22+
* ]
23+
* ]
24+
*
25+
* @return void
26+
* @throws ExceptionDbal
27+
*/
28+
public function prepareData(): void
29+
{
30+
/** @var PagevisitRepository $pagevisitRepository */
31+
$pagevisitRepository = GeneralUtility::makeInstance(PagevisitRepository::class);
32+
$titles = $amounts = [];
33+
foreach ($pagevisitRepository->getAmountOfReferrerDomains($this->filter->setLimit(5)) as $source) {
34+
$titles[] = $source['referrer_domain'];
35+
$amounts[] = $source['count'];
36+
}
37+
$this->data = ['amounts' => $amounts, 'titles' => $titles];
38+
}
39+
}

Classes/Domain/Model/Pagevisit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use DateTime;
77
use In2code\Lux\Domain\Repository\NewsvisitRepository;
8-
use In2code\Lux\Domain\Service\Referrer\Readable;
8+
use In2code\Lux\Domain\Service\Referrer\SourceHelper;
99
use In2code\Lux\Domain\Service\SiteService;
1010
use In2code\Lux\Utility\BackendUtility;
1111
use In2code\Lux\Utility\EnvironmentUtility;
@@ -114,8 +114,8 @@ public function getReferrer(): string
114114

115115
public function getReadableReferrer(): string
116116
{
117-
$referrerService = GeneralUtility::makeInstance(Readable::class, $this->getReferrer());
118-
return $referrerService->getReadableReferrer();
117+
$sourceHelper = GeneralUtility::makeInstance(SourceHelper::class, $this->getReferrer());
118+
return $sourceHelper->getReadableReferrer();
119119
}
120120

121121
public function isReferrerSet(): bool

Classes/Domain/Model/Utm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace In2code\Lux\Domain\Model;
55

66
use DateTime;
7-
use In2code\Lux\Domain\Service\Referrer\Readable;
7+
use In2code\Lux\Domain\Service\Referrer\SourceHelper;
88
use TYPO3\CMS\Core\Utility\GeneralUtility;
99
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
1010

@@ -119,8 +119,8 @@ public function getReferrer(): string
119119

120120
public function getReadableReferrer(): string
121121
{
122-
$referrerService = GeneralUtility::makeInstance(Readable::class, $this->getReferrer());
123-
return $referrerService->getReadableReferrer();
122+
$sourceHelper = GeneralUtility::makeInstance(SourceHelper::class, $this->getReferrer());
123+
return $sourceHelper->getReadableReferrer();
124124
}
125125

126126
public function setReferrer(string $referrer): Utm

0 commit comments

Comments
 (0)