Skip to content

Commit

Permalink
[FEATURE] Add site filter to view Lead/Companies
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 28, 2024
1 parent a86dab0 commit 49185ef
Show file tree
Hide file tree
Showing 17 changed files with 1,663 additions and 429 deletions.
48 changes: 37 additions & 11 deletions Classes/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,28 @@ public function companiesAction(FilterDto $filter, string $export = ''): Respons
$available = 0;
}
$this->view->assignMultiple([
'companies' => $this->companyRepository->findByFilter($filter),
'branches' => $this->companyRepository->findAllBranches(),
'filter' => $filter,
'countries' => $this->companyRepository->findCountriesByFilter($filter),
'luxCategories' => $this->categoryRepository->findAllLuxCategories(),
'branches' => $this->companyRepository->findAllBranches($filter),
'categories' => $this->categoryRepository->findAllLuxCompanyCategories(),
'companies' => $this->companyRepository->findByFilter($filter->setLimit(750)),
'revenueClassData' => GeneralUtility::makeInstance(RevenueClassDataProvider::class, $filter),
'companyAmountPerMonthData' => GeneralUtility::makeInstance(CompanyAmountPerMonthDataProvider::class),
'latestPagevisitsWithCompanies' => $this->pagevisitsRepository->findLatestPagevisitsWithCompanies(),
'companyAmountPerMonthData' => GeneralUtility::makeInstance(
CompanyAmountPerMonthDataProvider::class,
$filter
),
'latestPagevisitsWithCompanies' => $this->pagevisitsRepository->findLatestPagevisitsWithCompanies(
$filter->setLimit(8)
),
'wiredminds' => [
'status' => $this->wiredmindsRepository->getStatus() !== [],
'statistics' => $statistics,
'limit' => $limit,
'overall' => $limit,
'available' => $available,
'show' => BackendUtility::isAdministrator(),
],
'filter' => $filter,
]);
$this->addDocumentHeaderForCurrentController();
return $this->defaultRendering();
Expand Down Expand Up @@ -242,6 +250,9 @@ public function companiesDisabledAction(string $tokenWiredminds = ''): ResponseI
*/
public function companyAction(Company $company): ResponseInterface
{
if ($company->canBeRead() === false) {
throw new AuthenticationException('Not allowed to view this company', 1709123396);
}
$filter = ObjectUtility::getFilterDtoFromStartAndEnd(
$company->getFirstPagevisit()->getCrdate(),
new DateTime()
Expand All @@ -266,7 +277,7 @@ public function companyAction(Company $company): ResponseInterface
public function downloadCsvCompaniesAction(FilterDto $filter): ResponseInterface
{
$this->view->assignMultiple([
'companies' => $this->companyRepository->findByFilter($filter),
'companies' => $this->companyRepository->findByFilter($filter->setLimit(750)),
]);
return $this->csvResponse($this->view->render());
}
Expand Down Expand Up @@ -321,6 +332,7 @@ public function detailAjax(ServerRequestInterface $request): ResponseInterface
* @param ServerRequestInterface $request
* @return ResponseInterface
* @noinspection PhpUnused
* @throws AuthenticationException
*/
public function detailCompaniesAjax(ServerRequestInterface $request): ResponseInterface
{
Expand All @@ -333,6 +345,9 @@ public function detailCompaniesAjax(ServerRequestInterface $request): ResponseIn
));
$standaloneView->setPartialRootPaths(['EXT:lux/Resources/Private/Partials/']);
$company = $companyRepository->findByUid((int)$request->getQueryParams()['company']);
if ($company->canBeRead() === false) {
throw new AuthenticationException('Not allowed to view this company', 1709123966);
}
$standaloneView->assignMultiple([
'company' => $company,
'visitors' => $visitorRepository->findByCompany($company, 6),
Expand Down Expand Up @@ -444,11 +459,22 @@ 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]));
$amount = $visitorRepository->findAllWithIdentifiedFirstAmount($filter);
$label = LocalizationUtility::translateByKey('module.lead.list.overallajax', [$amount]);
return $this->jsonResponse(json_encode(['amount' => $amount, 'amountLabel' => $label]));
}

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

