Skip to content

Commit

Permalink
[FEATURE] Update of Analysis/Search/Detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 24, 2024
1 parent 75cc01f commit 7c68aa6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 63 deletions.
10 changes: 5 additions & 5 deletions Classes/Backend/Units/AbstractUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use In2code\Lux\Utility\ObjectUtility;
use In2code\Lux\Utility\StringUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Property\PropertyMapper;
use TYPO3\CMS\Fluid\View\StandaloneView;

abstract class AbstractUnit
Expand Down Expand Up @@ -71,10 +70,11 @@ protected function initializeFilter(): void
{
$filter = ObjectUtility::getFilterDto();
if ($this->filterClass !== '' && $this->filterFunction !== '') {
$filterArray = BackendUtility::getSessionValue('filter', $this->filterFunction, $this->filterClass);
$filterArray = array_merge(['timePeriod' => FilterDto::PERIOD_LAST3MONTH], $filterArray);
$propertyMapper = GeneralUtility::makeInstance(PropertyMapper::class);
$filter = $propertyMapper->convert($filterArray, FilterDto::class);
$filter = BackendUtility::getFilterFromSession(
$this->filterFunction,
$this->filterClass,
['timePeriod' => FilterDto::PERIOD_LAST3MONTH]
);
}
$this->filter = $filter;
}
Expand Down
11 changes: 1 addition & 10 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,12 @@ protected function setFilter(int $timePeriod = FilterDto::PERIOD_DEFAULT): void

// Save to session
if ($this->request->hasArgument('filter') === false) {
$filter = BackendUtility::getSessionValue('filter', $this->getActionName(), $this->getControllerName());
$filter = array_merge(['timePeriod' => $timePeriod], $filter);
$filter = BackendUtility::getFilterArrayFromSession($this->getActionName(), $this->getControllerName());
} else {
$filter = (array)$this->request->getArgument('filter');
BackendUtility::saveValueToSession('filter', $this->getActionName(), $this->getControllerName(), $filter);
}

if (array_key_exists('categoryScoring', $filter)
&& (is_array($filter['categoryScoring']) || $filter['categoryScoring'] === '')) {
$filter['categoryScoring'] = 0;
}
if (array_key_exists('branchCode', $filter)
&& (is_array($filter['branchCode']) || $filter['branchCode'] === '')) {
$filter['branchCode'] = 0;
}
if (isset($filter['identified']) && $filter['identified'] === '') {
$filter['identified'] = FilterDto::IDENTIFIED_ALL;
}
Expand Down
12 changes: 8 additions & 4 deletions Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use In2code\Lux\Domain\Model\News;
use In2code\Lux\Domain\Model\Page;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\FileUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
Expand Down Expand Up @@ -401,7 +402,7 @@ public function detailSearchAction(string $searchterm): ResponseInterface
$this->view->assignMultiple([
'searchterm' => $searchterm,
'searchData' => GeneralUtility::makeInstance(SearchDataProvider::class, $filter),
'searches' => $this->searchRepository->findBySearchterm(urldecode($searchterm)),
'searches' => $this->searchRepository->findBySearchterm($filter),
]);

$this->addDocumentHeaderForCurrentController();
Expand Down Expand Up @@ -494,10 +495,13 @@ public function detailSearchAjaxPage(ServerRequestInterface $request): ResponseI
'EXT:lux/Resources/Private/Templates/Analysis/SearchDetailPageAjax.html'
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$filter = BackendUtility::getFilterFromSession(
'search',
'Analysis',
['searchterm' => urldecode($request->getQueryParams()['searchterm']), 'limit' => 10]
);
$standaloneView->assignMultiple([
'searches' => $this->searchRepository->findBySearchterm(
urldecode($request->getQueryParams()['searchterm'])
),
'searches' => $this->searchRepository->findBySearchterm($filter),
'searchterm' => $request->getQueryParams()['searchterm'],
]);
$response = GeneralUtility::makeInstance(JsonResponse::class);
Expand Down
35 changes: 31 additions & 4 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class FilterDto
*/
protected string $timeTo = '';

