diff --git a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
index bbd22c965..dd9e8940d 100644
--- a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
+++ b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl
@@ -70,37 +70,4 @@
-
-
-
+
\ No newline at end of file
diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js
index 3dd5d3eab..9817ca7d5 100644
--- a/js/admin-dashboard.js
+++ b/js/admin-dashboard.js
@@ -179,6 +179,16 @@ function data_chart(widget_name, charts)
window[charts[chart_id].chart_type](widget_name, charts[chart_id]);
}
+function data_list_small(widget_name, data)
+{
+ for (var data_id in data)
+ {
+ for (var item in data[data_id])
+ $('#'+data_id+' ').append('
'+item+''+data[data_id][item]+'');
+ $('#'+data_id+', #'+widget_name).closest('section').removeClass('loading');
+ }
+}
+
function getBlogRss()
{
$.ajax({
diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php
index 81708c94c..73c27836b 100644
--- a/modules/dashactivity/dashactivity.php
+++ b/modules/dashactivity/dashactivity.php
@@ -53,11 +53,17 @@ class Dashactivity extends Module
|| !$this->registerHook('actionObjectCustomerMessageAddAfter')
|| !$this->registerHook('actionObjectCustomerThreadAddAfter')
|| !$this->registerHook('actionObjectOrderReturnAddAfter')
-
+ || !$this->registerHook('displayBackOfficeHeader')
)
return false;
return true;
}
+
+ public function hookDisplayBackOfficeHeader()
+ {
+ if (get_class($this->context->controller) == 'AdminDashboardController')
+ $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js');
+ }
public function hookDashboardZoneOne($params)
{
@@ -196,10 +202,56 @@ class Dashactivity extends Module
),
'data_trends' => array(
'orders_trends' => array('way' => 'down', 'value' => 0.42),
- )
+ ),
+ 'data_list_small' => array(
+ 'dash_traffic_source' => $this->getReferer($params['date_from'], $params['date_to']),
+ ),
+ 'data_chart' => array(
+ 'dash_trends_chart1' => $this->getChartTrafficSource($params['date_from'], $params['date_to']),
+ ),
);
}
+ public function getChartTrafficSource($date_from, $date_to)
+ {
+ $referers = $this->getReferer($date_from, $date_to);
+ $return = array('chart_type' => 'pie_chart_trends', 'data' => array());
+ foreach ($referers as $referer_name => $nbr)
+ $return['data'][] = array('key' => $referer_name, 'y' => $nbr);
+
+ return $return;
+ }
+
+ public function getReferer($date_from, $date_to, $limit = 10)
+ {
+ $directLink = $this->l('Direct link');
+ $sql = 'SELECT http_referer
+ FROM '._DB_PREFIX_.'connections
+ WHERE 1
+ '.Shop::addSqlRestriction().'
+ AND date_add BETWEEN '.$date_from.' AND '.$date_to.'
+ LIMIT 0, '.(int)$limit;
+
+ $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
+ $websites = array($directLink => 0);
+
+ while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
+ {
+ if (!isset($row['http_referer']) || empty($row['http_referer']))
+ ++$websites[$directLink];
+ else
+ {
+ $website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
+ if (!isset($websites[$website]))
+ $websites[$website] = 1;
+ else
+ ++$websites[$website];
+ }
+ }
+ arsort($websites);
+ return $websites;
+ }
+
public function hookActionObjectCustomerMessageAddAfter($params)
{
return $this->hookActionObjectOrderAddAfter($params);
diff --git a/modules/dashactivity/views/js/dashactivity.js b/modules/dashactivity/views/js/dashactivity.js
new file mode 100644
index 000000000..b145c04b7
--- /dev/null
+++ b/modules/dashactivity/views/js/dashactivity.js
@@ -0,0 +1,18 @@
+function pie_chart_trends(widget_name, chart_details)
+{
+ nv.addGraph(function() {
+ var chart = nv.models.pieChart()
+ .x(function(d) { return d.key })
+ .y(function(d) { return d.y })
+ .color(d3.scale.category10().range())
+ .donut(true)
+ .showLabels(false)
+ .showLegend(false);
+ d3.select("#dash_traffic_chart2 svg")
+ .datum(chart_details.data)
+ .transition().duration(1200)
+ .call(chart);
+ nv.utils.windowResize(chart.update);
+ return chart;
+ });
+}
\ No newline at end of file
diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl
index a415de819..9f3b7351e 100644
--- a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl
+++ b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl
@@ -166,19 +166,7 @@
{l s='Traffic Sources'}
-
- -
- {l s='Direct Link'}
- 120
-
- -
- google.com
- 75
-
- -
- facebook.com
- 32
-
+