Skip to content

Commit

Permalink
[FEATURE] Update of Analysis/Content/Detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 24, 2024
1 parent 7c68aa6 commit 7351d46
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ protected function setFilter(int $timePeriod = FilterDto::PERIOD_DEFAULT): void

protected function getFilterFromSessionForAjaxRequests(string $action, string $searchterm = ''): FilterDto
{
// Todo: Remove
die(__CLASS__ . ':' . __LINE__);
$filterValues = BackendUtility::getSessionValue('filter', $action, $this->getControllerName());
$filter = ObjectUtility::getFilterDto();
if (!empty($searchterm)) {
Expand Down
48 changes: 33 additions & 15 deletions Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
use In2code\Lux\Domain\Model\News;
use In2code\Lux\Domain\Model\Page;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Exception\ArgumentsException;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\FileUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -321,12 +321,18 @@ public function deleteLinkListenerAction(LinkListener $linkListener): ResponseIn
* @return ResponseInterface
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
* @throws ArgumentsException
*/
public function detailPageAction(Page $page): ResponseInterface
{
$filter = ObjectUtility::getFilterDto()->setSearchterm((string)$page->getUid());
$filter = BackendUtility::getFilterFromSession(
'content',
$this->getControllerName(),
['searchterm' => (string)$page->getUid(), 'limit' => 100]
);
$this->view->assignMultiple([
'pagevisits' => $this->pagevisitsRepository->findByPage($page, 100),
'filter' => $filter,
'pagevisits' => $this->pagevisitsRepository->findByFilter($filter),
'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class, $filter),
]);

Expand Down Expand Up @@ -362,9 +368,14 @@ public function detailNewsAction(News $news): ResponseInterface
*/
public function detailDownloadAction(string $href): ResponseInterface
{
$filter = ObjectUtility::getFilterDto()->setSearchterm(FileUtility::getFilenameFromPathAndFilename($href));
$filter = BackendUtility::getFilterFromSession(
'content',
$this->getControllerName(),
['href' => $href, 'limit' => 100]
);
$this->view->assignMultiple([
'downloads' => $this->downloadRepository->findByHref($href, 100),
'filter' => $filter,
'downloads' => $this->downloadRepository->findByFilter($filter),
'numberOfDownloadsData' => GeneralUtility::makeInstance(DownloadsDataProvider::class, $filter),
]);

Expand Down Expand Up @@ -410,25 +421,28 @@ public function detailSearchAction(string $searchterm): ResponseInterface
}

/**
* AJAX action to show a detail view
* AJAX action to show a detail view coming from contentAction
*
* @param ServerRequestInterface $request
* @return ResponseInterface
* @noinspection PhpUnused
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
* @throws ArgumentsException
*/
public function detailAjaxPage(ServerRequestInterface $request): ResponseInterface
{
$filter = $this->getFilterFromSessionForAjaxRequests('content', (string)$request->getQueryParams()['page']);
/** @var Page $page */
$page = $this->pageRepository->findByIdentifier((int)$request->getQueryParams()['page']);
$filter = BackendUtility::getFilterFromSession(
'content',
'Analysis',
['searchterm' => (string)$request->getQueryParams()['page'], 'limit' => 10]
);
$standaloneView = ObjectUtility::getStandaloneView();
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:lux/Resources/Private/Templates/Analysis/ContentDetailPageAjax.html'
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$standaloneView->assignMultiple([
'pagevisits' => $page !== null ? $this->pagevisitsRepository->findByPage($page, 10) : null,
'pagevisits' => $this->pagevisitsRepository->findByFilter($filter),
'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class, $filter),
]);
$response = GeneralUtility::makeInstance(JsonResponse::class);
Expand All @@ -444,7 +458,7 @@ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterfa
* @param ServerRequestInterface $request
* @return ResponseInterface
* @noinspection PhpUnused
* @throws ExceptionDbalDriver
* @throws ExceptionDbal
*/
public function detailNewsAjaxPage(ServerRequestInterface $request): ResponseInterface
{
Expand Down Expand Up @@ -521,17 +535,21 @@ public function detailSearchAjaxPage(ServerRequestInterface $request): ResponseI
*/
public function detailAjaxDownload(ServerRequestInterface $request): ResponseInterface
{
$filter = $this->getFilterFromSessionForAjaxRequests(
$filter = BackendUtility::getFilterFromSession(
'content',
FileUtility::getFilenameFromPathAndFilename((string)$request->getQueryParams()['download'])
'Analysis',
[
'href' => (string)$request->getQueryParams()['download'],
'limit' => 10,
]
);
$standaloneView = ObjectUtility::getStandaloneView();
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:lux/Resources/Private/Templates/Analysis/ContentDetailDownloadAjax.html'
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$standaloneView->assignMultiple([
'downloads' => $this->downloadRepository->findByHref((string)$request->getQueryParams()['download'], 10),
'downloads' => $this->downloadRepository->findByFilter($filter),
'numberOfDownloadsData' => GeneralUtility::makeInstance(DownloadsDataProvider::class, $filter),
]);
$response = GeneralUtility::makeInstance(JsonResponse::class);
Expand Down
27 changes: 27 additions & 0 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FilterDto
const IDENTIFIED_IDENTIFIED = 1;

protected string $searchterm = '';
protected string $href = '';
protected string $pid = '';

/**
Expand Down Expand Up @@ -121,6 +122,32 @@ public function setSearchterm(string $searchterm): self
return $this;
}

public function getHref(): string
{
return StringUtility::sanitizeString($this->href);
}

public function isHrefSet(): bool
{
return $this->href !== '';
}

/**
* Without sanitize function
*
* @return string
*/
public function getHrefRaw(): string
{
return $this->href;
}

public function setHref(string $href): self
{
$this->href = $href;
return $this;
}

public function getPid(): string
{
return StringUtility::sanitizeString($this->pid);
Expand Down
39 changes: 19 additions & 20 deletions Classes/Domain/Repository/DownloadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
class DownloadRepository extends AbstractRepository
{
/**
* @param string $href
* @param int $limit
* @param FilterDto $filter
* @return QueryResultInterface
* @throws InvalidQueryException
*/
public function findByHref(string $href, int $limit = 100): QueryResultInterface
public function findByFilter(FilterDto $filter): QueryResultInterface
{
$query = $this->createQuery();
$logicalAnd = [
$query->equals('href', $href),
$query->greaterThan('visitor.uid', 0),
];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendWithExtendedFilterQuery($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
$query->setLimit($limit);
$query->setLimit($filter->getLimit());
return $query->execute();
}

Expand All @@ -49,7 +49,7 @@ public function findCombinedByHref(FilterDto $filter): array
{
$query = $this->createQuery();
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, []);
$logicalAnd = $this->extendWithExtendedFilterQuery($query, $logicalAnd, $filter);
$logicalAnd = $this->extendWithExtendedFilterQuery($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
$assets = $query->execute(true);

Expand Down Expand Up @@ -100,7 +100,7 @@ public function getNumberOfDownloadsInTimeFrame(DateTime $start, DateTime $end,
$query->greaterThanOrEqual('crdate', $start->format('U')),
$query->lessThanOrEqual('crdate', $end->format('U')),
];
$logicalAnd = $this->extendWithExtendedFilterQuery($query, $logicalAnd, $filter);
$logicalAnd = $this->extendWithExtendedFilterQuery($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute()->count();
}
Expand Down Expand Up @@ -139,11 +139,13 @@ public function findAmountByPageIdentifierAndTimeFrame(int $pageIdentifier, Filt
* @throws InvalidQueryException
*/
protected function extendWithExtendedFilterQuery(
FilterDto $filter,
QueryInterface $query,
array $logicalAnd,
FilterDto $filter = null
array $logicalAnd
): array {
if ($filter !== null) {
if ($filter->isHrefSet()) {
$logicalAnd[] = $query->equals('href', $filter->getHrefRaw());
} else {
if ($filter->isSearchtermSet()) {
$logicalOr = [];
foreach ($filter->getSearchterms() as $searchterm) {
Expand All @@ -155,17 +157,14 @@ protected function extendWithExtendedFilterQuery(
}
$logicalAnd[] = $query->logicalOr(...$logicalOr);
}
if ($filter->isScoringSet()) {
$logicalAnd[] = $query->greaterThanOrEqual('visitor.scoring', $filter->getScoring());
}
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('visitor.categoryscorings.category', $filter->getCategoryScoring());
}
if ($filter->isDomainSet()) {
$logicalAnd[] = $query->equals('domain', $filter->getDomain());
}
$logicalAnd[] = $query->in('site', $filter->getSitesForFilter());
}
if ($filter->isScoringSet()) {
$logicalAnd[] = $query->greaterThanOrEqual('visitor.scoring', $filter->getScoring());
}
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('visitor.categoryscorings.category', $filter->getCategoryScoring());
}
$logicalAnd[] = $query->in('site', $filter->getSitesForFilter());
return $logicalAnd;
}
}
29 changes: 20 additions & 9 deletions Classes/Domain/Repository/PagevisitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
use In2code\Lux\Domain\Model\Visitor;
use In2code\Lux\Domain\Service\Referrer\Readable;
use In2code\Lux\Domain\Service\Referrer\SocialMedia;
use In2code\Lux\Exception\ArgumentsException;
use In2code\Lux\Utility\ArrayUtility;
use In2code\Lux\Utility\DatabaseUtility;
use In2code\Lux\Utility\ExtensionUtility;
use In2code\Lux\Utility\FrontendUtility;
use In2code\Luxenterprise\Domain\Repository\ShortenerRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
Expand Down Expand Up @@ -57,7 +59,6 @@ public function findCombinedByPageIdentifier(FilterDto $filter, int $limit = 100
. ' where 1 '
. $this->extendWhereClauseWithFilterSearchterms($filter, 'p')
. $this->extendWhereClauseWithFilterTime($filter, true, 'pv')
. $this->extendWhereClauseWithFilterDomain($filter, 'pv')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
. $this->extendWhereClauseWithFilterScoring($filter, 'v')
. $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs')
Expand Down Expand Up @@ -189,19 +190,29 @@ public function findLastByVisitorAndTime(Visitor $visitor, DateTime $time): ?Pag
}

/**
* Get a result with pagevisits grouped by visitor
*
* @param Page $page
* @param int $limit
* @param FilterDto $filter
* @return array
* @throws ArgumentsException
* @throws ExceptionDbal
*/
public function findByPage(Page $page, int $limit = 100): array
public function findByFilter(FilterDto $filter): array
{
if (MathUtility::canBeInterpretedAsInteger($filter->getSearchterm()) === false) {
throw new ArgumentsException('Filter searchterm must keep a page identifier here', 1708775656);
}

$sql = 'select pv.uid,pv.visitor,pv.crdate,pv.page from ' . Pagevisit::TABLE_NAME . ' pv'
. ' left join ' . Visitor::TABLE_NAME . ' v on v.uid = pv.visitor'
. ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor'
. ' where pv.page=' . (int)$filter->getSearchterm() . ' '
. $this->extendWhereClauseWithFilterTime($filter, true, 'pv')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
. $this->extendWhereClauseWithFilterScoring($filter, 'v')
. $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs')
. ' group by pv.visitor,pv.uid,pv.crdate,pv.page'
. ' order by pv.crdate desc'
. ' limit ' . ($filter->isLimitSet() ? $filter->getLimit() : 750);
$connection = DatabaseUtility::getConnectionForTable(Pagevisit::TABLE_NAME);
$sql = 'select uid,visitor,crdate from ' . Pagevisit::TABLE_NAME
. ' where page=' . $page->getUid()
. ' group by visitor,uid,crdate order by crdate desc limit ' . $limit;
$pagevisitIdentifiers = $connection->executeQuery($sql)->fetchFirstColumn();
return $this->convertIdentifiersToObjects($pagevisitIdentifiers, Pagevisit::TABLE_NAME);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Utility/StringUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public static function cleanString(string $string, bool $toLower = false, string
*
* Example replacements:
* 'Réne Nüßer' => 'Réne Nüßer',
* 'Not this/\+=*#?$%&!;"\'´`<>{}[]()--nono' => 'Not thisnono',
* 'Not this\=#?$&!;"\'´`<>{}[]()--nono' => 'Not thisnono',
* 'But [email protected]_is,ok' => 'But [email protected]_is,ok',
*
* @param string $string
* @return string
*/
public static function sanitizeString(string $string): string
{
return preg_replace('/[\/\\#?$%&!=\'"`´<>{}\[\]()]|--/', '', $string);
return preg_replace('/[\\#?$&!=\'"`´<>{}\[\]()]|--/', '', $string);
}

public static function getRandomString(int $length = 32, bool $lowerAndUpperCase = true): string
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,10 @@
<source>more then 2K employees</source>
<target state="translated">mehr als 2K Beschäftigte</target>
</trans-unit>
<trans-unit id="dictionary.pageidentifier">
<source>Page Identifier (PID)</source>
<target state="translated">Seitennummer (PID)</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,9 @@
<trans-unit id="dictionary.size_class.10">
<source>more then 2K employees</source>
</trans-unit>
<trans-unit id="dictionary.pageidentifier">
<source>Page Identifier (PID)</source>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 7351d46

Please sign in to comment.