protected int $limit = 0;
protected int $scoring = 0;
protected int $timePeriod = self::PERIOD_DEFAULT;
protected int $identified = self::IDENTIFIED_ALL;
Expand Down Expand Up @@ -94,6 +95,16 @@ public function getSearchterm(): string
return StringUtility::sanitizeString($this->searchterm);
}

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

public function isSearchtermSet(): bool
{
return $this->getSearchterm() !== '';
Expand Down Expand Up @@ -261,9 +272,9 @@ public function isCategoryScoringSet(): bool
return $this->getCategoryScoring() !== null;
}

public function setCategoryScoring(int $categoryUid): self
public function setCategoryScoring(?int $categoryUid): self
{
if ($categoryUid > 0) {
if ((int)$categoryUid > 0) {
$categoryRepository = GeneralUtility::makeInstance(CategoryRepository::class);
$category = $categoryRepository->findByUid((int)$categoryUid);
if ($category !== null) {
Expand Down Expand Up @@ -416,9 +427,9 @@ public function isBranchCodeSet(): bool
return $this->getBranchCode() > 0;
}

public function setBranchCode(int $branchCode): self
public function setBranchCode(?int $branchCode): self
{
$this->branchCode = $branchCode;
$this->branchCode = (int)$branchCode;
return $this;
}

Expand Down Expand Up @@ -486,6 +497,22 @@ public function setCompany(?Company $company): self
return $this;
}

public function getLimit(): int
{
return $this->limit;
}

public function isLimitSet(): bool
{
return $this->getLimit() > 0;
}

public function setLimit(int $limit): self
{
$this->limit = $limit;
return $this;
}

/**
* Calculated values from here
*/
Expand Down
19 changes: 19 additions & 0 deletions Classes/Domain/Repository/SearchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use In2code\Lux\Utility\DatabaseUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

class SearchRepository extends AbstractRepository
{
Expand Down Expand Up @@ -45,6 +46,24 @@ public function findCombinedBySearchIdentifier(FilterDto $filter): array
return $connection->executeQuery($sql)->fetchAllAssociative();
}

public function findBySearchterm(FilterDto $filter): QueryResultInterface
{
$sql = 'select s.* from ' . Search::TABLE_NAME . ' s'
. ' left join ' . Pagevisit::TABLE_NAME . ' pv on s.pagevisit = pv.uid'
. ' left join ' . Visitor::TABLE_NAME . ' v on s.visitor = v.uid'
. ' left join ' . Categoryscoring::TABLE_NAME . ' cs on cs.visitor = v.uid'
. ' where s.searchterm = "' . $filter->getSearchterm() . '"'
. $this->extendWhereClauseWithFilterTime($filter, true, 's')
. $this->extendWhereClauseWithFilterScoring($filter, 'v')
. $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
. ' order by s.crdate desc'
. ' limit ' . ($filter->isLimitSet() ? $filter->getLimit() : 750);
$query = $this->createQuery();
$query = $query->statement($sql);
return $query->execute();
}

/**
* Todo: This function can be removed (without replacement) if there are some values in
* tx_lux_domain_model_search.pagevisit (introduced with version 35.0.0)
Expand Down
40 changes: 27 additions & 13 deletions Classes/Utility/BackendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
declare(strict_types=1);
namespace In2code\Lux\Utility;

use In2code\Lux\Domain\Model\Transfer\FilterDto;
use Throwable;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Property\PropertyMapper;

class BackendUtility
{
Expand Down Expand Up @@ -32,19 +36,33 @@ public static function isAdministrator(): bool
return false;
}

/**
* @param string $key
* @param string $action
* @param string $controller
* @param array $data
* @return void
* @codeCoverageIgnore
*/
public static function saveValueToSession(string $key, string $action, string $controller, array $data)
public static function saveValueToSession(string $key, string $action, string $controller, array $data): void
{
self::getBackendUserAuthentication()->setAndSaveSessionData($key . $action . $controller . '_lux', $data);
}

public static function getFilterFromSession(
string $actionName,
string $controllerName,
array $propertyOverlay = []
): ?FilterDto {
$filterArray = self::getFilterArrayFromSession($actionName, $controllerName, $propertyOverlay);
try {
return GeneralUtility::makeInstance(PropertyMapper::class)->convert($filterArray, FilterDto::class);
} catch (Throwable $exception) {
return null;
}
}

public static function getFilterArrayFromSession(
string $actionName,
string $controllerName,
array $propertyOverlay = []
): array {
$filter = BackendUtility::getSessionValue('filter', $actionName, $controllerName);
return array_merge($filter, $propertyOverlay);
}

public static function getSessionValue(string $key, string $action, string $controller): array
{
$value = self::getBackendUserAuthentication()->getSessionData($key . $action . $controller . '_lux');
Expand All @@ -54,10 +72,6 @@ public static function getSessionValue(string $key, string $action, string $cont
return [];
}

/**
* @return ?BackendUserAuthentication
* @SuppressWarnings(PHPMD.Superglobals)
*/
public static function getBackendUserAuthentication(): ?BackendUserAuthentication
{
return $GLOBALS['BE_USER'] ?? null;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/StringUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function cleanString(string $string, bool $toLower = false, 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
57 changes: 31 additions & 26 deletions Resources/Private/Templates/Analysis/SearchDetailPageAjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,39 @@ <h3 class="panel-title">
<div class="panel-body">

<f:if condition="{searches}">
<table class="table table-striped">
<thead>
<tr>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.list.search.term">Searchterm</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.lead">Lead</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.company">Company</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.time">Time</f:translate></th>
</tr>
</thead>
<tbody>
<f:for each="{searches}" as="search">
<tr data-identifier-search="{search.uid}">
<td><span title="{search.searchterm}"><f:format.crop maxCharacters="35" append="...">{search.searchterm}</f:format.crop></span></td>
<td>
<span title="UID{search.visitor.uid}">{search.visitor.fullName}</span>
</td>
<td>{search.visitor.company}</td>
<td>
<span class="badge" title="{f:format.date(date:search.crdate,format:'{f:translate(key:\'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:date\')}')}">
<lux:format.readableDate>{search.crdate}</lux:format.readableDate>
</span>
</td>
<f:then>
<table class="table table-striped">
<thead>
<tr>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.list.search.term">Searchterm</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.lead">Lead</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.company">Company</f:translate></th>
<th><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.analysis.detailpage.time">Time</f:translate></th>
</tr>
</f:for>
</tbody>
</table>
</thead>
<tbody>
<f:for each="{searches}" as="search">
<tr data-identifier-search="{search.uid}">
<td><span title="{search.searchterm}"><f:format.crop maxCharacters="35" append="...">{search.searchterm}</f:format.crop></span></td>
<td>
<span title="UID{search.visitor.uid}">{search.visitor.fullName}</span>
</td>
<td>{search.visitor.company}</td>
<td>
<span class="badge" title="{f:format.date(date:search.crdate,format:'{f:translate(key:\'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:date\')}')}">
<lux:format.readableDate>{search.crdate}</lux:format.readableDate>
</span>
</td>
</tr>
</f:for>
</tbody>
</table>

<button style="margin-top: 15px" class="btn btn-primary pull-right" data-lux-linkmock-event="detailsearch{searchterm}"><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.detail.detail">show</f:translate></button>
<button style="margin-top: 15px" class="btn btn-primary pull-right" data-lux-linkmock-event="detailsearch{searchterm}"><f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:module.detail.detail">show</f:translate></button>
</f:then>
<f:else>
<f:render partial="Miscellaneous/NoValues" arguments="{_all}"/>
</f:else>
</f:if>
</div>
</div>

0 comments on commit 7c68aa6

Please sign in to comment.