2020-02-26 22:59:03 +01:00
|
|
|
<?php
|
|
|
|
|
2020-04-07 17:54:18 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Dashboard\Provider;
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use TYPO3\CMS\Core\Database\Connection;
|
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
2020-04-17 16:16:19 +02:00
|
|
|
use TYPO3\CMS\Dashboard\Widgets\ListDataProviderInterface;
|
2020-02-26 22:59:03 +01:00
|
|
|
|
2020-04-07 17:54:18 +02:00
|
|
|
class NewestPageviews implements ListDataProviderInterface
|
2020-02-26 22:59:03 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var QueryBuilder
|
|
|
|
*/
|
2020-04-07 17:54:18 +02:00
|
|
|
private $queryBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $maxResults;
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
/**
|
2020-04-07 17:54:18 +02:00
|
|
|
* @var array
|
2020-02-26 22:59:03 +01:00
|
|
|
*/
|
2020-04-07 17:54:18 +02:00
|
|
|
private $blackListedPages;
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
QueryBuilder $queryBuilder,
|
2020-04-07 17:54:18 +02:00
|
|
|
int $maxResults = 6,
|
|
|
|
array $blackListedPages = []
|
2020-02-26 22:59:03 +01:00
|
|
|
) {
|
|
|
|
$this->queryBuilder = $queryBuilder;
|
2020-04-07 17:54:18 +02:00
|
|
|
$this->maxResults = $maxResults;
|
|
|
|
$this->blackListedPages = $blackListedPages;
|
2020-02-26 22:59:03 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 17:54:18 +02:00
|
|
|
public function getItems(): array
|
2020-02-26 22:59:03 +01:00
|
|
|
{
|
2020-04-07 17:54:18 +02:00
|
|
|
$preparedItems = [];
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
$constraints = [];
|
2020-04-07 17:54:18 +02:00
|
|
|
if (count($this->blackListedPages)) {
|
2020-02-26 22:59:03 +01:00
|
|
|
$constraints[] = $this->queryBuilder->expr()->notIn(
|
|
|
|
'tx_tracking_pageview.pid',
|
|
|
|
$this->queryBuilder->createNamedParameter(
|
2020-04-07 17:54:18 +02:00
|
|
|
$this->blackListedPages,
|
2020-02-26 22:59:03 +01:00
|
|
|
Connection::PARAM_INT_ARRAY
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->queryBuilder
|
2020-04-07 17:54:18 +02:00
|
|
|
->select('url', 'user_agent')
|
2020-02-26 22:59:03 +01:00
|
|
|
->from('tx_tracking_pageview')
|
2020-02-26 23:14:04 +01:00
|
|
|
->orderBy('crdate', 'desc')
|
2020-04-07 17:54:18 +02:00
|
|
|
->setMaxResults($this->maxResults);
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
if ($constraints !== []) {
|
|
|
|
$this->queryBuilder->where(... $constraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $this->queryBuilder->execute()->fetchAll();
|
|
|
|
foreach ($items as $item) {
|
2020-04-07 17:54:18 +02:00
|
|
|
$preparedItems[] = sprintf(
|
|
|
|
'%s - %s',
|
|
|
|
$item['url'],
|
|
|
|
$item['user_agent']
|
|
|
|
);
|
2020-02-26 22:59:03 +01:00
|
|
|
}
|
2020-04-07 17:54:18 +02:00
|
|
|
|
|
|
|
return $preparedItems;
|
2020-02-26 22:59:03 +01:00
|
|
|
}
|
|
|
|
}
|