Skip to content

Commit

Permalink
[FEATURE] Add an overall number to lead list
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 27, 2024
1 parent f548a32 commit 1ddbd94
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 8 deletions.
19 changes: 18 additions & 1 deletion Classes/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use In2code\Lux\Domain\Repository\CompanyRepository;
use In2code\Lux\Domain\Repository\VisitorRepository;
use In2code\Lux\Domain\Service\CompanyConfigurationService;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function listAction(FilterDto $filter, string $export = ''): ResponseInte
$this->view->assignMultiple([
'filter' => $filter->setLimit(750),
'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
'allVisitors' => $this->visitorRepository->findAllWithIdentifiedFirst($filter),
'allVisitors' => $this->visitorRepository->findAllWithIdentifiedFirst($filter->setLimit(750)),
'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class, $filter),
'hottestVisitors' => $this->visitorRepository->findByHottestScorings($filter->setLimit(8)),
'visitorsPerTimeData' => GeneralUtility::makeInstance(LeadsPerTimeDataProvider::class, $filter),
Expand Down Expand Up @@ -134,6 +135,7 @@ public function downloadCsvAction(FilterDto $filter): ResponseInterface
*
* @param Visitor $visitor
* @return ResponseInterface
* @throws ExceptionDbal
*/
public function removeAction(Visitor $visitor): ResponseInterface
{
Expand Down Expand Up @@ -422,6 +424,21 @@ public function setCategoryToCompanyAjax(ServerRequestInterface $request): Respo
return GeneralUtility::makeInstance(JsonResponse::class);
}

/**
* @return ResponseInterface
* @noinspection PhpUnused
*/
public function getOverallLeadsAjax(): ResponseInterface
{
$filter = BackendUtility::getFilterFromSession('list', 'Lead');
$visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class);
$label = LocalizationUtility::translateByKey(
'module.lead.list.overallajax',
[$visitorRepository->findAllWithIdentifiedFirstAmount($filter)]
);
return $this->jsonResponse(json_encode(['amountLabel' => $label]));
}

protected function addDocumentHeaderForCurrentController(): void
{
$actions = ['dashboard', 'list', 'companies'];
Expand Down
6 changes: 4 additions & 2 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ public function isIdentifiedSet(): bool
return $this->getIdentified() !== self::IDENTIFIED_ALL;
}

public function setIdentified(int $identified): self
public function setIdentified(?int $identified): self
{
$this->identified = $identified;
if ($identified !== null) {
$this->identified = $identified;
}
return $this;
}

Expand Down
78 changes: 78 additions & 0 deletions Classes/Domain/Repository/VisitorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ public function findAllWithIdentifiedFirst(FilterDto $filter): array
return $query->execute()->toArray();
}

public function findAllWithIdentifiedFirstAmount(FilterDto $filter): int
{
$sql = 'select count(distinct v.uid) from ' . Visitor::TABLE_NAME . ' v'
. ' left join ' . Pagevisit::TABLE_NAME . ' pv on v.uid = pv.visitor'
. ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor'
. ' left join ' . Attribute::TABLE_NAME . ' a on v.uid = a.visitor'
. ' where v.deleted=0 and v.blacklisted=0'
. $this->extendWhereClauseWithFilterSearchterms($filter, 'v')
. $this->extendWhereClauseWithFilterTime($filter, true, 'pv')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
. $this->extendWhereClauseWithFilterScoring($filter, 'v')
. $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs')
. $this->extendWhereClauseWithFilterIdentified($filter)
. $this->extendWhereClauseWithFilterPid($filter)
. ' limit 1';
$connection = DatabaseUtility::getConnectionForTable(Visitor::TABLE_NAME);
return (int)$connection->executeQuery($sql)->fetchOne();
}

