From 5e0ca47073f17c39262534d0bc268cc5829779f2 Mon Sep 17 00:00:00 2001 From: lBrieu Date: Mon, 29 Aug 2011 15:35:57 +0000 Subject: [PATCH] [+] Allows to add notifications on the shop (backoffice only) --- classes/Notification.php | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 classes/Notification.php diff --git a/classes/Notification.php b/classes/Notification.php new file mode 100644 index 000000000..ac75cedc9 --- /dev/null +++ b/classes/Notification.php @@ -0,0 +1,63 @@ + + * @copyright PrestaShop + * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 + * @version 1.2 + * + `id_push_notification` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `tab` INT UNSIGNED NULL, + `link_to_push` VARCHAR(250) NULL, + `type` VARCHAR(250) NULL, + `date` DATETIME, + */ + +class Notification +{ + public $types; + + public function __construct() + { + $this->types = array('order', 'message', 'customer'); + } + + public function getLastElements() + { + global $cookie; + $notifications = array(); + $employee_infos = Db::getInstance()->getRow('SELECT id_last_order, id_last_message, id_last_customer FROM `'._DB_PREFIX_.'employee` WHERE `id_employee` = '.$cookie->id_employee); + + foreach ($this->types as $type) + { + $notifications[$type] = Notification::getLastElementsIdsByType($type, $employee_infos['id_last_'.$type]); + } + + return $notifications; + } + + public static function getLastElementsIdsByType($type, $id_last_element) + { + return Db::getInstance()->ExecuteS('SELECT id_'.$type.' FROM `'._DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'` WHERE `id_'.$type.'` > '.$id_last_element); + } + + public function updateEmployeeLastElement($type) + { + global $cookie; + + if (in_array($type, $this->types)) + { + // We update the last item viewed + Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'employee` SET `id_last_'.$type.'` = (SELECT MAX(`id_'.$type.'`) FROM `'. + _DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'`) WHERE `id_employee` = '.$cookie->id_employee); + return true; + } else { + return false; + } + } +} +?>