diff --git a/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php index d35df8cb..232c6798 100644 --- a/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php +++ b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php @@ -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), ]; } } diff --git a/Classes/Controller/AnalysisController.php b/Classes/Controller/AnalysisController.php index 25a30bbe..3cc7653d 100644 --- a/Classes/Controller/AnalysisController.php +++ b/Classes/Controller/AnalysisController.php @@ -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), diff --git a/Classes/Controller/LeadController.php b/Classes/Controller/LeadController.php index 8fb467ef..b82de926 100644 --- a/Classes/Controller/LeadController.php +++ b/Classes/Controller/LeadController.php @@ -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(); diff --git a/Classes/Domain/DataProvider/IdentificationMethodsDataProvider.php b/Classes/Domain/DataProvider/IdentificationMethodsDataProvider.php index afe39774..94a175bb 100644 --- a/Classes/Domain/DataProvider/IdentificationMethodsDataProvider.php +++ b/Classes/Domain/DataProvider/IdentificationMethodsDataProvider.php @@ -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; @@ -28,8 +27,7 @@ class IdentificationMethodsDataProvider extends AbstractDataProvider * ] * * @return void - * @throws DBALException - * @throws ExceptionDbalDriver + * @throws Exception */ public function prepareData(): void { diff --git a/Classes/Domain/Model/Transfer/FilterDto.php b/Classes/Domain/Model/Transfer/FilterDto.php index 8af5712c..fb5a3f7c 100644 --- a/Classes/Domain/Model/Transfer/FilterDto.php +++ b/Classes/Domain/Model/Transfer/FilterDto.php @@ -367,7 +367,7 @@ public function getSite(): string public function isSiteSet(): bool { - return $this->getSite() !==''; + return $this->getSite() !== ''; } public function setSite(string $site): self diff --git a/Classes/Domain/Repository/AbstractRepository.php b/Classes/Domain/Repository/AbstractRepository.php index 2bd52be0..e460ee1f 100644 --- a/Classes/Domain/Repository/AbstractRepository.php +++ b/Classes/Domain/Repository/AbstractRepository.php @@ -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; } @@ -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'; } diff --git a/Classes/Domain/Repository/IpinformationRepository.php b/Classes/Domain/Repository/IpinformationRepository.php index 6c2af329..4cb08999 100644 --- a/Classes/Domain/Repository/IpinformationRepository.php +++ b/Classes/Domain/Repository/IpinformationRepository.php @@ -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 @@ -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 = []; diff --git a/Classes/Domain/Repository/LogRepository.php b/Classes/Domain/Repository/LogRepository.php index 76351830..34779728 100644 --- a/Classes/Domain/Repository/LogRepository.php +++ b/Classes/Domain/Repository/LogRepository.php @@ -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(); } @@ -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); @@ -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(); } diff --git a/Classes/Domain/Repository/VisitorRepository.php b/Classes/Domain/Repository/VisitorRepository.php index 343b8233..f00dbd34 100644 --- a/Classes/Domain/Repository/VisitorRepository.php +++ b/Classes/Domain/Repository/VisitorRepository.php @@ -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; @@ -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' @@ -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(); } @@ -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(); } @@ -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(); } @@ -317,6 +322,7 @@ 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(); } @@ -324,16 +330,18 @@ public function findUnknown(FilterDto $filter): QueryResultInterface /** * 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(); } diff --git a/Classes/Utility/ObjectUtility.php b/Classes/Utility/ObjectUtility.php index 97ec9e4f..5ed9ebf6 100644 --- a/Classes/Utility/ObjectUtility.php +++ b/Classes/Utility/ObjectUtility.php @@ -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); + } } diff --git a/Classes/Widgets/DataProvider/LuxIdentifiedPerMonthDataProvider.php b/Classes/Widgets/DataProvider/LuxIdentifiedPerMonthDataProvider.php index 4cb73983..6e1c888a 100644 --- a/Classes/Widgets/DataProvider/LuxIdentifiedPerMonthDataProvider.php +++ b/Classes/Widgets/DataProvider/LuxIdentifiedPerMonthDataProvider.php @@ -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; @@ -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);