Skip to content

Commit

Permalink
[FEATURE] UTM Listview: Add a checkbox to see only results with refer…
Browse files Browse the repository at this point in the history
…rers

This replaces the just included filter field content
  • Loading branch information
einpraegsam committed Mar 1, 2024
1 parent 97a47ad commit 12aeb1d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 57 deletions.
1 change: 0 additions & 1 deletion Classes/Controller/AnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public function utmAction(FilterDto $filter, string $export = ''): ResponseInter
'utmCampaigns' => $this->utmRepository->findAllCampaigns($filter),
'utmSources' => $this->utmRepository->findAllSources($filter),
'utmMedia' => $this->utmRepository->findAllMedia($filter),
'utmContent' => $this->utmRepository->findAllContent($filter),
'utmList' => $this->utmRepository->findByFilter($filter),
'utmData' => GeneralUtility::makeInstance(UtmDataProvider::class, $filter),
'utmCampaignData' => GeneralUtility::makeInstance(UtmCampaignDataProvider::class, $filter),
Expand Down
38 changes: 18 additions & 20 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FilterDto
protected int $timePeriodDefault = self::PERIOD_DEFAULT;
protected int $timePeriod = self::PERIOD_DEFAULT;
protected int $identified = self::IDENTIFIED_ALL;
protected bool $withReferrer = false;

/**
* Filter by categoryscoring greater then 0
Expand Down Expand Up @@ -280,6 +281,22 @@ public function setIdentified(?int $identified): self
return $this;
}

public function isWithReferrer(): bool
{
return $this->withReferrer;
}

public function isWithReferrerSet(): bool
{
return $this->isWithReferrer() !== false;
}

public function setWithReferrer(bool $withReferrer): self
{
$this->withReferrer = $withReferrer;
return $this;
}

/**
* Set a timeTo and timeFrom if there is a timeframe given in seconds. E.g. 60 means a starttime 60s ago to now.
*
Expand Down Expand Up @@ -594,6 +611,7 @@ public function isSet(): bool
|| $this->isTimeToSet()
|| $this->isTimePeriodSet()
|| $this->isIdentifiedSet()
|| $this->isWithReferrerSet()
|| $this->isDomainSet()
|| $this->isCountrySet()
|| $this->isSiteSet()
Expand All @@ -611,26 +629,6 @@ public function isTimeFromOrTimeToSet(): bool
return $this->isTimeFromSet() || $this->isTimeToSet();
}

/**
* Is only a searchterm given and nothing else in backend filter?
*
* @return bool
*/
protected function isOnlySearchtermGiven(): bool
{
return $this->isSearchtermSet()
&& $this->isPidSet() === false
&& $this->isScoringSet() === false
&& $this->isCategoryScoringSet() === false
&& $this->isTimeFromSet() === false
&& $this->isTimeToSet() === false
&& $this->timePeriod === self::PERIOD_DEFAULT
&& $this->identified === self::IDENTIFIED_ALL
&& $this->isDomainSet() === false
&& $this->isSiteSet() === false
&& $this->isCountrySet() === false;
}

/**
* Get a start datetime for period filter
*
Expand Down
51 changes: 27 additions & 24 deletions Classes/Domain/Repository/UtmRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function findByFilter(FilterDto $filter): QueryResultInterface
$query = $this->createQuery();
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForCrdate($filter, $query, []);
$logicalAnd = $this->extendWithExtendedFilterQuery($query, $logicalAnd, $filter);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForIsReferrer($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
$query->setLimit(750);
return $query->execute();
Expand Down Expand Up @@ -62,16 +63,6 @@ public function findAllMedia(FilterDto $filter): array
return $this->findAllProperties('utm_medium', $filter);
}

/**
* @param FilterDto $filter
* @return array
* @throws ExceptionDbal
*/
public function findAllContent(FilterDto $filter): array
{
return $this->findAllProperties('utm_content', $filter);
}

