[-] BO : fixed notifications when there is too much data

This commit is contained in:
Damien Metzger
2013-09-10 09:17:54 +02:00
parent 2a7bc49190
commit 1d8da79507
3 changed files with 40 additions and 52 deletions
+3 -3
View File
@@ -130,7 +130,7 @@
<div class="dropdown-menu notifs_dropdown">
<section id="orders_notif_wrapper" class="notifs_panel">
<header class="notifs_panel_header">
<h3>{l s='Last orders'}</h3>
<h3>{l s='Latest Orders'}</h3>
</header>
<div id="list_orders_notif" class="list-group">
<a href="#" class="media list-group-item no_notifs">
@@ -160,7 +160,7 @@
<div class="dropdown-menu notifs_dropdown">
<section id="customers_notif_wrapper" class="notifs_panel">
<header class="notifs_panel_header">
<h3>{l s='Last customers'}</h3>
<h3>{l s='Latest Registrations'}</h3>
</header>
<div id="list_customers_notif" class="list-group">
<a href="#" class="media list-group-item no_notifs">
@@ -190,7 +190,7 @@
<div class="dropdown-menu notifs_dropdown">
<section id="customer_messages_notif_wrapper" class="notifs_panel">
<header class="notifs_panel_header">
<h3>{l s='Last messages'}</h3>
<h3>{l s='Latest Messages'}</h3>
</header>
<div id="list_orders_notif" class="list-group">
<a href="#" class="media list-group-item no_notifs">
+25 -25
View File
@@ -45,9 +45,9 @@ class NotificationCore
$notifications = array();
$employee_infos = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT id_last_order, id_last_customer_message, id_last_customer
FROM `'._DB_PREFIX_.'employee`
WHERE `id_employee` = '.(int)$cookie->id_employee);
SELECT id_last_order, id_last_customer_message, id_last_customer
FROM `'._DB_PREFIX_.'employee`
WHERE `id_employee` = '.(int)$cookie->id_employee);
foreach ($this->types as $type)
$notifications[$type] = Notification::getLastElementsIdsByType($type, $employee_infos['id_last_'.$type]);
@@ -57,10 +57,11 @@ class NotificationCore
public function installDb()
{
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('ALTER TABLE `'._DB_PREFIX_.'employee`
ADD `id_last_order` INT(10) unsigned NOT NULL default "0"
ADD `id_last_customer_message` INT(10) unsigned NOT NULL default "0"
ADD `id_last_message` INT(10) unsigned NOT NULL default "0"');
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
ALTER TABLE `'._DB_PREFIX_.'employee`
ADD `id_last_order` INT(10) unsigned NOT NULL default "0"
ADD `id_last_customer_message` INT(10) unsigned NOT NULL default "0"
ADD `id_last_message` INT(10) unsigned NOT NULL default "0"');
}
/**
@@ -77,40 +78,40 @@ class NotificationCore
{
case 'order':
$sql = '
SELECT o.`id_order`, o.`id_customer`, o.`total_paid`, o.`id_currency`, c.`firstname`, c.`lastname`
SELECT SQL_CALC_FOUND_ROWS o.`id_order`, o.`id_customer`, o.`total_paid`, o.`id_currency`, c.`firstname`, c.`lastname`
FROM `'._DB_PREFIX_.'orders` as o
LEFT JOIN `'._DB_PREFIX_.'customer` as c ON (c.`id_customer` = o.`id_customer`)
WHERE `id_order` > '.(int)$id_last_element.
Shop::addSqlRestriction(false, 'o').'
ORDER BY `id_order` DESC
';
LIMIT 5';
break;
case 'customer_message':
$sql = '
SELECT c.`id_customer_message`, ct.`id_customer`, ct.`id_customer_thread`, ct.`email`
SELECT SQL_CALC_FOUND_ROWS c.`id_customer_message`, ct.`id_customer`, ct.`id_customer_thread`, ct.`email`
FROM `'._DB_PREFIX_.'customer_message` as c
LEFT JOIN `'._DB_PREFIX_.'customer_thread` as ct ON (c.`id_customer_thread` = ct.`id_customer_thread`)
WHERE c.`id_customer_message` > '.(int)$id_last_element.'
AND c.`id_employee` = 0
AND ct.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
ORDER BY c.`id_customer_message` DESC
';
LIMIT 5';
break;
default:
$sql = '
SELECT t.`id_'.bqSQL($type).'`, t.*
SELECT SQL_CALC_FOUND_ROWS t.`id_'.bqSQL($type).'`, t.*
FROM `'._DB_PREFIX_.bqSQL($type).'` t
WHERE t.`deleted` = 0 AND t.`id_'.bqSQL($type).'` > '.(int)$id_last_element.
Shop::addSqlRestriction(false, 't').'
ORDER BY t.`id_'.bqSQL($type).'` DESC
';
LIMIT 5';
break;
}
$json = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$total = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
$json = array('total' => $total, 'results' => array());
foreach ($result as $value)
{
$customer_name = '';
@@ -119,7 +120,7 @@ class NotificationCore
else if (isset($value['email']))
$customer_name = Tools::safeOutput($value['email']);
$json[] = array(
$json['results'][] = array(
'id_order' => ((!empty($value['id_order'])) ? (int)$value['id_order'] : 0),
'id_customer' => ((!empty($value['id_customer'])) ? (int)$value['id_customer'] : 0),
'id_customer_message' => ((!empty($value['id_customer_message'])) ? (int)$value['id_customer_message'] : 0),
@@ -146,13 +147,12 @@ class NotificationCore
if (in_array($type, $this->types))
// We update the last item viewed
return Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'employee`
SET `id_last_'.bqSQL($type).'` = (
SELECT IFNULL(MAX(`id_'.$type.'`), 0)
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s' : bqSQL($type)).'`
)
WHERE `id_employee` = '.(int)$cookie->id_employee);
else
return false;
UPDATE `'._DB_PREFIX_.'employee`
SET `id_last_'.bqSQL($type).'` = (
SELECT IFNULL(MAX(`id_'.$type.'`), 0)
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s' : bqSQL($type)).'`
)
WHERE `id_employee` = '.(int)$cookie->id_employee);
return false;
}
}
}
+12 -24
View File
@@ -54,8 +54,7 @@ function getPush(refresh)
// Add orders notifications to the list
html = "";
nb_notifs = 0;
$.each(json.order, function(property, value) {
$.each(json.order.results, function(property, value) {
html += "<a href='index.php?tab=AdminOrders&token=" + token_admin_orders + "&vieworder&id_order=" + parseInt(value.id_order) + "' class='media list-group-item no_notifs'>";
html += "<span class='pull-left'><i class='icon-time'></i></span>";
html += "<span class='media-body'>";
@@ -67,23 +66,19 @@ function getPush(refresh)
html += "<small class='text-muted'>1 minute ago</small>";
html += "</span></a>";
});
if (html != "")
if (json.order.total)
{
//$("#list_orders_notif").prev("p").hide();
$("#list_orders_notif").empty().append(html);
nb_notifs = $("#list_orders_notif").length;
$("#orders_notif_value").text(nb_notifs);
$("#orders_notif_value").text(json.order.total);
$("#orders_notif_number_wrapper").show();
}
else
{
$("#orders_notif_number_wrapper").hide();
}
// Add customers notifications to the list
html = "";
nb_notifs = 0;
$.each(json.customer, function(property, value) {
$.each(json.customer.results, function(property, value) {
html += "<a href='index.php?tab=AdminCustomers&token=" + token_admin_customers + "&viewcustomer&id_customer=" + parseInt(value.id_customer) + "' class='media list-group-item no_notifs'>";
html += "<span class='pull-left'><i class='icon-time'></i></span>";
html += "<span class='media-body'>";
@@ -93,23 +88,19 @@ function getPush(refresh)
html += "<small class='text-muted'>1 minute ago</small>";
html += "</span></a>";
});
if (html != "")
if (json.customer.total)
{
//$("#list_customers_notif").prev("p").hide();
$("#list_customers_notif").empty().append(html);
nb_notifs = $("#list_customers_notif").length;
$("#customers_notif_value").text(nb_notifs);
$("#customers_notif_value").text(json.customer.total);
$("#customers_notif_number_wrapper").show();
}
else
{
$("#customers_notif_number_wrapper").hide();
}
// Add messages notifications to the list
html = "";
nb_notifs = 0;
$.each(json.customer_message, function(property, value) {
$.each(json.customer_message.results, function(property, value) {
html += "<a href='index.php?tab=AdminCustomerThreads&token=" + token_admin_customer_threads + "&viewcustomer_thread&id_customer_thread=" + parseInt(value.id_customer_thread) + "'>";
html += "<span class='pull-left'><i class='icon-time'></i></span>";
html += "<span class='media-body'>";
@@ -120,20 +111,17 @@ function getPush(refresh)
html += "</span></a>";
});
if (html != "")
if (json.customer_message.total)
{
$("#list_customer_messages_notif").prev("p").hide();
// $("#list_customer_messages_notif").prev("p").hide();
$("#list_customer_messages_notif").empty().append(html);
nb_notifs = $("#list_customer_messages_notif li").length;
$("#customer_messages_notif_value").text(nb_notifs);
$("#customer_messages_notif_value").text(json.customer_message.total);
$("#customer_messages_notif_number_wrapper").show();
}
else
{
$("#customer_messages_notif_number_wrapper").hide();
}
}
if(refresh)
setTimeout("getPush(1)",60000);
if (refresh)
setTimeout("getPush(1)", 60000);
});
}