diff --git a/modules/graphnvd3/config.xml b/modules/graphnvd3/config.xml new file mode 100644 index 000000000..7dee6998a --- /dev/null +++ b/modules/graphnvd3/config.xml @@ -0,0 +1,12 @@ + + + graphnvd3 + + + + + + 0 + 0 + + \ No newline at end of file diff --git a/modules/graphnvd3/graphnvd3.php b/modules/graphnvd3/graphnvd3.php new file mode 100644 index 000000000..bf0d25e40 --- /dev/null +++ b/modules/graphnvd3/graphnvd3.php @@ -0,0 +1,170 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +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 = 1.0; + $this->author = 'PrestaShop'; + $this->need_instance = 0; + + Module::__construct(); + + $this->displayName = $this->l('NVD3 Charts'); + $this->description = ''; + } + + 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.js', + __PS_BASE_URI__.$admin_webpath.'/themes/'.$this->context->employee->bo_theme.'/js/vendor/nv.d3.js', + )); + $this->context->controller->addCSS(__PS_BASE_URI__.$admin_webpath.'/themes/'.$this->context->employee->bo_theme.'/css/nv.d3.css'); + } + + public static function hookGraphEngine($params, $drawer) + { + static $divid = 1; + + $nvd3_func = array( + 'line' => ' + nv.models.lineChart()', + 'pie' => ' + nv.models.pieChart() + .x(function(d) {return d.label}) + .y(function(d) {return d.value}) + .showLabels(true) + .showLegend(false)' + ); + + 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); + 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]); + } + die(preg_replace('/"([0-9]+)"/', '$1', Tools::jsonEncode($array))); + } +} \ No newline at end of file diff --git a/modules/graphnvd3/index.php b/modules/graphnvd3/index.php new file mode 100644 index 000000000..3f6561f72 --- /dev/null +++ b/modules/graphnvd3/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +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