Skip to content

Commit

Permalink
[FEATURE] Update of Analysis/LinkClick view
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 23, 2024
1 parent 7dd1eb1 commit 75cc01f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 81 deletions.
21 changes: 10 additions & 11 deletions Classes/Domain/DataProvider/AllLinkclickDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
namespace In2code\Lux\Domain\DataProvider;

use DateTime;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver;
use Doctrine\DBAL\Exception as ExceptionDbal;
use In2code\Lux\Domain\Model\Linkclick;
use In2code\Lux\Domain\Model\Pagevisit;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
Expand Down Expand Up @@ -45,13 +44,12 @@ public function __construct(FilterDto $filter = null)
* 'max-y' => 100 // max value for logarithmic y-axes
* ]
* @return void
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function prepareData(): void
{
$intervals = $this->filter->getIntervals();
$frequency = (string)$intervals['frequency'];
$frequency = $intervals['frequency'];
$pageList = $this->getRelatedPageListToLinkclicks($intervals['intervals']);
foreach ($intervals['intervals'] as $interval) {
$clicks = $this->linkclickRepository->findByTimeFrame(
Expand Down Expand Up @@ -82,8 +80,7 @@ protected function setMaxYValue(): void
* @param DateTime $end
* @param string $pagelist
* @return int
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getAmountOfPagevisitsInTimeframeAndPagelist(
DateTime $start,
Expand All @@ -93,7 +90,8 @@ protected function getAmountOfPagevisitsInTimeframeAndPagelist(
$connection = DatabaseUtility::getConnectionForTable(Pagevisit::TABLE_NAME);
$sql = 'select count(*) from ' . Pagevisit::TABLE_NAME
. ' where crdate >= ' . $start->getTimestamp() . ' and crdate <= ' . $end->getTimestamp()
. ' and deleted=0';
. ' and deleted=0'
. ' and site in ("' . implode('","', $this->filter->getSitesForFilter()) . '")';
if ($pagelist !== '') {
$sql .= ' and page in (' . $pagelist . ')';
}
Expand All @@ -105,8 +103,7 @@ protected function getAmountOfPagevisitsInTimeframeAndPagelist(
*
* @param array $intervals
* @return string
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getRelatedPageListToLinkclicks(array $intervals): string
{
Expand All @@ -117,7 +114,9 @@ protected function getRelatedPageListToLinkclicks(array $intervals): string
$connection = DatabaseUtility::getConnectionForTable(Linkclick::TABLE_NAME);
return (string)$connection->executeQuery(
'select group_concat(distinct page) from ' . Linkclick::TABLE_NAME
. ' where crdate >= ' . $start->getTimestamp() . ' and crdate <= ' . $end->getTimestamp() . ' and deleted=0'
. ' where crdate >= ' . $start->getTimestamp() . ' and crdate <= ' . $end->getTimestamp()
. ' and deleted=0'
. ' and site in ("' . implode('","', $this->filter->getSitesForFilter()) . '")'
)->fetchOne();
}
}
13 changes: 3 additions & 10 deletions Classes/Domain/DataProvider/LinkclickDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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\Model\Linklistener;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
Expand Down Expand Up @@ -48,8 +46,7 @@ public function __construct(FilterDto $filter = null)
* ]
* ]
* @return void
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function prepareData(): void
{
Expand Down Expand Up @@ -123,8 +120,7 @@ public function sortGroupedDataByPerformanceAndLimitResult(array $data, int $lim
* ]
*
* @return array
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function getGroupedData(): array
{
Expand Down Expand Up @@ -180,8 +176,7 @@ public function getGroupedData(): array
* ]
*
* @return array
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getUngroupedData(): array
{
Expand Down Expand Up @@ -211,8 +206,6 @@ protected function getUngroupedData(): array
* @param int $pageUid
* @param int $linklistener
* @return int
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
protected function getPagevisitsFromPageByTagTimeframe(int $pageUid, int $linklistener): int
Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ protected function extendWhereClauseWithFilterDomain(FilterDto $filter, string $
* @param FilterDto $filter
* @param string $table table with crdate (normally the main table)
* @return string
* @throws Exception
*/
protected function extendWhereClauseWithFilterSite(FilterDto $filter, string $table = ''): string
{
Expand Down
18 changes: 4 additions & 14 deletions Classes/Domain/Repository/LinkclickRepository.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 Exception;
use In2code\Lux\Domain\Model\Linkclick;
Expand All @@ -21,7 +19,6 @@ class LinkclickRepository extends AbstractRepository
/**
* @return int
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function findAllAmount(): int
{
Expand All @@ -33,7 +30,6 @@ public function findAllAmount(): int
* @param int $linklistener
* @return int
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function getFirstCreationDateFromLinklistenerIdentifier(int $linklistener): int
{
Expand All @@ -52,7 +48,6 @@ public function getFirstCreationDateFromLinklistenerIdentifier(int $linklistener
* @param int $linklistener
* @return int
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function getLatestCreationDateFromLinklistenerIdentifier(int $linklistener): int
{
Expand Down Expand Up @@ -88,8 +83,7 @@ public function getLatestCreationDateFromLinklistenerIdentifier(int $linklistene
* ]
* @param FilterDto $filter
* @return array
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function getAmountOfLinkclicksGroupedByPageUid(FilterDto $filter): array
{
Expand All @@ -100,6 +94,7 @@ public function getAmountOfLinkclicksGroupedByPageUid(FilterDto $filter): array
. ' where ' . $this->extendWhereClauseWithFilterTime($filter, false, 'lc');
$sql .= $this->extendWhereClauseWithFilterSearchterms($filter, 'll');
$sql .= $this->extendWhereClauseWithFilterCategoryScoring($filter, 'll');
$sql .= $this->extendWhereClauseWithFilterSite($filter, 'lc');
$sql .= ' group by lc.linklistener, lc.page';
return $connection->executeQuery($sql)->fetchAllAssociative();
}
Expand All @@ -120,9 +115,7 @@ public function getAmountOfLinkclicksGroupedByPageUid(FilterDto $filter): array
* ]
* @param int $linklistener
* @return array
* @throws DBALException
* @throws Exception
* @throws ExceptionDbalDriver
*/
public function getAmountOfLinkclicksByLinklistenerGroupedByPageUid(int $linklistener): array
{
Expand All @@ -139,7 +132,6 @@ public function getAmountOfLinkclicksByLinklistenerGroupedByPageUid(int $linklis
* @return int
* @throws ExceptionDbal
* @throws Exception
* @throws ExceptionDbalDriver
*/
public function getAmountOfLinkclicksByPageIdentifierAndTimeframe(int $pageIdentifier, FilterDto $filter): int
{
Expand All @@ -156,7 +148,6 @@ public function getAmountOfLinkclicksByPageIdentifierAndTimeframe(int $pageIdent
* @param int $page
* @return DateTime
* @throws Exception
* @throws ExceptionDbalDriver
*/
public function findLastDateByLinklistenerAndPage(int $linklistener, int $page): DateTime
{
Expand Down Expand Up @@ -193,7 +184,6 @@ public function findByLinklistenerIdentifier(int $linklistenerIdentifier, int $l
* @param int $linklistener
* @return array
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function findRawByLinklistenerIdentifier(int $linklistener): array
{
Expand All @@ -211,8 +201,7 @@ public function findRawByLinklistenerIdentifier(int $linklistener): array
* @param DateTime $end
* @param FilterDto|null $filter
* @return int
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function findByTimeFrame(DateTime $start, DateTime $end, FilterDto $filter = null): int
{
Expand All @@ -223,6 +212,7 @@ public function findByTimeFrame(DateTime $start, DateTime $end, FilterDto $filte
. ' where lc.crdate >= ' . $start->getTimestamp() . ' and lc.crdate <= ' . $end->getTimestamp();
$sql .= $this->extendWhereClauseWithFilterSearchterms($filter, 'll');
$sql .= $this->extendWhereClauseWithFilterCategoryScoring($filter, 'll');
$sql .= $this->extendWhereClauseWithFilterSite($filter, 'lc');
return (int)$connection->executeQuery($sql)->fetchOne();
}
}
60 changes: 36 additions & 24 deletions Classes/Domain/Repository/LinklistenerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,58 @@ class LinklistenerRepository extends AbstractRepository
public function findByFilter(FilterDto $filter): QueryResultInterface
{
$query = $this->createQuery();
$logicalAnd = [$query->greaterThan('uid', 0)];
if ($filter->isSet()) {
$logicalAnd[] = $query->greaterThan('linkclicks.crdate', $filter->getStartTimeForFilter());
$logicalAnd[] = $query->lessThan('linkclicks.crdate', $filter->getEndTimeForFilter());
}
$logicalAnd = $this->extendWithExtendedFilterQuery($query, $logicalAnd, $filter);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, []);
$logicalAnd = $this->extendWithExtendedFilterQuery($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}

/**
* @param FilterDto $filter
* @param QueryInterface $query
* @param array $logicalAnd
* @return array
* @throws InvalidQueryException
*/
protected function extendLogicalAndWithFilterConstraintsForCrdate(
FilterDto $filter,
QueryInterface $query,
array $logicalAnd
): array {
$logicalAnd[] = $query->greaterThan('linkclicks.crdate', $filter->getStartTimeForFilter());
$logicalAnd[] = $query->lessThan('linkclicks.crdate', $filter->getEndTimeForFilter());
return $logicalAnd;
}

/**
* @param FilterDto $filter
* @param QueryInterface $query
* @param array $logicalAnd
* @param FilterDto|null $filter
* @return array
* @throws InvalidQueryException
*/
protected function extendWithExtendedFilterQuery(
FilterDto $filter,
QueryInterface $query,
array $logicalAnd,
FilterDto $filter = null
array $logicalAnd
): array {
if ($filter !== null) {
if ($filter->isSearchtermSet()) {
$logicalOr = [];
foreach ($filter->getSearchterms() as $searchterm) {
if (MathUtility::canBeInterpretedAsInteger($searchterm)) {
$logicalOr[] = $query->equals('uid', $searchterm);
} else {
$logicalOr[] = $query->like('title', '%' . $searchterm . '%');
$logicalOr[] = $query->like('description', '%' . $searchterm . '%');
$logicalOr[] = $query->like('category.title', '%' . $searchterm . '%');
}
if ($filter->isSearchtermSet()) {
$logicalOr = [];
foreach ($filter->getSearchterms() as $searchterm) {
if (MathUtility::canBeInterpretedAsInteger($searchterm)) {
$logicalOr[] = $query->equals('uid', $searchterm);
} else {
$logicalOr[] = $query->like('title', '%' . $searchterm . '%');
$logicalOr[] = $query->like('description', '%' . $searchterm . '%');
$logicalOr[] = $query->like('category.title', '%' . $searchterm . '%');
}
$logicalAnd[] = $query->logicalOr(...$logicalOr);
}
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('category', $filter->getCategoryScoring());
}
$logicalAnd[] = $query->logicalOr(...$logicalOr);
}
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('category', $filter->getCategoryScoring());
}
$logicalAnd[] = $query->in('linkclicks.site', $filter->getSitesForFilter());
return $logicalAnd;
}
}
Loading

0 comments on commit 75cc01f

Please sign in to comment.