From 6a15d87683ac22f763a1f57cc66d3fa5126b2a6b Mon Sep 17 00:00:00 2001 From: Tiago Zimmermann Date: Wed, 20 Apr 2016 10:47:27 -0300 Subject: [PATCH] Notification --- install/database/schema.sql | 1 + install/database/system_data.sql | 2 +- lib/Snep/Notifications.php | 21 +++++++++++++++++++-- modules/default/controllers/IndexController.php | 40 +++++++++++++++++++++++++++++----------- modules/default/controllers/NotificationsController.php | 4 ---- modules/default/views/layouts/layout.phtml | 16 +++++----------- modules/default/views/scripts/notifications/index.phtml | 5 ++++- 7 files changed, 59 insertions(+), 30 deletions(-) diff --git a/install/database/schema.sql b/install/database/schema.sql index 6a40c66..4b07ec7 100644 --- a/install/database/schema.sql +++ b/install/database/schema.sql @@ -749,6 +749,7 @@ CREATE TABLE IF NOT EXISTS `core_notifications` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_itc` int(11), `title` varchar(255) NOT NULL, + `from` varchar(128) DEFAULT "OPENS", `message` text NOT NULL, `creation_date` datetime NOT NULL, `read` boolean DEFAULT false, diff --git a/install/database/system_data.sql b/install/database/system_data.sql index 54f5313..accb61a 100644 --- a/install/database/system_data.sql +++ b/install/database/system_data.sql @@ -88,4 +88,4 @@ INSERT INTO `regras_negocio` VALUES ('',0,'Internas - Ramal para Ramal','G:all', INSERT INTO `regras_negocio_actions` VALUES (1,0,'PBX_Rule_Action_CCustos'),(1,1,'PBX_Rule_Action_DiscarRamal'); INSERT INTO `regras_negocio_actions_config` VALUES (1,0,'ccustos','9'),(1,1,'allow_voicemail','false'),(1,1,'dial_flags','twk'),(1,1,'dial_timeout','60'),(1,1,'diff_ring','false'),(1,1,'dont_overflow','false'),(1,1,'resolv_agent','false'); -INSERT INTO `core_config` (`config_module`, `config_name`, `config_value`) VALUES ('CORE', 'HOST_NOTIFICATION', 'http://api.opens.com.br:3003/notifications/last_id/'); +INSERT INTO `core_config` (`config_module`, `config_name`, `config_value`) VALUES ('CORE', 'HOST_NOTIFICATION', 'http://api.opens.com.br:3003/notifications'); diff --git a/lib/Snep/Notifications.php b/lib/Snep/Notifications.php index 68dcb87..bb59596 100644 --- a/lib/Snep/Notifications.php +++ b/lib/Snep/Notifications.php @@ -174,14 +174,17 @@ class Snep_Notifications { * @param $title * @param $notification */ - public function addNotification($title,$message,$id_itc) { + public function addNotification($title,$message,$id_itc,$costumer) { $db = Zend_Registry::get('db'); + ($costumer == 68) ? $from = "OPENS" : $from = "INTEGRADOR"; + $insert_data = array('title' => $title, 'message' => $message, 'id_itc' => $id_itc, - 'creation_date' => date('Y-m-d H:i:s')); + 'creation_date' => date('Y-m-d H:i:s'), + 'from' => $from); $db->insert('core_notifications', $insert_data); @@ -238,5 +241,19 @@ class Snep_Notifications { } } + /** + * Method to update a lastNotification + * @param $id + */ + public function updateLastNotification($id) { + + $db = Zend_Registry::get('db'); + + $update_data = array('config_value' => $id); + + $db->update("core_config", $update_data, "config_name = 'LAST_ID_NOTIFICATION'"); + + } + } ?> diff --git a/modules/default/controllers/IndexController.php b/modules/default/controllers/IndexController.php index add506a..3ce0a00 100644 --- a/modules/default/controllers/IndexController.php +++ b/modules/default/controllers/IndexController.php @@ -199,7 +199,7 @@ class IndexController extends Zend_Controller_Action { $title = $this->view->translate('Welcome to Intercomunexão.'); $message = $this->view->translate('By registering your SNEP, you connect to the portal of Intercomunexão. Portal where you will have access to exclusive solutions, high-quality support and a constantly evolving technology.
Access: itc.opens.com.br'); - Snep_Notifications::addNotification($title,$message); + Snep_Notifications::addNotification($title,$message,1,"OPENS"); // go to snep $_SESSION['registered'] = true; @@ -277,19 +277,22 @@ class IndexController extends Zend_Controller_Action { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array( $this->view->translate("Dashboard"))); + $configs = Snep_Config::getConfiguration('CORE','HOST_NOTIFICATION'); + // get last_id_notification if exists $idLastNotification = Snep_Config::getConfiguration("CORE", "LAST_ID_NOTIFICATION"); if($idLastNotification){ - $idLastNotification = $idLastNotification["config_value"]; + + $idLastNotification = $idLastNotification["config_value"]; + $url = $configs["config_value"]."/last_id/".$idLastNotification."/UUID/".$_SESSION["uuid"]; + }else{ - $idLastNotification = Snep_Notifications::getDateLastNotification(); - } - $configs = Snep_Config::getConfiguration('CORE','HOST_NOTIFICATION'); + $dateNotification = date("Y-m-d"); + $url = $configs["config_value"]."/date/".$dateNotification."/UUID/".$_SESSION["uuid"]; + } // get notification in itc - $url = $configs["config_value"].$idLastNotification."/UUID/".$_SESSION["uuid"]; - $http = curl_init($url); curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false); @@ -304,8 +307,23 @@ class IndexController extends Zend_Controller_Action { $notifications = json_decode($http_response); foreach($notifications as $item => $notification){ - Snep_Notifications::addNotification(utf8_decode($notification->title),utf8_decode($notification->message),$notification->id); + $lastId = $notification->id; + + Snep_Notifications::addNotification(utf8_decode($notification->title),utf8_decode($notification->message),$notification->id,$notification->id_costumer); } + + if(isset($lastId)){ + + // get last_id_notification if exists + $idLastNotification = Snep_Config::getConfiguration("CORE", "LAST_ID_NOTIFICATION"); + if($idLastNotification){ + Snep_Notifications::updateLastNotification($lastId); + }else{ + Snep_Notifications::addLastNotification($lastId); + } + + } + break; case 500: @@ -314,7 +332,7 @@ class IndexController extends Zend_Controller_Action { $title = $this->view->translate('Warning'); $message = $this->view->translate('Internal Server Error.
To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.'); - Snep_Notifications::addNotification($title,$message); + Snep_Notifications::addNotification($title,$message,1,"OPENS"); } break; @@ -325,7 +343,7 @@ class IndexController extends Zend_Controller_Action { $title = $this->view->translate('Warning'); $message = $this->view->translate('Error notifications.
To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.'); - Snep_Notifications::addNotification($title,$message); + Snep_Notifications::addNotification($title,$message,1,"OPENS"); } break; @@ -336,7 +354,7 @@ class IndexController extends Zend_Controller_Action { $title = $this->view->translate('Warning'); $message = $this->view->translate("Error: Code ") . $httpcode . $this->view->translate(". Please contact the administrator for receiver notifications."); - Snep_Notifications::addNotification($title,$message); + Snep_Notifications::addNotification($title,$message,"OPENS"); } break; } diff --git a/modules/default/controllers/NotificationsController.php b/modules/default/controllers/NotificationsController.php index d9eefa9..00f5333 100644 --- a/modules/default/controllers/NotificationsController.php +++ b/modules/default/controllers/NotificationsController.php @@ -135,10 +135,6 @@ class NotificationsController extends Zend_Controller_Action { $idLastNotification = Snep_Notifications::getDateLastNotification(); - // update last notification in config_core - Snep_Notifications::removeLastNotification(); - Snep_Notifications::addLastNotification($idLastNotification); - // remove notification Snep_Notifications::removeNotification($id); diff --git a/modules/default/views/layouts/layout.phtml b/modules/default/views/layouts/layout.phtml index cce5581..e9da18c 100644 --- a/modules/default/views/layouts/layout.phtml +++ b/modules/default/views/layouts/layout.phtml @@ -67,26 +67,20 @@ diff --git a/modules/default/views/scripts/notifications/index.phtml b/modules/default/views/scripts/notifications/index.phtml index 52dbe54..6b8e318 100644 --- a/modules/default/views/scripts/notifications/index.phtml +++ b/modules/default/views/scripts/notifications/index.phtml @@ -33,6 +33,7 @@ $this->headLink()->appendStylesheet( $this->baseUrl() . "/css/index.css"); + translate('Remetente');?> translate('Notification');?> translate('Date');?> translate('Actions');?> @@ -46,12 +47,14 @@ $this->headLink()->appendStylesheet( $this->baseUrl() . "/css/index.css"); - + + + -- libgit2 0.21.2