Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<module>
<name>dashtrends</name>
<displayName><![CDATA[Dashboard Trends]]></displayName>
<version><![CDATA[2.1.3]]></version>
<description><![CDATA[Adds a block whith the evolution of your stores main numbers along with a graphic.]]></description>
<version><![CDATA[3.0.0]]></version>
<description><![CDATA[Enrich your dashboard: display a graphical representation of your store&rsquo;s development.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[dashboard]]></tab>
<tab><![CDATA[administration]]></tab>
<is_configurable>0</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
Expand Down
64 changes: 63 additions & 1 deletion dashtrends.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
use Twig\Environment;

if (!defined('_PS_VERSION_')) {
exit;
}
Expand All @@ -44,7 +46,7 @@ public function __construct()
{
$this->name = 'dashtrends';
$this->tab = 'administration';
$this->version = '2.1.3';
$this->version = '3.0.0';
$this->author = 'PrestaShop';

parent::__construct();
Expand All @@ -59,6 +61,8 @@ public function install()
&& $this->registerHook('dashboardZoneTwo')
&& $this->registerHook('dashboardData')
&& $this->registerHook('actionAdminControllerSetMedia')
// Modern counterpart of dashboardZoneTwo, registered alongside it (#41971).
&& $this->registerHook('displayAdminDashboardZoneTwo')
;
}

Expand All @@ -78,6 +82,64 @@ public function hookDashboardZoneTwo($params)
return $this->display(__FILE__, 'dashboard_zone_two.tpl');
}

/**
* Modern counterpart of hookDashboardZoneTwo() for the Symfony dashboard (#41971).
* No comparison-period overlay: the new hook isn't passed compare_from/compare_to.
*/
public function hookDisplayAdminDashboardZoneTwo(array $params)
{
$tmp_data = $this->getData($params['date_from'], $params['date_to']);
$dashboardData = $this->refineData($params['date_from'], $params['date_to'], $tmp_data);

return $this->render('zone_two.html.twig', [
'title' => $this->trans('Sales trend', [], 'Modules.Dashtrends.Admin'),
'chartId' => 'dashtrends-sales',
'chartConfig' => $this->getSalesChartConfig($dashboardData),
]);
}

private function render(string $template, array $params = []): string
Comment thread
jolelievre marked this conversation as resolved.
{
$twig = $this->get('twig');
if (!$twig instanceof Environment) {
return '';
}

return $twig->render('@Modules/dashtrends/views/templates/admin/' . $template, $params);
}

/**
* Plain Chart.js config, no dataset color (auto-applied by the core psColors plugin).
*/
private function getSalesChartConfig(array $dashboardData): array
{
$labels = [];
$data = [];
foreach ($dashboardData['sales'] as $timestamp => $value) {
$labels[] = Tools::displayDate(date('Y-m-d', (int) $timestamp));
$data[] = round((float) $value, 2);
}

return [
'type' => 'line',
'data' => [
'labels' => $labels,
'datasets' => [
[
'label' => $this->trans('Sales', [], 'Admin.Global'),
'data' => $data,
'fill' => true,
'tension' => 0.3,
],
],
],
'options' => [
'plugins' => ['legend' => ['position' => 'bottom']],
'scales' => ['y' => ['beginAtZero' => true]],
],
];
}

protected function getData($date_from, $date_to)
{
// We need the following figures to calculate our stats
Expand Down
10 changes: 9 additions & 1 deletion tests/php/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Base PHPStan configuration for the module
# This file is included by version-specific configs
# This file is included by version-specific configs

parameters:
# Reset to auto-detection: the shared CI action injects a phpVersion computed from the
# matrix's php-version input, which some older PrestaShop releases' pinned PHPStan can't
# parse once that input reaches a version newer than its own release date (PHPStan's
# phpVersion schema is capped at whatever PHP existed when that PHPStan version shipped).
# Included last, so this wins over the injected value (see PrestaShop/.github#phpstan).
phpVersion: null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the recent changes in the shared action, we shouldn't need this anymore, no?

34 changes: 34 additions & 0 deletions upgrade/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
33 changes: 33 additions & 0 deletions upgrade/upgrade-2.2.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_2_2_0($object)
{
return $object->registerHook('displayAdminDashboardZoneTwo');
}
34 changes: 34 additions & 0 deletions views/templates/admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
11 changes: 11 additions & 0 deletions views/templates/admin/zone_two.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#
# For the full copyright and license information, please view the
# docs/licenses/LICENSE.txt file that was distributed with this source code.
#}
{{ component('ChartCard', {
chartId: chartId,
config: chartConfig,
height: 300,
title: title,
icon: 'show_chart',
}) }}
Loading