2020-10-13 19:21:27 +01:00
|
|
|
<?php
|
|
|
|
|
2021-03-25 11:01:14 +00:00
|
|
|
namespace App\Statistics\LegacyHandler;
|
2020-10-13 19:21:27 +01:00
|
|
|
|
|
|
|
use App\Entity\Statistic;
|
2021-03-25 11:01:14 +00:00
|
|
|
use App\Data\LegacyHandler\PresetDataHandlers\SubpanelDataQueryHandler;
|
2020-10-13 19:21:27 +01:00
|
|
|
use App\Service\StatisticsProviderInterface;
|
2021-03-11 11:15:48 +00:00
|
|
|
use Psr\Log\LoggerAwareInterface;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2020-10-13 19:21:27 +01:00
|
|
|
|
2021-03-11 11:15:48 +00:00
|
|
|
class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProviderInterface, LoggerAwareInterface
|
2020-10-13 19:21:27 +01:00
|
|
|
{
|
2020-12-14 11:02:40 +00:00
|
|
|
use StatisticsHandlingTrait;
|
|
|
|
|
2020-10-13 19:21:27 +01:00
|
|
|
public const KEY = 'default';
|
|
|
|
|
2021-03-11 11:15:48 +00:00
|
|
|
/**
|
|
|
|
* @var LoggerInterface
|
|
|
|
*/
|
|
|
|
protected $logger;
|
|
|
|
|
2020-10-13 19:21:27 +01:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getKey(): string
|
|
|
|
{
|
|
|
|
return self::KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2020-12-14 11:02:40 +00:00
|
|
|
public function getData(array $query): Statistic
|
2020-10-13 19:21:27 +01:00
|
|
|
{
|
2021-02-11 18:38:40 +00:00
|
|
|
|
2021-02-19 09:17:36 +00:00
|
|
|
$subpanel = $query['params']['subpanel'] ?? $query['key'];
|
2021-02-11 18:38:40 +00:00
|
|
|
|
2020-12-14 11:02:40 +00:00
|
|
|
[$module, $id] = $this->extractContext($query);
|
2020-12-08 16:15:13 +00:00
|
|
|
if (empty($module) || empty($id)) {
|
2020-12-14 11:02:40 +00:00
|
|
|
return $this->getEmptyResponse(self::KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$this->startLegacyApp();
|
|
|
|
|
|
|
|
$queries = $this->getQueries($module, $id, $subpanel);
|
2021-02-11 18:38:40 +00:00
|
|
|
|
2021-03-11 11:15:48 +00:00
|
|
|
if (empty($queries)) {
|
|
|
|
$this->logger->error('default-statistic: No queries found.', ['query' => $query]);
|
|
|
|
|
|
|
|
return $this->getErrorResponse(self::KEY);
|
|
|
|
}
|
|
|
|
|
2020-12-14 11:02:40 +00:00
|
|
|
$parts = $queries[0];
|
|
|
|
$parts['select'] = 'SELECT COUNT(*) as value';
|
2020-10-13 19:21:27 +01:00
|
|
|
|
2020-12-14 11:02:40 +00:00
|
|
|
$dbQuery = $this->joinQueryParts($parts);
|
|
|
|
$result = $this->fetchRow($dbQuery);
|
|
|
|
$statistic = $this->buildSingleValueResponse(self::KEY, 'int', $result);
|
2021-02-11 18:38:40 +00:00
|
|
|
|
2021-03-23 13:21:18 +00:00
|
|
|
$this->addMetadata($statistic, ['tooltip_title_key' => 'LBL_DEFAULT_TOTAL_TOOLTIP']);
|
|
|
|
$this->addMetadata($statistic, ['descriptionKey' => 'LBL_DEFAULT_TOTAL']);
|
2020-12-14 11:02:40 +00:00
|
|
|
$this->close();
|
2021-02-11 18:38:40 +00:00
|
|
|
|
2020-10-13 19:21:27 +01:00
|
|
|
return $statistic;
|
|
|
|
}
|
2021-03-11 11:15:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function setLogger(LoggerInterface $logger)
|
|
|
|
{
|
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
2020-10-13 19:21:27 +01:00
|
|
|
}
|