/**
* @param string $property
* @param FilterDto $filter
Expand Down Expand Up @@ -112,6 +103,7 @@ public function getNumberOfVisitorsInTimeFrame(DateTime $start, DateTime $end, F
$query->lessThanOrEqual('crdate', $end->format('U')),
];
$logicalAnd = $this->extendWithExtendedFilterQuery($query, $logicalAnd, $filter);
$logicalAnd = $this->extendLogicalAndWithFilterConstraintsForIsReferrer($filter, $query, $logicalAnd);
$query->matching($query->logicalAnd(...$logicalAnd));
return $query->execute()->count();
}
Expand Down Expand Up @@ -142,8 +134,8 @@ public function findCombinedByField(string $field, FilterDto $filter): array
. $this->extendWhereClauseWithFilterCampaign($filter, 'utm')
. $this->extendWhereClauseWithFilterSource($filter, 'utm')
. $this->extendWhereClauseWithFilterMedium($filter, 'utm')
. $this->extendWhereClauseWithFilterContent($filter, 'utm')
. $this->extendWhereClauseWithFilterSite($filter)
. $this->extendWhereClauseWithFilterIsReferrer($filter, 'utm')
. ' group by utm.' . $field . ' order by count desc limit 8';
return $connection->executeQuery($sql)->fetchAllAssociative();
}
Expand Down Expand Up @@ -187,19 +179,6 @@ protected function extendWhereClauseWithFilterMedium(FilterDto $filter, string $
return $sql;
}

protected function extendWhereClauseWithFilterContent(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->isUtmContentSet()) {
$field = 'utm_content';
if ($table !== '') {
$field = $table . '.' . $field;
}
$sql .= ' and ' . $field . '="' . $filter->getUtmContent() . '"';
}
return $sql;
}

/**
* Returns part of a where clause like
* ' and site="site 1"'
Expand All @@ -218,6 +197,19 @@ protected function extendWhereClauseWithFilterSite(FilterDto $filter, string $ta
return $sql;
}

protected function extendWhereClauseWithFilterIsReferrer(FilterDto $filter, string $table = ''): string
{
$sql = '';
if ($filter->isWithReferrerSet()) {
$field = 'referrer';
if ($table !== '') {
$field = $table . '.' . $field;
}
$sql .= ' and ' . $field . ' != \'\'';
}
return $sql;
}

/**
* @param QueryInterface $query
* @param array $logicalAnd
Expand Down Expand Up @@ -262,4 +254,15 @@ protected function extendWithExtendedFilterQuery(
}
return $logicalAnd;
}

protected function extendLogicalAndWithFilterConstraintsForIsReferrer(
FilterDto $filter,
QueryInterface $query,
array $logicalAnd
): array {
if ($filter->isWithReferrerSet()) {
$logicalAnd[] = $query->logicalNot($query->equals('referrer', ''));
}
return $logicalAnd;
}
}
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 @@ -2605,6 +2605,10 @@
<source>Page Identifier (PID)</source>
<target state="translated">Seitennummer (PID)</target>
</trans-unit>
<trans-unit id="dictionary.withreferrer">
<source>With referrer</source>
<target state="translated">Mit Referrer</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,9 @@
<trans-unit id="dictionary.pageidentifier">
<source>Page Identifier (PID)</source>
</trans-unit>
<trans-unit id="dictionary.withreferrer">
<source>With referrer</source>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 12 additions & 12 deletions Resources/Private/Partials/Filter/Analysis/Utm.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ <h5>
</div>

<div class="input-group form-group">
<f:form.select
property="utmContent"
options="{utmContent}"
optionLabelField="title"
optionValueField="uid"
prependOptionValue=""
prependOptionLabel=""
class="form-control form-select"
id="utmContent"/>
<button type="button" class="btn btn-default" data-global-event="click" data-action-focus="#utmContent">
<f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:dictionary.content">Content</f:translate>
</button>
<div class="form-check form-switch" style="position: relative; display: flex; justify-content: right; width: 100%;">
<f:form.checkbox
class="form-check-input"
id="withReferrer"
property="withReferrer"
value="1"
style="position: absolute; top: 4px;"
checked="{f:if(condition:'{filter.withReferrer} == 1',then:'checked')}"/>
<label style="padding: 5px 0 0 5px; margin-right: 40px;" class="form-check-label" for="withReferrer">
<f:translate key="LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:dictionary.withreferrer">With referrer</f:translate>
</label>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 12aeb1d

Please sign in to comment.