From ba8572b6957d71417346fefb5f7a639d93cd6c52 Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Fri, 23 Feb 2024 22:14:02 +0100 Subject: [PATCH] [FEATURE] Update of Analysis/News view --- Classes/Controller/AnalysisController.php | 5 +- .../DataProvider/DomainNewsDataProvider.php | 9 +-- .../LanguagesNewsDataProvider.php | 9 +-- Classes/Domain/Model/Transfer/FilterDto.php | 10 +++ .../Domain/Repository/AbstractRepository.php | 16 ++-- .../Repository/LinklistenerRepository.php | 4 +- .../Domain/Repository/NewsvisitRepository.php | 27 +++---- .../Domain/Repository/PagevisitRepository.php | 37 ---------- .../Domain/Repository/SearchRepository.php | 8 +- Classes/Domain/Repository/UtmRepository.php | 8 +- .../Domain/Repository/VisitorRepository.php | 4 +- .../Partials/Filter/Analysis/News.html | 74 +++++++++---------- 12 files changed, 85 insertions(+), 126 deletions(-) diff --git a/Classes/Controller/AnalysisController.php b/Classes/Controller/AnalysisController.php index 4698cabe..f5f9293e 100644 --- a/Classes/Controller/AnalysisController.php +++ b/Classes/Controller/AnalysisController.php @@ -155,7 +155,6 @@ public function newsAction(FilterDto $filter, string $export = ''): ResponseInte 'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter), 'languageData' => GeneralUtility::makeInstance(LanguagesNewsDataProvider::class, $filter), 'domainData' => GeneralUtility::makeInstance(DomainNewsDataProvider::class, $filter), - 'domains' => $this->newsvisitRepository->getAllDomains($filter), ]); $this->addDocumentHeaderForCurrentController(); @@ -166,7 +165,6 @@ public function newsAction(FilterDto $filter, string $export = ''): ResponseInte * @param FilterDto $filter * @return ResponseInterface * @throws ExceptionDbal - * @throws ExceptionDbalDriver */ public function newsCsvAction(FilterDto $filter): ResponseInterface { @@ -574,13 +572,14 @@ public function detailAjaxLinklistener(ServerRequestInterface $request): Respons */ protected function addDocumentHeaderForCurrentController(): void { - $actions = ['dashboard', 'content', 'utm', 'linkListener']; + $actions = ['dashboard', 'content']; if ($this->newsvisitRepository->isTableFilled()) { $actions[] = 'news'; } if ($this->searchRepository->isTableFilled()) { $actions[] = 'search'; } + $actions = array_merge($actions, ['utm', 'linkListener']); $menuConfiguration = []; foreach ($actions as $action) { $menuConfiguration[] = [ diff --git a/Classes/Domain/DataProvider/DomainNewsDataProvider.php b/Classes/Domain/DataProvider/DomainNewsDataProvider.php index 93b2f08b..47b61fca 100644 --- a/Classes/Domain/DataProvider/DomainNewsDataProvider.php +++ b/Classes/Domain/DataProvider/DomainNewsDataProvider.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace In2code\Lux\Domain\DataProvider; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; +use Doctrine\DBAL\Exception as ExceptionDbal; use In2code\Lux\Domain\Repository\NewsvisitRepository; use In2code\Lux\Utility\LocalizationUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -27,8 +26,7 @@ class DomainNewsDataProvider extends AbstractDataProvider * ] * * @return void - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ public function prepareData(): void { @@ -41,8 +39,7 @@ public function prepareData(): void /** * @return array - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ protected function getDomains(): array { diff --git a/Classes/Domain/DataProvider/LanguagesNewsDataProvider.php b/Classes/Domain/DataProvider/LanguagesNewsDataProvider.php index 770f24aa..dc192c33 100644 --- a/Classes/Domain/DataProvider/LanguagesNewsDataProvider.php +++ b/Classes/Domain/DataProvider/LanguagesNewsDataProvider.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace In2code\Lux\Domain\DataProvider; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; +use Doctrine\DBAL\Exception as ExceptionDbal; use In2code\Lux\Domain\Repository\LanguageRepository; use In2code\Lux\Domain\Repository\NewsvisitRepository; use In2code\Lux\Utility\LocalizationUtility; @@ -28,8 +27,7 @@ class LanguagesNewsDataProvider extends AbstractDataProvider * ] * * @return void - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ public function prepareData(): void { @@ -42,8 +40,7 @@ public function prepareData(): void /** * @return array - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ protected function getLanguagesFromSystem(): array { diff --git a/Classes/Domain/Model/Transfer/FilterDto.php b/Classes/Domain/Model/Transfer/FilterDto.php index 17d5db1b..1087a6b0 100644 --- a/Classes/Domain/Model/Transfer/FilterDto.php +++ b/Classes/Domain/Model/Transfer/FilterDto.php @@ -442,6 +442,11 @@ public function getVisitor(): ?Visitor return $this->visitor; } + public function isVisitorSet(): bool + { + return $this->getVisitor() !== null; + } + public function setVisitor(?Visitor $visitor): self { $this->visitor = $visitor; @@ -453,6 +458,11 @@ public function getCompany(): ?Company return $this->company; } + public function isCompanySet(): bool + { + return $this->getCompany() !== null; + } + public function setCompany(?Company $company): self { $this->company = $company; diff --git a/Classes/Domain/Repository/AbstractRepository.php b/Classes/Domain/Repository/AbstractRepository.php index 2addc2b2..88ffd8cc 100644 --- a/Classes/Domain/Repository/AbstractRepository.php +++ b/Classes/Domain/Repository/AbstractRepository.php @@ -102,7 +102,7 @@ protected function extendWhereClauseWithFilterSearchterms( string $concatenation = 'and' ): string { $sql = ''; - if ($filter->getSearchterms() !== []) { + if ($filter->isSearchtermSet()) { foreach ($filter->getSearchterms() as $searchterm) { if ($sql === '') { $sql .= ' ' . $concatenation . ' ('; @@ -162,7 +162,7 @@ protected function extendWhereClauseWithFilterTime( protected function extendWhereClauseWithFilterDomain(FilterDto $filter, string $table = ''): string { $sql = ''; - if ($filter->getDomain() !== '') { + if ($filter->isDomainSet()) { $field = 'domain'; if ($table !== '') { $field = $table . '.' . $field; @@ -201,7 +201,7 @@ protected function extendWhereClauseWithFilterSite(FilterDto $filter, string $ta protected function extendWhereClauseWithFilterScoring(FilterDto $filter, string $table = ''): string { $sql = ''; - if ($filter->getScoring() > 0) { + if ($filter->isScoringSet()) { $field = 'scoring'; if ($table !== '') { $field = $table . '.' . $field; @@ -229,10 +229,10 @@ protected function extendWhereClauseWithFilterVisitor( if ($table !== '') { $field = $table . '.' . $field; } - if ($filter->getVisitor() !== null) { + if ($filter->isVisitorSet()) { $sql = ' and ' . $field . ' = ' . $filter->getVisitor()->getUid(); } - if ($filter->getCompany() !== null) { + if ($filter->isCompanySet()) { $sql = ''; foreach ($filter->getCompany()->getVisitors() as $visitor) { if ($visitor !== null) { @@ -260,7 +260,7 @@ protected function extendWhereClauseWithFilterVisitor( protected function extendWhereClauseWithFilterCategoryScoring(FilterDto $filter, string $table = ''): string { $sql = ''; - if ($filter->getCategoryScoring() !== null) { + if ($filter->isCategoryScoringSet()) { $field = 'category'; if ($table !== '') { $field = $table . '.' . $field; @@ -285,7 +285,7 @@ protected function extendFromClauseWithJoinByFilter( if (in_array('v', $tables)) { $sql .= ' left join ' . Visitor::TABLE_NAME . ' v on v.uid = pv.visitor'; } - if ($filter->getSearchterm() !== '' || $filter->getDomain() !== '') { + if ($filter->isSearchtermSet() || $filter->isDomainSet()) { if (in_array('pv', $tables)) { $sql .= ' left join ' . Pagevisit::TABLE_NAME . ' pv on v.uid = pv.visitor'; } @@ -293,7 +293,7 @@ protected function extendFromClauseWithJoinByFilter( $sql .= ' left join ' . Page::TABLE_NAME . ' p on p.uid = pv.page'; } } - if ($filter->getCategoryScoring() !== null) { + if ($filter->isCategoryScoringSet()) { if (in_array('cs', $tables)) { $sql .= ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor'; } diff --git a/Classes/Domain/Repository/LinklistenerRepository.php b/Classes/Domain/Repository/LinklistenerRepository.php index f5fcff1a..c51d00a1 100644 --- a/Classes/Domain/Repository/LinklistenerRepository.php +++ b/Classes/Domain/Repository/LinklistenerRepository.php @@ -46,7 +46,7 @@ protected function extendWithExtendedFilterQuery( FilterDto $filter = null ): array { if ($filter !== null) { - if ($filter->getSearchterm() !== '') { + if ($filter->isSearchtermSet()) { $logicalOr = []; foreach ($filter->getSearchterms() as $searchterm) { if (MathUtility::canBeInterpretedAsInteger($searchterm)) { @@ -59,7 +59,7 @@ protected function extendWithExtendedFilterQuery( } $logicalAnd[] = $query->logicalOr(...$logicalOr); } - if ($filter->getCategoryScoring() !== null) { + if ($filter->isCategoryScoringSet()) { $logicalAnd[] = $query->equals('category', $filter->getCategoryScoring()); } } diff --git a/Classes/Domain/Repository/NewsvisitRepository.php b/Classes/Domain/Repository/NewsvisitRepository.php index 9e3d2ea8..120b62e6 100644 --- a/Classes/Domain/Repository/NewsvisitRepository.php +++ b/Classes/Domain/Repository/NewsvisitRepository.php @@ -4,8 +4,6 @@ namespace In2code\Lux\Domain\Repository; use DateTime; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; use Doctrine\DBAL\Exception as ExceptionDbal; use In2code\Lux\Domain\Model\Categoryscoring; use In2code\Lux\Domain\Model\News; @@ -31,7 +29,6 @@ class NewsvisitRepository extends AbstractRepository * * @param FilterDto $filter * @return array - * @throws ExceptionDbalDriver * @throws ExceptionDbal */ public function findCombinedByNewsIdentifier(FilterDto $filter): array @@ -96,7 +93,6 @@ public function getNumberOfVisitorsInTimeFrame(DateTime $start, DateTime $end, F /** * @param FilterDto $filter * @return array - * @throws ExceptionDbalDriver * @throws ExceptionDbal */ public function getDomainsWithAmountOfVisits(FilterDto $filter): array @@ -108,7 +104,7 @@ public function getDomainsWithAmountOfVisits(FilterDto $filter): array . ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor' . ' where ' . $this->extendWhereClauseWithFilterTime($filter, false, 'nv') - . $this->extendWhereClauseWithFilterDomain($filter, 'pv') + . $this->extendWhereClauseWithFilterSite($filter, 'pv') . $this->extendWhereClauseWithFilterScoring($filter, 'v') . $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs') . ' group by domain order by count desc'; @@ -121,8 +117,7 @@ public function getDomainsWithAmountOfVisits(FilterDto $filter): array * @param News $news * @param int $limit * @return array - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ public function findByNews(News $news, int $limit = 100): array { @@ -153,8 +148,7 @@ public function findByPagevisit(Pagevisit $pagevisit): ?Newsvisit * * @param FilterDto $filter * @return array - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ public function getAllDomains(FilterDto $filter): array { @@ -174,8 +168,7 @@ public function getAllDomains(FilterDto $filter): array /** * @param FilterDto $filter * @return array - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws ExceptionDbal */ public function getAllLanguages(FilterDto $filter): array { @@ -186,7 +179,7 @@ public function getAllLanguages(FilterDto $filter): array . ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor' . ' where ' . $this->extendWhereClauseWithFilterTime($filter, false, 'nv') - . $this->extendWhereClauseWithFilterDomain($filter, 'pv') + . $this->extendWhereClauseWithFilterSite($filter, 'pv') . $this->extendWhereClauseWithFilterScoring($filter, 'v') . $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs') . ' group by nv.language order by count desc'; @@ -195,7 +188,6 @@ public function getAllLanguages(FilterDto $filter): array /** * @return bool - * @throws ExceptionDbalDriver * @throws ExceptionDbal */ public function isTableFilled(): bool @@ -221,7 +213,7 @@ protected function extendWithExtendedFilterQuery( FilterDto $filter = null ): array { if ($filter !== null) { - if ($filter->getSearchterm() !== '') { + if ($filter->isSearchtermSet()) { $logicalOr = []; foreach ($filter->getSearchterms() as $searchterm) { if (MathUtility::canBeInterpretedAsInteger($searchterm)) { @@ -232,15 +224,16 @@ protected function extendWithExtendedFilterQuery( } $logicalAnd[] = $query->logicalOr(...$logicalOr); } - if ($filter->getScoring() > 0) { + if ($filter->isScoringSet()) { $logicalAnd[] = $query->greaterThanOrEqual('visitor.scoring', $filter->getScoring()); } - if ($filter->getCategoryScoring() !== null) { + if ($filter->isCategoryScoringSet()) { $logicalAnd[] = $query->equals('visitor.categoryscorings.category', $filter->getCategoryScoring()); } - if ($filter->getDomain() !== '') { + if ($filter->isDomainSet()) { $logicalAnd[] = $query->equals('pagevisit.domain', $filter->getDomain()); } + $logicalAnd[] = $query->in('pagevisit.site', $filter->getSitesForFilter()); } return $logicalAnd; } diff --git a/Classes/Domain/Repository/PagevisitRepository.php b/Classes/Domain/Repository/PagevisitRepository.php index 3910f977..29a55798 100644 --- a/Classes/Domain/Repository/PagevisitRepository.php +++ b/Classes/Domain/Repository/PagevisitRepository.php @@ -493,41 +493,4 @@ public function compareAmountPerPage(int $pageIdentifier, FilterDto $filter1, Fi $amount2 = $this->findAmountPerPage($pageIdentifier, $filter2); return $amount1 - $amount2; } - - /** - * @param QueryInterface $query - * @param array $logicalAnd - * @param FilterDto|null $filter - * @return array - * @throws InvalidQueryException - */ - protected function extendWithExtendedFilterQuery( - QueryInterface $query, - array $logicalAnd, - FilterDto $filter = null - ): array { - if ($filter !== null) { - if ($filter->getSearchterm() !== '') { - $logicalOr = []; - foreach ($filter->getSearchterms() as $searchterm) { - if (MathUtility::canBeInterpretedAsInteger($searchterm)) { - $logicalOr[] = $query->equals('page.uid', (int)$searchterm); - } else { - $logicalOr[] = $query->like('page.title', '%' . $searchterm . '%'); - } - } - $logicalAnd[] = $query->logicalOr(...$logicalOr); - } - if ($filter->getScoring() > 0) { - $logicalAnd[] = $query->greaterThanOrEqual('visitor.scoring', $filter->getScoring()); - } - if ($filter->getCategoryScoring() !== null) { - $logicalAnd[] = $query->equals('visitor.categoryscorings.category', $filter->getCategoryScoring()); - } - if ($filter->getDomain() !== '') { - $logicalAnd[] = $query->equals('domain', $filter->getDomain()); - } - } - return $logicalAnd; - } } diff --git a/Classes/Domain/Repository/SearchRepository.php b/Classes/Domain/Repository/SearchRepository.php index 953f6a2c..721d14af 100644 --- a/Classes/Domain/Repository/SearchRepository.php +++ b/Classes/Domain/Repository/SearchRepository.php @@ -107,20 +107,20 @@ protected function extendWithExtendedFilterQuery( FilterDto $filter = null ): array { if ($filter !== null) { - if ($filter->getSearchterm() !== '') { + if ($filter->isSearchtermSet()) { $logicalOr = []; foreach ($filter->getSearchterms() as $searchterm) { $logicalOr[] = $query->like('searchterm', '%' . $searchterm . '%'); } $logicalAnd[] = $query->logicalOr(...$logicalOr); } - if ($filter->getScoring() > 0) { + if ($filter->isScoringSet()) { $logicalAnd[] = $query->greaterThanOrEqual('visitor.scoring', $filter->getScoring()); } - if ($filter->getCategoryScoring() !== null) { + if ($filter->isCategoryScoringSet()) { $logicalAnd[] = $query->equals('visitor.categoryscorings.category', $filter->getCategoryScoring()); } - if ($filter->getDomain() !== '') { + if ($filter->isDomainSet()) { $logicalAnd[] = $query->equals('pagevisit.domain', $filter->getDomain()); } } diff --git a/Classes/Domain/Repository/UtmRepository.php b/Classes/Domain/Repository/UtmRepository.php index e857dfd1..4f3fdd1f 100644 --- a/Classes/Domain/Repository/UtmRepository.php +++ b/Classes/Domain/Repository/UtmRepository.php @@ -197,7 +197,7 @@ protected function extendWithExtendedFilterQuery( FilterDto $filter = null ): array { if ($filter !== null) { - if ($filter->getSearchterm() !== '') { + if ($filter->isSearchtermSet()) { $logicalOr = []; foreach ($filter->getSearchterms() as $searchterm) { $logicalOr[] = $query->like('utmSource', '%' . $searchterm . '%'); @@ -209,13 +209,13 @@ protected function extendWithExtendedFilterQuery( } $logicalAnd[] = $query->logicalOr(...$logicalOr); } - if ($filter->getUtmCampaign() !== '') { + if ($filter->isUtmCampaignSet()) { $logicalAnd[] = $query->like('utmCampaign', '%' . $filter->getUtmCampaign() . '%'); } - if ($filter->getUtmMedium() !== '') { + if ($filter->isUtmMediumSet()) { $logicalAnd[] = $query->like('utmMedium', '%' . $filter->getUtmMedium() . '%'); } - if ($filter->getUtmSource() !== '') { + if ($filter->isUtmSourceSet()) { $logicalAnd[] = $query->like('utmSource', '%' . $filter->getUtmSource() . '%'); } } diff --git a/Classes/Domain/Repository/VisitorRepository.php b/Classes/Domain/Repository/VisitorRepository.php index 0307eadb..343b8233 100644 --- a/Classes/Domain/Repository/VisitorRepository.php +++ b/Classes/Domain/Repository/VisitorRepository.php @@ -70,8 +70,8 @@ public function findOneAndAlsoBlacklistedByFingerprint(string $identificator, in */ public function findAllWithIdentifiedFirst(FilterDto $filter, int $limit = 750): array { - // Search for calculated hash - if ($filter->getSearchterm() !== '' && StringUtility::isShortMd5($filter->getSearchterm())) { + // Search for single visitor by calculated hash + if ($filter->isSearchtermSet() && StringUtility::isShortMd5($filter->getSearchterm())) { $visitor = $this->findByHash($filter->getSearchterm()); if ($visitor !== null) { return [$visitor]; diff --git a/Resources/Private/Partials/Filter/Analysis/News.html b/Resources/Private/Partials/Filter/Analysis/News.html index baa32f8c..c7ec938a 100644 --- a/Resources/Private/Partials/Filter/Analysis/News.html +++ b/Resources/Private/Partials/Filter/Analysis/News.html @@ -10,41 +10,45 @@
+ type="text" + property="searchterm" + id="searchterm" + class="form-control" + placeholder="{f:translate(key:'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.list.filter.searchtermpagefile')}" />
- -
-
Scoring
+
Zeit
-
@@ -62,7 +66,19 @@
-
Category
+
Scoring
+ +
+ + +
- - -
- - - Domain - - - {domain} - - - -
-