Skip to content

Commit

Permalink
Merge pull request #8 from xima-media/release-11.0.4
Browse files Browse the repository at this point in the history
release 11.0.4
  • Loading branch information
github-actions[bot] committed Dec 3, 2023
2 parents 406b3af + 16c489f commit 6f1133e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
38 changes: 36 additions & 2 deletions Classes/Widgets/LineChartWidget.php
Expand Up @@ -18,6 +18,7 @@
namespace Xima\XmGoaccess\Widgets;

use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Dashboard\Widgets\AdditionalCssInterface;
use TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface;
use TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface;
Expand Down Expand Up @@ -59,6 +60,11 @@ class LineChartWidget implements WidgetInterface, EventDataInterface, Additional
*/
private $options;

/**
* @var int
*/
private $typo3Version;

public function __construct(
WidgetConfigurationInterface $configuration,
LineChartDataProvider $dataProvider,
Expand All @@ -69,11 +75,13 @@ public function __construct(
$this->dataProvider = $dataProvider;
$this->view = $view;
$this->options = $options;

$this->dataProvider->setGoaccessType($this->options['goaccessType']);
$this->typo3Version = (int)VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version())['version_main'];
}

public function renderWidgetContent(): string
{
$this->dataProvider->setGoaccessType($this->options['goaccessType']);
$this->view->setTemplate('Widget/ChartWidget');
$this->view->assignMultiple([
'options' => $this->options,
Expand All @@ -84,7 +92,7 @@ public function renderWidgetContent(): string

public function getEventData(): array
{
return [
$data = [
'graphConfig' => [
'type' => 'line',
'options' => [
Expand Down Expand Up @@ -123,15 +131,41 @@ public function getEventData(): array
'data' => $this->dataProvider->getChartData(),
],
];

if ($this->typo3Version >= 12) {
$data['graphConfig']['options']['scales'] = [
'y' => [
'id' => 'right',
'position' => 'right',
'display' => 'auto',
'ticks' => [
'beginAtZero' => true,
'sampleSize' => 4,
'autoSkip' => true,
],
],
];
}

return $data;
}

public function getCssFiles(): array
{
if ($this->typo3Version >= 12) {
return [];
}
return ['EXT:dashboard/Resources/Public/Css/Contrib/chart.css'];
}

public function getJavaScriptModuleInstructions(): array
{
if ($this->typo3Version >= 12) {
return [
JavaScriptModuleInstruction::create('@typo3/dashboard/contrib/chartjs.js'),
JavaScriptModuleInstruction::create('@typo3/dashboard/chart-initializer.js'),
];
}
return [
JavaScriptModuleInstruction::forRequireJS('TYPO3/CMS/Dashboard/Contrib/chartjs'),
JavaScriptModuleInstruction::forRequireJS('TYPO3/CMS/Dashboard/ChartInitializer'),
Expand Down
12 changes: 10 additions & 2 deletions Classes/Widgets/Provider/LineChartDataProvider.php
Expand Up @@ -2,13 +2,13 @@

namespace Xima\XmGoaccess\Widgets\Provider;

use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Dashboard\WidgetApi;
use TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface;

class LineChartDataProvider extends AbstractGoaccessDataProvider implements ChartDataProviderInterface
{
/**
* @param string $type
* @param int $days
* @return array{labels: string[], hits: int[], visitors: int[], bytes: int[]}
* @throws \Exception
Expand Down Expand Up @@ -65,7 +65,7 @@ public function getChartData(): array
{
$data = $this->getGoaccessChartData();

return [
$data = [
'labels' => $data['labels'],
'datasets' => [
[
Expand All @@ -86,5 +86,13 @@ public function getChartData(): array
],
],
];

$typo3Version = (int)VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version())['version_main'];
if ($typo3Version >= 12) {
$data['datasets'][0]['fill'] = 'origin';
$data['datasets'][1]['fill'] = 'origin';
}

return $data;
}
}
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -21,7 +21,8 @@
"squizlabs/php_codesniffer": "^3.4",
"friendsofphp/php-cs-fixer": "^3.3",
"vimeo/psalm": "^4.0",
"phpstan/phpstan": "^1.6"
"phpstan/phpstan": "^1.6",
"helhum/typo3-console": "^8.1"
},
"extra": {
"typo3/cms": {
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Expand Up @@ -10,7 +10,7 @@
'state' => 'stable',
'internal' => '',
'uploadfolder' => '0',
'version' => '11.0.3',
'version' => '11.0.4',
'constraints' => [
'depends' => [
'typo3' => '11.0.0-12.99.99',
Expand Down

0 comments on commit 6f1133e

Please sign in to comment.