Skip to content

Commit

Permalink
[FEATURE] Update of Analysis/News view
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 23, 2024
1 parent 02a3913 commit ba8572b
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 126 deletions.
5 changes: 2 additions & 3 deletions Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
{
Expand Down Expand Up @@ -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[] = [
Expand Down
9 changes: 3 additions & 6 deletions Classes/Domain/DataProvider/DomainNewsDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,8 +26,7 @@ class DomainNewsDataProvider extends AbstractDataProvider
* ]
*
* @return void
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function prepareData(): void
{
Expand All @@ -41,8 +39,7 @@ public function prepareData(): void

/**
* @return array
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getDomains(): array
{
Expand Down
9 changes: 3 additions & 6 deletions Classes/Domain/DataProvider/LanguagesNewsDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +27,7 @@ class LanguagesNewsDataProvider extends AbstractDataProvider
* ]
*
* @return void
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function prepareData(): void
{
Expand All @@ -42,8 +40,7 @@ public function prepareData(): void

/**
* @return array
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getLanguagesFromSystem(): array
{
Expand Down
10 changes: 10 additions & 0 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ' (';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -285,15 +285,15 @@ 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';
}
if (in_array('p', $tables)) {
$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';
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/LinklistenerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -59,7 +59,7 @@ protected function extendWithExtendedFilterQuery(
}
$logicalAnd[] = $query->logicalOr(...$logicalOr);
}
if ($filter->getCategoryScoring() !== null) {
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('category', $filter->getCategoryScoring());
}
}
Expand Down
27 changes: 10 additions & 17 deletions Classes/Domain/Repository/NewsvisitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +29,6 @@ class NewsvisitRepository extends AbstractRepository
*
* @param FilterDto $filter
* @return array
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function findCombinedByNewsIdentifier(FilterDto $filter): array
Expand Down Expand Up @@ -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
Expand All @@ -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';
Expand All @@ -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
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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';
Expand All @@ -195,7 +188,6 @@ public function getAllLanguages(FilterDto $filter): array

/**
* @return bool
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function isTableFilled(): bool
Expand All @@ -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)) {
Expand All @@ -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;
}
Expand Down
37 changes: 0 additions & 37 deletions Classes/Domain/Repository/PagevisitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions Classes/Domain/Repository/SearchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Loading

0 comments on commit ba8572b

Please sign in to comment.