From b9305be60bc8db7cd17260eace90e9234d6a630b Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Tue, 8 Feb 2022 09:14:32 +0100 Subject: [PATCH] Fixed PHPCSFixer --- graphnvd3.php | 240 +++++++++++++++++++++++++------------------------- index.php | 19 ++-- 2 files changed, 129 insertions(+), 130 deletions(-) diff --git a/graphnvd3.php b/graphnvd3.php index a2d4510..86b0de2 100644 --- a/graphnvd3.php +++ b/graphnvd3.php @@ -23,94 +23,96 @@ * @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; +if (!defined('_PS_VERSION_')) { + exit; +} class GraphNvD3 extends ModuleGraphEngine { - private $_width; - private $_height; - private $_values; - private $_legend; - private $_titles; - - function __construct($type = null) - { - if ($type !== null) - return parent::__construct($type); - - $this->name = 'graphnvd3'; - $this->tab = 'administration'; - $this->version = '2.0.2'; - $this->author = 'PrestaShop'; - $this->need_instance = 0; - - Module::__construct(); - - $this->displayName = $this->trans('NVD3 Charts', array(), 'Modules.Graphnvd3.Admin'); - $this->description = $this->trans('Enable the NVD3 charting code for your own uses, providing you with ever so useful graphs.', array(), 'Modules.Graphnvd3.Admin'); - $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); - } - - function install() - { - return (parent::install() && $this->registerHook('GraphEngine') && $this->registerHook('actionAdminControllerSetMedia')); - } - - public function hookActionAdminControllerSetMedia($params) - { - $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); - $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); - - $this->context->controller->addJS(array( - _PS_JS_DIR_.'vendor/d3.v3.min.js', - __PS_BASE_URI__.$admin_webpath.'/themes/'.$this->context->employee->bo_theme.'/js/vendor/nv.d3.min.js', - )); - $this->context->controller->addCSS(__PS_BASE_URI__.$admin_webpath.'/themes/'.$this->context->employee->bo_theme.'/css/vendor/nv.d3.css'); - } - - public static function hookGraphEngine($params, $drawer) - { - static $divid = 1; - - if (strpos($params['width'], '%') !== false) - $params['width'] = (int)preg_replace('/\s*%\s*/', '', $params['width']).'%'; - else - $params['width'] = (int)$params['width'].'px'; - - $nvd3_func = array( - 'line' => ' + private $_width; + private $_height; + private $_values; + private $_legend; + private $_titles; + + public function __construct($type = null) + { + if ($type !== null) { + return parent::__construct($type); + } + + $this->name = 'graphnvd3'; + $this->tab = 'administration'; + $this->version = '2.0.2'; + $this->author = 'PrestaShop'; + $this->need_instance = 0; + + Module::__construct(); + + $this->displayName = $this->trans('NVD3 Charts', [], 'Modules.Graphnvd3.Admin'); + $this->description = $this->trans('Enable the NVD3 charting code for your own uses, providing you with ever so useful graphs.', [], 'Modules.Graphnvd3.Admin'); + $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; + } + + public function install() + { + return parent::install() && $this->registerHook('GraphEngine') && $this->registerHook('actionAdminControllerSetMedia'); + } + + public function hookActionAdminControllerSetMedia($params) + { + $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); + $admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath); + + $this->context->controller->addJS([ + _PS_JS_DIR_ . 'vendor/d3.v3.min.js', + __PS_BASE_URI__ . $admin_webpath . '/themes/' . $this->context->employee->bo_theme . '/js/vendor/nv.d3.min.js', + ]); + $this->context->controller->addCSS(__PS_BASE_URI__ . $admin_webpath . '/themes/' . $this->context->employee->bo_theme . '/css/vendor/nv.d3.css'); + } + + public static function hookGraphEngine($params, $drawer) + { + static $divid = 1; + + if (strpos($params['width'], '%') !== false) { + $params['width'] = (int) preg_replace('/\s*%\s*/', '', $params['width']) . '%'; + } else { + $params['width'] = (int) $params['width'] . 'px'; + } + + $nvd3_func = [ + 'line' => ' nv.models.lineChart()', - 'pie' => ' + 'pie' => ' nv.models.pieChart() .x(function(d) { return d.label; }) .y(function(d) { return d.value; }) .showLabels(true) - .showLegend(false)' - ); + .showLegend(false)', + ]; - return ' -
- + return ' +
+
'; - } - - public function createValues($values) - { - $this->_values = $values; - } - - public function setSize($width, $height) - { - $this->_width = $width; - $this->_height = $height; - } - - public function setLegend($legend) - { - $this->_legend = $legend; - } - - public function setTitles($titles) - { - $this->_titles = $titles; - } - - public function draw() - { - $array = array( - 'axisLabels' => array('xAxis' => $this->_titles['x'], 'yAxis' => $this->_titles['y']), - 'data' => array() - ); - - if (!isset($this->_values[0]) || !is_array($this->_values[0])) - { - $nvd3_values = array(); - if (Tools::getValue('type') == 'pie') - { - foreach ($this->_values as $x => $y) - $nvd3_values[] = array('label' => $this->_legend[$x], 'value' => $y); - $array['data'] = $nvd3_values; - } - else - { - foreach ($this->_values as $x => $y) - $nvd3_values[] = array('x' => $x, 'y' => $y); - $array['data'][] = array('values' => $nvd3_values, 'key' => $this->_titles['main']); - } - } - else - foreach ($this->_values as $layer => $gross_values) - { - $nvd3_values = array(); - foreach ($gross_values as $x => $y) - $nvd3_values[] = array('x' => $x, 'y' => $y); - $array['data'][] = array('values' => $nvd3_values, 'key' => $this->_titles['main'][$layer]); - } - echo preg_replace('/"([0-9]+)"/', '$1', json_encode($array)); - } + } + + public function createValues($values) + { + $this->_values = $values; + } + + public function setSize($width, $height) + { + $this->_width = $width; + $this->_height = $height; + } + + public function setLegend($legend) + { + $this->_legend = $legend; + } + + public function setTitles($titles) + { + $this->_titles = $titles; + } + + public function draw() + { + $array = [ + 'axisLabels' => ['xAxis' => $this->_titles['x'], 'yAxis' => $this->_titles['y']], + 'data' => [], + ]; + + if (!isset($this->_values[0]) || !is_array($this->_values[0])) { + $nvd3_values = []; + if (Tools::getValue('type') == 'pie') { + foreach ($this->_values as $x => $y) { + $nvd3_values[] = ['label' => $this->_legend[$x], 'value' => $y]; + } + $array['data'] = $nvd3_values; + } else { + foreach ($this->_values as $x => $y) { + $nvd3_values[] = ['x' => $x, 'y' => $y]; + } + $array['data'][] = ['values' => $nvd3_values, 'key' => $this->_titles['main']]; + } + } else { + foreach ($this->_values as $layer => $gross_values) { + $nvd3_values = []; + foreach ($gross_values as $x => $y) { + $nvd3_values[] = ['x' => $x, 'y' => $y]; + } + $array['data'][] = ['values' => $nvd3_values, 'key' => $this->_titles['main'][$layer]]; + } + } + echo preg_replace('/"([0-9]+)"/', '$1', json_encode($array)); + } } diff --git a/index.php b/index.php index c4ae07a..45df26c 100644 --- a/index.php +++ b/index.php @@ -23,13 +23,12 @@ * @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; \ No newline at end of file +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;