mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-22 05:56:08 +01:00
Use DI instead of unnecessary code
This commit is contained in:
parent
2105b79b8a
commit
ab6c7d2967
4 changed files with 85 additions and 34 deletions
|
@ -22,8 +22,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Widgets;
|
|||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Dashboard\Widgets\AbstractBarChartWidget;
|
||||
|
||||
class PageViewsBar extends AbstractBarChartWidget
|
||||
|
@ -36,6 +35,18 @@ class PageViewsBar extends AbstractBarChartWidget
|
|||
|
||||
protected $height = 4;
|
||||
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
protected $queryBuilder;
|
||||
|
||||
public function __construct(string $identifier, QueryBuilder $queryBuilder)
|
||||
{
|
||||
parent::__construct($identifier);
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
|
||||
protected function prepareChartData(): void
|
||||
{
|
||||
list($labels, $data) = $this->calculateDataForLastDays(31);
|
||||
|
@ -57,18 +68,15 @@ class PageViewsBar extends AbstractBarChartWidget
|
|||
|
||||
protected function getPageViewsInPeriod(int $start, int $end): int
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_tracking_pageview');
|
||||
|
||||
return (int)$queryBuilder
|
||||
return (int)$this->queryBuilder
|
||||
->count('*')
|
||||
->from('tx_tracking_pageview')
|
||||
->where(
|
||||
$queryBuilder->expr()->gte('tstamp', $start),
|
||||
$queryBuilder->expr()->lte('tstamp', $end),
|
||||
$queryBuilder->expr()->notIn(
|
||||
$this->queryBuilder->expr()->gte('tstamp', $start),
|
||||
$this->queryBuilder->expr()->lte('tstamp', $end),
|
||||
$this->queryBuilder->expr()->notIn(
|
||||
'tx_tracking_pageview.pid',
|
||||
$queryBuilder->createNamedParameter([
|
||||
$this->queryBuilder->createNamedParameter([
|
||||
1,
|
||||
11,
|
||||
38,
|
||||
|
|
|
@ -23,9 +23,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Widgets;
|
|||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Dashboard\Widgets\AbstractDoughnutChartWidget;
|
||||
|
||||
class PageViewsPerPageDoughnut extends AbstractDoughnutChartWidget
|
||||
|
@ -34,6 +32,17 @@ class PageViewsPerPageDoughnut extends AbstractDoughnutChartWidget
|
|||
|
||||
protected $description = 'LLL:EXT:tracking/Resources/Private/Language/locallang.xlf:dashboard.widgets.pageViewsPerPageDoughnut.description';
|
||||
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
protected $queryBuilder;
|
||||
|
||||
public function __construct(string $identifier, QueryBuilder $queryBuilder)
|
||||
{
|
||||
parent::__construct($identifier);
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
}
|
||||
|
||||
protected function prepareChartData(): void
|
||||
{
|
||||
list($labels, $data) = $this->getPageViewsPerPage(31);
|
||||
|
@ -53,9 +62,8 @@ class PageViewsPerPageDoughnut extends AbstractDoughnutChartWidget
|
|||
{
|
||||
$labels = [];
|
||||
$data = [];
|
||||
$queryBuilder = $this->getQueryBuilder();
|
||||
|
||||
$result = $queryBuilder
|
||||
$result = $this->queryBuilder
|
||||
->selectLiteral('count(tx_tracking_pageview.pid) as total')
|
||||
->addSelect('pages.title', 'pages.uid')
|
||||
->from('tx_tracking_pageview')
|
||||
|
@ -63,12 +71,15 @@ class PageViewsPerPageDoughnut extends AbstractDoughnutChartWidget
|
|||
'tx_tracking_pageview',
|
||||
'pages',
|
||||
'pages',
|
||||
$queryBuilder->expr()->eq('tx_tracking_pageview.pid', $queryBuilder->quoteIdentifier('pages.uid'))
|
||||
$this->queryBuilder->expr()->eq(
|
||||
'tx_tracking_pageview.pid',
|
||||
$this->queryBuilder->quoteIdentifier('pages.uid')
|
||||
)
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->notIn(
|
||||
$this->queryBuilder->expr()->notIn(
|
||||
'tx_tracking_pageview.pid',
|
||||
$queryBuilder->createNamedParameter([
|
||||
$this->queryBuilder->createNamedParameter([
|
||||
1,
|
||||
11,
|
||||
38,
|
||||
|
@ -91,9 +102,4 @@ class PageViewsPerPageDoughnut extends AbstractDoughnutChartWidget
|
|||
$data,
|
||||
];
|
||||
}
|
||||
|
||||
private function getQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,27 @@ services:
|
|||
DanielSiepmann\Tracking\:
|
||||
resource: '../Classes/*'
|
||||
|
||||
DanielSiepmann\DI\DatabaseConnection\Pageview:
|
||||
# Virtual services
|
||||
|
||||
DanielSiepmann\Tracking\DI\DatabaseConnection\Pageview:
|
||||
factory:
|
||||
- '@TYPO3\CMS\Core\Database\ConnectionPool'
|
||||
- 'getConnectionForTable'
|
||||
arguments:
|
||||
- 'tx_tracking_pageview'
|
||||
DanielSiepmann\Tracking\DI\QueryBuilder\PageView:
|
||||
factory:
|
||||
- '@TYPO3\CMS\Core\Database\ConnectionPool'
|
||||
- 'getQueryBuilderForTable'
|
||||
arguments:
|
||||
- 'tx_tracking_pageview'
|
||||
|
||||
# Existing classes
|
||||
|
||||
DanielSiepmann\Tracking\Domain\Repository\Pageview:
|
||||
public: true
|
||||
arguments:
|
||||
- '@DanielSiepmann\DI\DatabaseConnection\Pageview'
|
||||
- '@DanielSiepmann\Tracking\DI\DatabaseConnection\Pageview'
|
||||
|
||||
DanielSiepmann\Tracking\Middleware\Pageview:
|
||||
public: true
|
||||
|
@ -30,17 +40,21 @@ services:
|
|||
# Dashboard Widgets
|
||||
|
||||
DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsBar:
|
||||
class: DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsBar
|
||||
arguments: [pageViewsBar]
|
||||
class: 'DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsBar'
|
||||
arguments:
|
||||
- 'pageViewsBar'
|
||||
- '@DanielSiepmann\Tracking\DI\QueryBuilder\PageView'
|
||||
tags:
|
||||
- name: dashboard.widget
|
||||
identifier: pageViewsBar
|
||||
widgetGroups: tracking
|
||||
- name: 'dashboard.widget'
|
||||
identifier: 'pageViewsBar'
|
||||
widgetGroups: 'tracking'
|
||||
|
||||
DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsPerPageDoughnut:
|
||||
class: DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsPerPageDoughnut
|
||||
arguments: [pageViewsPerPageDoughnut]
|
||||
class: 'DanielSiepmann\Tracking\Dashboard\Widgets\PageViewsPerPageDoughnut'
|
||||
arguments:
|
||||
- 'pageViewsPerPageDoughnut'
|
||||
- '@DanielSiepmann\Tracking\DI\QueryBuilder\PageView'
|
||||
tags:
|
||||
- name: dashboard.widget
|
||||
identifier: pageViewsPerPageDoughnut
|
||||
widgetGroups: tracking
|
||||
- name: 'dashboard.widget'
|
||||
identifier: 'pageViewsPerPageDoughnut'
|
||||
widgetGroups: 'tracking'
|
||||
|
|
23
readme.rst
Normal file
23
readme.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
Todos
|
||||
=====
|
||||
|
||||
#. Add command that will iterate over all DB entries and remove ones matching the black list rule.
|
||||
E.g. if rule is adjusted in meanwhile.
|
||||
|
||||
#. Add further widgets.
|
||||
|
||||
#. Top 404 requests (Collect them to show them).
|
||||
|
||||
#. Grouped by user agents.
|
||||
|
||||
#. Move bot detection to another rule.
|
||||
|
||||
#. Keep indexing those requests, but mark them as bot and separate them in widgets.
|
||||
|
||||
#. Provide an overview of crawls as widgets. E.g. to allow fine grained robots.txt.
|
||||
|
||||
#. Add information to Admin Panel.
|
||||
|
||||
#. Add operating System
|
||||
|
||||
#. Another Symfony Expression which returns the OS ("Ubuntu", "Macintosh", "Android", "iPhone", "Windows")
|
Loading…
Reference in a new issue