From d575ba82739c8482ca118d5291ddb12c6c7a1ac9 Mon Sep 17 00:00:00 2001 From: Jerome Nadaud Date: Fri, 11 Oct 2013 18:30:05 +0200 Subject: [PATCH] // Adding compare dates to date range picker --- .../template/helpers/calendar/calendar.tpl | 16 +++- classes/Employee.php | 7 ++ classes/helper/HelperCalendar.php | 74 ++++++++++++++----- .../admin/AdminDashboardController.php | 20 ++++- install-dev/upgrade/sql/1.6.0.1.sql | 4 +- 5 files changed, 98 insertions(+), 23 deletions(-) diff --git a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl index adee2219b..40bddca6a 100644 --- a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl +++ b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl @@ -29,9 +29,19 @@
- + - + +
+
+
+
{l s='Compare to'}
+
+
+ + + +

@@ -40,7 +50,7 @@ {l s='Cancel'} - diff --git a/classes/Employee.php b/classes/Employee.php index 8c6397337..3065dca74 100644 --- a/classes/Employee.php +++ b/classes/Employee.php @@ -52,6 +52,9 @@ class EmployeeCore extends ObjectModel public $stats_date_from; public $stats_date_to; + public $stats_compare_from; + public $stats_compare_to; + /** @var string Display back office background in the specified color */ public $bo_color; @@ -96,6 +99,8 @@ class EmployeeCore extends ObjectModel 'bo_menu' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'stats_date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'stats_date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'stats_compare_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'stats_compare_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); @@ -105,6 +110,8 @@ class EmployeeCore extends ObjectModel 'last_passwd_gen' => array('setter' => null), 'stats_date_from' => array('setter' => null), 'stats_date_to' => array('setter' => null), + 'stats_compare_from' => array('setter' => null), + 'stats_compare_to' => array('setter' => null), 'passwd' => array('setter' => 'setWsPasswd'), ), ); diff --git a/classes/helper/HelperCalendar.php b/classes/helper/HelperCalendar.php index f0c6f41ff..4d74173ea 100644 --- a/classes/helper/HelperCalendar.php +++ b/classes/helper/HelperCalendar.php @@ -29,9 +29,11 @@ class HelperCalendarCore extends Helper const DEFAULT_DATE_FORMAT = 'dd-mm-yyyy'; private $_actions; + private $_compare_date_from; + private $_compare_date_to; private $_date_format; - private $_from_date; - private $_to_date; + private $_date_from; + private $_date_to; public function __construct() { @@ -57,6 +59,40 @@ class HelperCalendarCore extends Helper return $this->_actions; } + public function setCompareDateFrom($value) + { + if (!is_string($value)) + throw new PrestaShopException('Date format must be string'); + + $this->_compare_date_from = $value; + return $this; + } + + public function getCompareDateFrom() + { + if (!isset($this->_compare_date_from)) + $this->_compare_date_from = date('d-m-Y', strtotime("-31 days")); + + return $this->_compare_date_from; + } + + public function setCompareDateTo($value) + { + if (!is_string($value)) + throw new PrestaShopException('Date format must be string'); + + $this->_compare_date_to = $value; + return $this; + } + + public function getCompareDateTo() + { + if (!isset($this->_compare_date_to)) + $this->_compare_date_to = date('d-m-Y'); + + return $this->_compare_date_to; + } + public function setDateFormat($value) { if (!is_string($value)) @@ -74,38 +110,38 @@ class HelperCalendarCore extends Helper return $this->_date_format; } - public function setFromDate($value) + public function setDateFrom($value) { if (!is_string($value)) throw new PrestaShopException('Date format must be string'); - $this->_from_date = $value; + $this->_date_from = $value; return $this; } - public function getFromDate() + public function getDateFrom() { - if (!isset($this->_from_date)) - $this->_from_date = date('d-m-Y', strtotime("-31 days")); + if (!isset($this->_date_from)) + $this->_date_from = date('d-m-Y', strtotime("-31 days")); - return $this->_from_date; + return $this->_date_from; } - public function setToDate($value) + public function setDateTo($value) { if (!is_string($value)) throw new PrestaShopException('Date format must be string'); - $this->_to_date = $value; + $this->_date_to = $value; return $this; } - public function getToDate() + public function getDateTo() { - if (!isset($this->_to_date)) - $this->_to_date = date('d-m-Y'); + if (!isset($this->_date_to)) + $this->_date_to = date('d-m-Y'); - return $this->_to_date; + return $this->_date_to; } public function addAction($action) @@ -142,10 +178,12 @@ class HelperCalendarCore extends Helper $this->tpl = $this->createTemplate($this->base_tpl); $this->tpl->assign(array( - 'date_format' => $this->getDateFormat(), - 'from_date' => $this->getFromDate(), - 'to_date' => $this->getToDate(), - 'actions' => $this->getActions() + 'date_format' => $this->getDateFormat(), + 'date_from' => $this->getDateFrom(), + 'date_to' => $this->getDateTo(), + 'compare_date_from' => $this->getCompareDateFrom(), + 'compare_date_to' => $this->getCompareDateTo(), + 'actions' => $this->getActions() )); $html .= parent::generate(); diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php index 2aedd77e1..9323e9954 100644 --- a/controllers/admin/AdminDashboardController.php +++ b/controllers/admin/AdminDashboardController.php @@ -152,7 +152,11 @@ class AdminDashboardControllerCore extends AdminController ); $calendar_helper = new HelperCalendar(); - + $calendar_helper->setDateFrom(Tools::getValue('date_from', $this->context->employee->stats_date_from)); + $calendar_helper->setDateTo(Tools::getValue('date_to', $this->context->employee->stats_date_to)); + $calendar_helper->setCompareDateFrom(Tools::getValue('compare_date_from', $this->context->employee->stats_compare_from)); + $calendar_helper->setCompareDateTo(Tools::getValue('compare_date_to', $this->context->employee->stats_compare_to)); + $this->tpl_view_vars = array( 'hookDashboardZoneOne' => Hook::exec('dashboardZoneOne'), 'hookDashboardZoneTwo' => Hook::exec('dashboardZoneTwo'), @@ -167,6 +171,20 @@ class AdminDashboardControllerCore extends AdminController ); return parent::renderView(); } + + public function postProcess() + { + if (Tools::isSubmit('submitDateRange')) + { + $this->context->employee->stats_date_from = Tools::getValue('date_from'); + $this->context->employee->stats_date_to = Tools::getValue('date_to'); + $this->context->employee->stats_compare_from = Tools::getValue('compare_date_from'); + $this->context->employee->stats_compare_to = Tools::getValue('compare_date_to'); + $this->context->employee->update(); + } + + parent::postProcess(); + } protected function getWarningDomainName() { diff --git a/install-dev/upgrade/sql/1.6.0.1.sql b/install-dev/upgrade/sql/1.6.0.1.sql index dd96716d9..952d590c3 100644 --- a/install-dev/upgrade/sql/1.6.0.1.sql +++ b/install-dev/upgrade/sql/1.6.0.1.sql @@ -63,4 +63,6 @@ INSERT INTO `PREFIX_hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) SELECT m.id_module, s.id_shop, h.id_hook, 2 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashproducts') AND h.name IN ('dashboardZoneTwo') ); -/* PHP:update_order_messages(); */; \ No newline at end of file +/* PHP:update_order_messages(); */; + +ALTER TABLE `PREFIX_employee` ADD `stats_compare_from` DATE NULL DEFAULT NULL AFTER `stats_date_to` , ADD `stats_compare_to` DATE NULL DEFAULT NULL AFTER `stats_compare_from` \ No newline at end of file