/**
* @param FilterDto $filter
* @return array
Expand Down Expand Up @@ -195,6 +214,7 @@ public function findByHottestScorings(FilterDto $filter)
. ' left join ' . Pagevisit::TABLE_NAME . ' pv on v.uid = pv.visitor'
. ' left join ' . Page::TABLE_NAME . ' p on p.uid = pv.page'
. ' left join ' . Categoryscoring::TABLE_NAME . ' cs on v.uid = cs.visitor'
. ' left join ' . Attribute::TABLE_NAME . ' a on v.uid = a.visitor'
. ' where v.deleted=0 and v.hidden=0 and v.identified=1'
. $this->extendWhereClauseWithFilterSearchterms($filter, 'v', 'email')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
Expand Down Expand Up @@ -718,6 +738,64 @@ protected function getOrderingsArrayByFilterDto(FilterDto $filter): array
return $orderings;
}

/**
* @param FilterDto $filter
* @param string $table
* @param string $titleField
* @param string $concatenation
* @return string
*/
protected function extendWhereClauseWithFilterSearchterms(
FilterDto $filter,
string $table = '',
string $titleField = 'title',
string $concatenation = 'and'
): string {
$sql = '';
if ($filter->isSearchtermSet()) {
$tablePrefix = ($table !== '' ? $table . '.' : '');
$or = [];
foreach ($filter->getSearchterms() as $searchterm) {
$searchterm = StringUtility::cleanString($searchterm);
if ($sql === '') {
$sql .= ' ' . $concatenation . ' (';
}

if (MathUtility::canBeInterpretedAsInteger($searchterm)) {
$or[] = ' ' . $tablePrefix . 'uid = ' . (int)$searchterm;
} else {
$or[] = ' ' . $tablePrefix . 'email like "%' . $searchterm . '%"';
$or[] = ' ' . $tablePrefix . 'company like "%' . $searchterm . '%"';
$or[] = ' ' . $tablePrefix . 'ip_address like "%' . $searchterm . '%"';
$or[] = ' ' . $tablePrefix . 'description like "%' . $searchterm . '%"';
$or[] = ' a.value like "%' . $searchterm . '%"';
}
$sql .= implode(' or ', $or);
}

$sql .= ')';
}
return $sql;
}

protected function extendWhereClauseWithFilterIdentified(FilterDto $filter): string
{
$sql = '';
if ($filter->getIdentified() > FilterDto::IDENTIFIED_ALL) {
$sql .= ' and v.identified=' . (int)($filter->getIdentified() === FilterDto::IDENTIFIED_IDENTIFIED);
}
return $sql;
}

protected function extendWhereClauseWithFilterPid(FilterDto $filter): string
{
$sql = '';
if ($filter->isPidSet()) {
$sql .= ' and pv.page=' . (int)$filter->getPid();
}
return $sql;
}

/**
* @param object $modifiedObject
* @return void
Expand Down
4 changes: 4 additions & 0 deletions Configuration/Backend/AjaxRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
'path' => '/lux/linklistenerperformance',
'target' => GeneralController::class . '::getLinkListenerPerformanceAjax',
],
'/lux/overallleads' => [
'path' => '/lux/overallleads',
'target' => LeadController::class . '::getOverallLeadsAjax',
],
'/lux/pageoverview' => [
'path' => '/lux/pageoverview',
'target' => GeneralController::class . '::showOrHidePageOverviewAjax',
Expand Down
20 changes: 20 additions & 0 deletions Resources/Private/Build/JavaScript/Backend/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define(['jquery'], function($) {
asynchronousImageLoading();
asynchronousLinkListenerPerformanceLoading();
asynchronousCompaniesInformationLoading();
asynchronousLeadAmountLoading();
addToggleListener();
addUnitAjaxListener();
};
Expand Down Expand Up @@ -269,6 +270,25 @@ define(['jquery'], function($) {
target2.innerHTML = response.numberOfVisitors;
};

/**
* @returns {void}
*/
const asynchronousLeadAmountLoading = function() {
const element = document.querySelector('[data-lux-getoverallleads]');
if (element !== null) {
ajaxConnection(
TYPO3.settings.ajaxUrls['/lux/overallleads'], {}, 'asynchronousLeadAmountLoadingCallback', {element}
);
}
};

/**
* @params {Json} response
*/
this.asynchronousLeadAmountLoadingCallback = function(response, callbackArguments) {
callbackArguments.element.innerHTML = response.amountLabel;
};

/**
* Toggle elements
*
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 @@ -1441,6 +1441,10 @@
<source>Leads</source>
<target state="translated">Leads</target>
</trans-unit>
<trans-unit id="module.lead.list.overallajax">
<source>(%d overall)</source>
<target state="translated">(insgesamt %d)</target>
</trans-unit>
<trans-unit id="module.lead.companies">
<source>Companies</source>
<target state="translated">Firmen</target>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@
<trans-unit id="module.lead.list">
<source>Leads</source>
</trans-unit>
<trans-unit id="module.lead.list.overallajax">
<source>(%d overall)</source>
</trans-unit>
<trans-unit id="module.lead.companies">
<source>Companies</source>
</trans-unit>
Expand Down
3 changes: 2 additions & 1 deletion Resources/Private/Templates/Lead/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<f:then>
<lux:pagination.paginate objects="{allVisitors}" as="visitorsPaginator" itemsPerPage="25">
<div style="background-color: #dddddd; border-top: 1px solid #cccccc; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; color: #5a5a5a; font-weight: bold; padding: 10px;">
{allVisitors -> f:count()}
Leads
({allVisitors -> f:count()})
<span data-lux-getoverallleads="true" style="color: #aaa"></span>
</div>
<table class="table table-striped table-hover table-pointer min-height-50">
<f:render section="TableHeader" arguments="{_all}"/>
Expand Down
Loading

0 comments on commit 1ddbd94

Please sign in to comment.