2020-02-26 22:59:03 +01:00
|
|
|
<?php
|
|
|
|
|
2022-09-16 13:53:49 +02:00
|
|
|
declare(strict_types=1);
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-09-16 13:53:49 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Dashboard\Provider;
|
|
|
|
|
2020-02-26 22:59:03 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2021-08-16 09:56:19 +02:00
|
|
|
* @var Demand
|
2020-04-07 17:54:18 +02:00
|
|
|
*/
|
2021-08-16 09:56:19 +02:00
|
|
|
private $demand;
|
2020-08-03 12:33:02 +02:00
|
|
|
|
2020-02-26 22:59:03 +01:00
|
|
|
public function __construct(
|
|
|
|
QueryBuilder $queryBuilder,
|
2021-08-16 09:56:19 +02:00
|
|
|
Demand $demand
|
2020-02-26 22:59:03 +01:00
|
|
|
) {
|
|
|
|
$this->queryBuilder = $queryBuilder;
|
2021-08-16 09:56:19 +02:00
|
|
|
$this->demand = $demand;
|
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
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
$constraints = $this->demand->getConstraints(
|
|
|
|
$this->queryBuilder,
|
|
|
|
'tx_tracking_pageview'
|
|
|
|
);
|
2020-02-26 22:59:03 +01:00
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
$this->demand->addJoins($this->queryBuilder, 'tx_tracking_pageview');
|
2020-08-03 12:33:02 +02:00
|
|
|
|
2020-02-26 22:59:03 +01:00
|
|
|
$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-07-30 12:22:32 +02:00
|
|
|
->addOrderBy('uid', 'desc')
|
2021-08-16 09:56:19 +02:00
|
|
|
->setMaxResults($this->demand->getMaxResults());
|
2020-02-26 22:59:03 +01:00
|
|
|
|
|
|
|
if ($constraints !== []) {
|
2021-05-21 18:49:38 +02:00
|
|
|
$this->queryBuilder->where(...$constraints);
|
2020-02-26 22:59:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$items = $this->queryBuilder->execute()->fetchAll();
|
|
|
|
foreach ($items as $item) {
|
2021-11-25 14:40:00 +01:00
|
|
|
if (is_array($item) === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|