protected function addDocumentHeaderForCurrentController(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CompanyAmountPerMonthDataProvider extends AbstractDataProvider
public function prepareData(): void
{
$companyRepository = GeneralUtility::makeInstance(CompanyRepository::class);
$results = $companyRepository->findCompanyAmountOfLastSixMonths();
$results = $companyRepository->findCompanyAmountOfLastSixMonths($this->filter);
$titles = $amounts = [];
foreach ($results as $month => $amount) {
$titles[] = LocalizationUtility::translateByKey('datetime.month.' . $month);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/DataProvider/RevenueClassDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RevenueClassDataProvider extends AbstractDataProvider
public function prepareData(): void
{
$companyRepository = GeneralUtility::makeInstance(CompanyRepository::class);
$results = $companyRepository->findRevenueClasses($this->filter);
$results = $companyRepository->findRevenueClasses($this->filter->setLimit(6));
$titles = $amounts = [];
foreach ($results as $revenueClass => $amount) {
$titles[] = LocalizationUtility::translateByKey('dictionary.revenue_class.' . $revenueClass);
Expand Down
17 changes: 17 additions & 0 deletions Classes/Domain/Model/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use In2code\Lux\Domain\Service\BranchService;
use In2code\Lux\Domain\Service\CountryService;
use In2code\Lux\Domain\Service\Image\CompanyImageService;
use In2code\Lux\Domain\Service\SiteService;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\StringUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
Expand Down Expand Up @@ -351,4 +353,19 @@ public function getImageUrl(): string
$visitorImageService = GeneralUtility::makeInstance(CompanyImageService::class);
return $visitorImageService->getUrl(['company' => $this]);
}

/**
* Check if this record can be viewed by current editor
*
* @return bool
*/
public function canBeRead(): bool
{
if (BackendUtility::isAdministrator()) {
return true;
}
$sites = GeneralUtility::makeInstance(SiteService::class)->getAllowedSites();
return GeneralUtility::makeInstance(CompanyRepository::class)
->canCompanyBeReadBySites($this, array_keys($sites));
}
}
37 changes: 33 additions & 4 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class FilterDto

protected string $domain = '';
protected string $site = '';
protected string $country = '';
protected string $utmCampaign = '';
protected string $utmSource = '';
protected string $utmMedium = '';
Expand Down Expand Up @@ -382,6 +383,22 @@ public function setSite(string $site): self
return $this;
}

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

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

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

public function getUtmCampaign(): string
{
return StringUtility::sanitizeString($this->utmCampaign);
Expand Down Expand Up @@ -557,6 +574,7 @@ public function isSet(): bool
|| $this->isTimePeriodSet()
|| $this->isIdentifiedSet()
|| $this->isDomainSet()
|| $this->isCountrySet()
|| $this->isSiteSet()
|| $this->isUtmCampaignSet()
|| $this->isUtmMediumSet()
Expand Down Expand Up @@ -587,7 +605,9 @@ protected function isOnlySearchtermGiven(): bool
&& $this->isTimeToSet() === false
&& $this->timePeriod === self::PERIOD_DEFAULT
&& $this->identified === self::IDENTIFIED_ALL
&& $this->isDomainSet() === false;
&& $this->isDomainSet() === false
&& $this->isSiteSet() === false
&& $this->isCountrySet() === false;
}

/**
Expand Down Expand Up @@ -905,9 +925,18 @@ public function getHash(): string
*/
public function __toString(): string
{
$string = $this->searchterm . $this->pid . $this->timeFrom . $this->timeTo . (string)$this->scoring .
(string)$this->categoryScoring . (string)$this->timePeriod . (string)$this->identified .
(string)$this->shortMode . (string)$this->domain . $this->getSitesForFilterList();
$string = $this->searchterm
. $this->pid
. $this->timeFrom
. $this->timeTo
. $this->scoring
. $this->categoryScoring
. $this->timePeriod
. $this->identified
. $this->shortMode
. $this->domain
. $this->country
. $this->getSitesForFilterList();
return md5($string);
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ public function getLongitude(): string
}

/**
* Check if this visitor can be viewed by current editor
* Check if this record can be viewed by current editor
*
* @return bool
*/
Expand Down
61 changes: 61 additions & 0 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ protected function extendWhereClauseWithFilterSite(FilterDto $filter, string $ta
return ' and ' . $field . ' in ("' . implode('","', $filter->getSitesForFilter()) . '")';
}

protected function extendWhereClauseWithFilterCountry(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->isCountrySet()) {
$field = 'country_code';
if ($table !== '') {
$field = $table . '.' . $field;
}
$sql .= ' and ' . $field . '="' . $filter->getCountry() . '"';
}
return $sql;
}

/**
* Returns part of a where clause like
* " and v.scoring >= 90"
Expand Down Expand Up @@ -301,4 +314,52 @@ protected function extendFromClauseWithJoinByFilter(
}
return $sql;
}

protected function extendWhereClauseWithFilterSizeClass(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->getSizeClass() !== '') {
if ($table !== '') {
$table .= '.';
}
$sql .= ' and ' . $table . 'size_class = ' . $filter->getSizeClass();
}
return $sql;
}

protected function extendWhereClauseWithFilterRevenueClass(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->getRevenueClass() !== '') {
if ($table !== '') {
$table .= '.';
}
$sql .= ' and ' . $table . 'revenue_class = ' . $filter->getRevenueClass();
}
return $sql;
}

protected function extendWhereClauseWithFilterBranchCode(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->getBranchCode() > 0) {
if ($table !== '') {
$table .= '.';
}
$sql .= ' and ' . $table . 'branch_code = ' . $filter->getBranchCode();
}
return $sql;
}

protected function extendWhereClauseWithFilterCategory(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->getCategory() !== null) {
if ($table !== '') {
$table .= '.';
}
$sql .= ' and ' . $table . 'category = ' . $filter->getCategory()->getUid();
}
return $sql;
}
}
Loading

0 comments on commit 49185ef

Please sign in to comment.