Skip to content

Commit

Permalink
[FEATURE] Add site filter to view Lead/Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 26, 2024
1 parent 01b2130 commit 4dcb531
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ protected function assignAdditionalVariables(): array
return [];
}
$logRepository = GeneralUtility::makeInstance(LogRepository::class);
$this->filter->setLimit(6);
return [
'identifiedPerMonth' => $logRepository->findIdentifiedLogsFromMonths(),
'identifiedPerMonth' => $logRepository->findIdentifiedLogsFromMonths($this->filter),
];
}
}
1 change: 1 addition & 0 deletions Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function initializeDashboardAction(): void
*/
public function dashboardAction(FilterDto $filter): ResponseInterface
{
$filter->setLimit(8);
$this->view->assignMultiple([
'filter' => $filter,
'interestingLogs' => $this->logRepository->findInterestingLogs($filter),
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function dashboardAction(FilterDto $filter): ResponseInterface
{
$this->view->assignMultiple([
'filter' => $filter,
'interestingLogs' => $this->logRepository->findInterestingLogs($filter, 10),
'whoisonline' => $this->visitorRepository->findOnline(8),
'interestingLogs' => $this->logRepository->findInterestingLogs($filter->setLimit(10)),
'whoisonline' => $this->visitorRepository->findOnline($filter->setLimit(8)),
]);

$this->addDocumentHeaderForCurrentController();
Expand Down
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 Exception;
use In2code\Lux\Domain\Model\Log;
use In2code\Lux\Domain\Repository\LogRepository;
use In2code\Lux\Utility\LocalizationUtility;
Expand All @@ -28,8 +27,7 @@ class IdentificationMethodsDataProvider extends AbstractDataProvider
* ]
*
* @return void
* @throws DBALException
* @throws ExceptionDbalDriver
* @throws Exception
*/
public function prepareData(): void
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function getSite(): string

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

public function setSite(string $site): self
Expand Down
10 changes: 6 additions & 4 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ protected function extendLogicalAndWithFilterConstraintsForCrdate(
* @param FilterDto $filter
* @param QueryInterface $query
* @param array $logicalAnd
* @param string $tablePrefix
* @return array
* @throws InvalidQueryException
* @throws Exception
*/
protected function extendLogicalAndWithFilterConstraintsForSite(
FilterDto $filter,
QueryInterface $query,
array $logicalAnd
array $logicalAnd,
string $tablePrefix = ''
): array {
$logicalAnd[] = $query->in('site', $filter->getSitesForFilter());
$field = ($tablePrefix ? $tablePrefix . '.' : '') . 'site';
$logicalAnd[] = $query->in($field, $filter->getSitesForFilter());
return $logicalAnd;
}

Expand Down Expand Up @@ -284,7 +286,7 @@ protected function extendFromClauseWithJoinByFilter(
if (in_array('v', $tables)) {
$sql .= ' left join ' . Visitor::TABLE_NAME . ' v on v.uid = pv.visitor';
}
if ($filter->isSearchtermSet() || $filter->isDomainSet()) {
if ($filter->isSearchtermSet() || $filter->isSiteQueryNeeded()) {
if (in_array('pv', $tables)) {
$sql .= ' left join ' . Pagevisit::TABLE_NAME . ' pv on v.uid = pv.visitor';
}
Expand Down
17 changes: 10 additions & 7 deletions Classes/Domain/Repository/IpinformationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
declare(strict_types=1);
namespace In2code\Lux\Domain\Repository;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception as ExceptionDbal;
use In2code\Lux\Domain\Model\Ipinformation;
use In2code\Lux\Domain\Model\Pagevisit;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Domain\Model\Visitor;
use In2code\Lux\Utility\DatabaseUtility;

class IpinformationRepository extends AbstractRepository
{
/**
* @return int
* @throws Exception
* @throws ExceptionDbal
*/
public function findAllAmount(): int
Expand All @@ -36,15 +35,19 @@ public function findAllAmount(): int
*
* @param FilterDto $filter
* @return array
* @throws DBALException
* @throws Exception
* @throws ExceptionDbal
*/
public function findAllCountryCodesGrouped(FilterDto $filter): array
{
$connection = DatabaseUtility::getConnectionForTable(Ipinformation::TABLE_NAME);
$rows = $connection->executeQuery(
'select value from ' . Ipinformation::TABLE_NAME . ' where name = "countryCode"'
. $this->extendWhereClauseWithFilterTime($filter)
'select value from ' . Ipinformation::TABLE_NAME . ' i'
. ' left join ' . Visitor::TABLE_NAME . ' v on i.visitor=v.uid'
. ' left join ' . Pagevisit::TABLE_NAME . ' pv on pv.visitor=v.uid'
. ' where i.name = "countryCode"'
. $this->extendWhereClauseWithFilterTime($filter, true, 'i')
. $this->extendWhereClauseWithFilterTime($filter, true, 'pv')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
)->fetchAllAssociative();

$countryCodes = [];
Expand Down
18 changes: 9 additions & 9 deletions Classes/Domain/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ public function findAllAmount(): int

/**
* @param FilterDto $filter
* @param int $limit
* @return QueryResultInterface
* @throws InvalidQueryException
* @throws InvalidConfigurationTypeException
*/
public function findInterestingLogs(FilterDto $filter, int $limit = 8): QueryResultInterface
public function findInterestingLogs(FilterDto $filter): QueryResultInterface
{
$query = $this->createQuery();
$logicalAnd = $this->interestingLogsLogicalAnd($query);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
$query->setLimit($limit);
$query->setLimit($filter->getLimit());
return $query->execute();
}

Expand Down Expand Up @@ -76,20 +74,21 @@ public function findInterestingLogsByCompany(Company $company, int $limit = 250)
* [Log:4, Log:88],
* ]
*
* @param int $months
* @param FilterDto $filter property limit in filter will be used for number of month
* @return array
* @throws ExceptionDbal
*/
public function findIdentifiedLogsFromMonths(int $months = 6): array
public function findIdentifiedLogsFromMonths(FilterDto $filter): array
{
$queryBuilder = DatabaseUtility::getConnectionForTable(Log::TABLE_NAME);
$result = [];
for ($i = 0; $i < $months; $i++) {
for ($i = 0; $i < $filter->getLimit(); $i++) {
/** @noinspection PhpUnhandledExceptionInspection */
$dates = DateUtility::getLatestMonthDates($i);
$query = 'select * from ' . Log::TABLE_NAME .
' where status in(' . implode(',', Log::getIdentifiedStatus()) . ')' .
' and crdate >= ' . $dates[0]->format('U') . ' and crdate <= ' . $dates[1]->format('U');
' and crdate >= ' . $dates[0]->format('U') . ' and crdate <= ' . $dates[1]->format('U')
. $this->extendWhereClauseWithFilterSite($filter);
$result[] = $queryBuilder->executeQuery($query)->fetchAllAssociative();
}
$result = array_reverse($result);
Expand All @@ -106,7 +105,8 @@ public function findByStatusAmount(int $status, FilterDto $filter): int
{
$connection = DatabaseUtility::getConnectionForTable(Log::TABLE_NAME);
$query = 'select count(*) from ' . Log::TABLE_NAME . ' where status=' . $status
. $this->extendWhereClauseWithFilterTime($filter);
. $this->extendWhereClauseWithFilterTime($filter)
. $this->extendWhereClauseWithFilterSite($filter);
return (int)$connection->executeQuery($query)->fetchOne();
}

Expand Down
22 changes: 15 additions & 7 deletions Classes/Domain/Repository/VisitorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use In2code\Lux\Domain\Model\Linkclick;
use In2code\Lux\Domain\Model\Log;
use In2code\Lux\Domain\Model\Newsvisit;
use In2code\Lux\Domain\Model\Page;
use In2code\Lux\Domain\Model\Pagevisit;
use In2code\Lux\Domain\Model\Search;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
Expand Down Expand Up @@ -192,16 +193,17 @@ public function findByProperty(string $propertyName, string $propertyValue): ?Vi
* @param int $limit
* @return array
* @throws ExceptionDbal
* @throws ExceptionDbalDriver
*/
public function findByHottestScorings(FilterDto $filter, int $limit = 10)
{
$connection = DatabaseUtility::getConnectionForTable(Visitor::TABLE_NAME);
$sql = 'select distinct v.uid, v.scoring, v.tstamp from ' . Visitor::TABLE_NAME . ' v'
. $this->extendFromClauseWithJoinByFilter($filter, ['pv', 'p', 'cs'])
. ' 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'
. ' where v.deleted=0 and v.hidden=0 and v.identified=1'
. $this->extendWhereClauseWithFilterSearchterms($filter, 'v', 'email')
. $this->extendWhereClauseWithFilterDomain($filter, 'pv')
. $this->extendWhereClauseWithFilterSite($filter, 'pv')
. $this->extendWhereClauseWithFilterScoring($filter, 'v')
. $this->extendWhereClauseWithFilterCategoryScoring($filter, 'cs')
. ' order by v.scoring DESC, v.tstamp DESC'
Expand Down Expand Up @@ -275,6 +277,7 @@ public function findByUniqueSiteVisits(FilterDto $filter): QueryResultInterface
$query = $this->createQuery();
$logicalAnd = [$query->equals('visits', 1)];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}
Expand All @@ -289,6 +292,7 @@ public function findByRecurringSiteVisits(FilterDto $filter): QueryResultInterfa
$query = $this->createQuery();
$logicalAnd = [$query->greaterThan('visits', 1)];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}
Expand All @@ -303,6 +307,7 @@ public function findIdentified(FilterDto $filter): QueryResultInterface
$query = $this->createQuery();
$logicalAnd = [$query->equals('identified', true)];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}
Expand All @@ -317,23 +322,26 @@ public function findUnknown(FilterDto $filter): QueryResultInterface
$query = $this->createQuery();
$logicalAnd = [$query->equals('identified', false)];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, $logicalAnd);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute();
}

/**
* Find visitors that are now on the website (5 Min last activity)
*
* @param int $limit
* @param FilterDto $filter
* @return QueryResultInterface
* @throws InvalidQueryException
* @throws Exception
*/
public function findOnline(int $limit = 10): QueryResultInterface
public function findOnline(FilterDto $filter): QueryResultInterface
{
$query = $this->createQuery();
$query->matching($query->greaterThan('tstamp', DateUtility::getCurrentOnlineDateTime()->format('U')));
$query->setLimit($limit);
$logicalAnd = [$query->greaterThan('pagevisits.tstamp', DateUtility::getCurrentOnlineDateTime())];
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForSite($filter, $query, $logicalAnd, 'pagevisits');
$query->matching($query->logicalAnd(...$logicalAnd));
$query->setLimit($filter->getLimit());
$query->setOrderings(['tstamp' => QueryInterface::ORDER_DESCENDING]);
return $query->execute();
}
Expand Down
5 changes: 5 additions & 0 deletions Classes/Utility/ObjectUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public static function getFilterDtoFromStartAndEnd(DateTime $start, DateTime $en
$filterDto->setTimeFrom($start->format('c'))->setTimeTo($end->format('c'));
return $filterDto;
}

public static function getFilterWithLimit(int $limit = 10): FilterDto
{
return GeneralUtility::makeInstance(FilterDto::class)->setLimit(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Exception;
use In2code\Lux\Domain\Repository\LogRepository;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Dashboard\WidgetApi;
use TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function getChartData(): array
protected function getData(): array
{
$logRepository = GeneralUtility::makeInstance(LogRepository::class);
$logs = $logRepository->findIdentifiedLogsFromMonths(6);
$logs = $logRepository->findIdentifiedLogsFromMonths(ObjectUtility::getFilterWithLimit(6));
$amount = [];
foreach ($logs as $logsCombined) {
$amount[] = count($logsCombined);
Expand Down

0 comments on commit 4dcb531

Please sign in to comment.