-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add widget "Most viewed pages"
resolves: #47
- Loading branch information
1 parent
0fb19b0
commit 2a9dfcf
Showing
9 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
Classes/DependencyInjection/Widgets/MostViewedPagesRegistration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "matomo_widgets" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\MatomoWidgets\DependencyInjection\Widgets; | ||
|
||
use Brotkrueml\MatomoWidgets\Extension; | ||
use Brotkrueml\MatomoWidgets\Widgets\Decorator\NumberDecorator; | ||
use Brotkrueml\MatomoWidgets\Widgets\Provider\GenericTableDataProvider; | ||
use Brotkrueml\MatomoWidgets\Widgets\TableWidget; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MostViewedPagesRegistration extends AbstractRegistration | ||
{ | ||
private const METHOD = 'Actions.getPageUrls'; | ||
private const PARAMETERS_PARAMETERS = 'matomo_widgets.mostViewedPages.parameters'; | ||
|
||
protected $serviceIdSuffix = 'actions.mostViewedPages'; | ||
|
||
public function register(): void | ||
{ | ||
if (! $this->matomoConfiguration->isWidgetActive('mostViewedPages')) { | ||
return; | ||
} | ||
|
||
$this->defineParameters(); | ||
$this->registerDataProvider(); | ||
$this->registerWidget(); | ||
} | ||
|
||
private function defineParameters(): void | ||
{ | ||
$this->parameters->set( | ||
self::PARAMETERS_PARAMETERS, | ||
[ | ||
'period' => 'month', | ||
'date' => 'today', | ||
'filter_limit' => '50', | ||
'filter_sort_column' => 'nb_hits', | ||
'filter_sort_order' => 'desc', | ||
'flat' => 1, | ||
], | ||
); | ||
} | ||
|
||
private function registerDataProvider(): void | ||
{ | ||
$this->services | ||
->set($this->buildServiceDataProviderId(), GenericTableDataProvider::class) | ||
->arg('$connectionConfiguration', new Reference($this->connectionConfigurationId)) | ||
->arg('$method', self::METHOD) | ||
->arg( | ||
'$columns', | ||
[ | ||
[ | ||
'column' => 'label', | ||
'header' => Extension::LANGUAGE_PATH_DASHBOARD . ':urls', | ||
'classes' => 'matomo-widgets__break-word', | ||
], | ||
[ | ||
'column' => 'nb_hits', | ||
'header' => Extension::LANGUAGE_PATH_DASHBOARD . ':hits', | ||
'decorator' => new Reference(NumberDecorator::class), | ||
'classes' => 'matomo-widgets__text-end', | ||
], | ||
], | ||
) | ||
->arg('$parameters', '%' . self::PARAMETERS_PARAMETERS . '%') | ||
->call('addParameter', [ | ||
'showColumns', 'nb_hits', | ||
]); | ||
} | ||
|
||
private function registerWidget(): void | ||
{ | ||
$localisedTitle = Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.actions.mostViewedPages.title'; | ||
$title = $this->matomoConfiguration->siteTitle !== '' | ||
? \sprintf('%s: %s', $this->matomoConfiguration->siteTitle, 'Most viewed pages') | ||
: $localisedTitle; | ||
|
||
$this->services | ||
->set($this->buildServiceWidgetId(), TableWidget::class) | ||
->arg('$view', new Reference('dashboard.views.widget')) | ||
->arg('$dataProvider', new Reference($this->buildServiceDataProviderId())) | ||
->arg( | ||
'$options', | ||
[ | ||
'reportLink' => $this->buildReportLink(), | ||
'siteTitle' => $this->matomoConfiguration->siteTitle, | ||
'title' => $localisedTitle, | ||
], | ||
) | ||
->tag( | ||
'dashboard.widget', | ||
[ | ||
'identifier' => $this->buildWidgetIdentifier(), | ||
'groupNames' => 'matomo', | ||
'title' => $title, | ||
'description' => Extension::LANGUAGE_PATH_DASHBOARD . ':widgets.actions.mostViewedPages.description', | ||
'iconIdentifier' => self::ICON_IDENTIFIER, | ||
'height' => 'medium', | ||
'width' => 'medium', | ||
], | ||
); | ||
} | ||
|
||
private function buildReportLink(): string | ||
{ | ||
return \sprintf( | ||
'%s?module=CoreHome&action=index&idSite=%d&period=month&date=today#?&General_Actions&subcategory=General_Pages', | ||
$this->matomoConfiguration->url, | ||
$this->matomoConfiguration->idSite, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters