[-] BO : fixed notifications when there is too much data
This commit is contained in:
@@ -130,7 +130,7 @@
|
|||||||
<div class="dropdown-menu notifs_dropdown">
|
<div class="dropdown-menu notifs_dropdown">
|
||||||
<section id="orders_notif_wrapper" class="notifs_panel">
|
<section id="orders_notif_wrapper" class="notifs_panel">
|
||||||
<header class="notifs_panel_header">
|
<header class="notifs_panel_header">
|
||||||
<h3>{l s='Last orders'}</h3>
|
<h3>{l s='Latest Orders'}</h3>
|
||||||
</header>
|
</header>
|
||||||
<div id="list_orders_notif" class="list-group">
|
<div id="list_orders_notif" class="list-group">
|
||||||
<a href="#" class="media list-group-item no_notifs">
|
<a href="#" class="media list-group-item no_notifs">
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
<div class="dropdown-menu notifs_dropdown">
|
<div class="dropdown-menu notifs_dropdown">
|
||||||
<section id="customers_notif_wrapper" class="notifs_panel">
|
<section id="customers_notif_wrapper" class="notifs_panel">
|
||||||
<header class="notifs_panel_header">
|
<header class="notifs_panel_header">
|
||||||
<h3>{l s='Last customers'}</h3>
|
<h3>{l s='Latest Registrations'}</h3>
|
||||||
</header>
|
</header>
|
||||||
<div id="list_customers_notif" class="list-group">
|
<div id="list_customers_notif" class="list-group">
|
||||||
<a href="#" class="media list-group-item no_notifs">
|
<a href="#" class="media list-group-item no_notifs">
|
||||||
@@ -190,7 +190,7 @@
|
|||||||
<div class="dropdown-menu notifs_dropdown">
|
<div class="dropdown-menu notifs_dropdown">
|
||||||
<section id="customer_messages_notif_wrapper" class="notifs_panel">
|
<section id="customer_messages_notif_wrapper" class="notifs_panel">
|
||||||
<header class="notifs_panel_header">
|
<header class="notifs_panel_header">
|
||||||
<h3>{l s='Last messages'}</h3>
|
<h3>{l s='Latest Messages'}</h3>
|
||||||
</header>
|
</header>
|
||||||
<div id="list_orders_notif" class="list-group">
|
<div id="list_orders_notif" class="list-group">
|
||||||
<a href="#" class="media list-group-item no_notifs">
|
<a href="#" class="media list-group-item no_notifs">
|
||||||
|
|||||||
+25
-25
@@ -45,9 +45,9 @@ class NotificationCore
|
|||||||
|
|
||||||
$notifications = array();
|
$notifications = array();
|
||||||
$employee_infos = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$employee_infos = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT id_last_order, id_last_customer_message, id_last_customer
|
SELECT id_last_order, id_last_customer_message, id_last_customer
|
||||||
FROM `'._DB_PREFIX_.'employee`
|
FROM `'._DB_PREFIX_.'employee`
|
||||||
WHERE `id_employee` = '.(int)$cookie->id_employee);
|
WHERE `id_employee` = '.(int)$cookie->id_employee);
|
||||||
|
|
||||||
foreach ($this->types as $type)
|
foreach ($this->types as $type)
|
||||||
$notifications[$type] = Notification::getLastElementsIdsByType($type, $employee_infos['id_last_'.$type]);
|
$notifications[$type] = Notification::getLastElementsIdsByType($type, $employee_infos['id_last_'.$type]);
|
||||||
@@ -57,10 +57,11 @@ class NotificationCore
|
|||||||
|
|
||||||
public function installDb()
|
public function installDb()
|
||||||
{
|
{
|
||||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('ALTER TABLE `'._DB_PREFIX_.'employee`
|
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
|
||||||
ADD `id_last_order` INT(10) unsigned NOT NULL default "0"
|
ALTER TABLE `'._DB_PREFIX_.'employee`
|
||||||
ADD `id_last_customer_message` INT(10) unsigned NOT NULL default "0"
|
ADD `id_last_order` INT(10) unsigned NOT NULL default "0"
|
||||||
ADD `id_last_message` 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':
|
case 'order':
|
||||||
$sql = '
|
$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
|
FROM `'._DB_PREFIX_.'orders` as o
|
||||||
LEFT JOIN `'._DB_PREFIX_.'customer` as c ON (c.`id_customer` = o.`id_customer`)
|
LEFT JOIN `'._DB_PREFIX_.'customer` as c ON (c.`id_customer` = o.`id_customer`)
|
||||||
WHERE `id_order` > '.(int)$id_last_element.
|
WHERE `id_order` > '.(int)$id_last_element.
|
||||||
Shop::addSqlRestriction(false, 'o').'
|
Shop::addSqlRestriction(false, 'o').'
|
||||||
ORDER BY `id_order` DESC
|
ORDER BY `id_order` DESC
|
||||||
';
|
LIMIT 5';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'customer_message':
|
case 'customer_message':
|
||||||
$sql = '
|
$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
|
FROM `'._DB_PREFIX_.'customer_message` as c
|
||||||
LEFT JOIN `'._DB_PREFIX_.'customer_thread` as ct ON (c.`id_customer_thread` = ct.`id_customer_thread`)
|
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.'
|
WHERE c.`id_customer_message` > '.(int)$id_last_element.'
|
||||||
AND c.`id_employee` = 0
|
AND c.`id_employee` = 0
|
||||||
AND ct.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
|
AND ct.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
|
||||||
ORDER BY c.`id_customer_message` DESC
|
ORDER BY c.`id_customer_message` DESC
|
||||||
';
|
LIMIT 5';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$sql = '
|
$sql = '
|
||||||
SELECT t.`id_'.bqSQL($type).'`, t.*
|
SELECT SQL_CALC_FOUND_ROWS t.`id_'.bqSQL($type).'`, t.*
|
||||||
FROM `'._DB_PREFIX_.bqSQL($type).'` t
|
FROM `'._DB_PREFIX_.bqSQL($type).'` t
|
||||||
WHERE t.`deleted` = 0 AND t.`id_'.bqSQL($type).'` > '.(int)$id_last_element.
|
WHERE t.`deleted` = 0 AND t.`id_'.bqSQL($type).'` > '.(int)$id_last_element.
|
||||||
Shop::addSqlRestriction(false, 't').'
|
Shop::addSqlRestriction(false, 't').'
|
||||||
ORDER BY t.`id_'.bqSQL($type).'` DESC
|
ORDER BY t.`id_'.bqSQL($type).'` DESC
|
||||||
';
|
LIMIT 5';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = array();
|
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
$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)
|
foreach ($result as $value)
|
||||||
{
|
{
|
||||||
$customer_name = '';
|
$customer_name = '';
|
||||||
@@ -119,7 +120,7 @@ class NotificationCore
|
|||||||
else if (isset($value['email']))
|
else if (isset($value['email']))
|
||||||
$customer_name = Tools::safeOutput($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_order' => ((!empty($value['id_order'])) ? (int)$value['id_order'] : 0),
|
||||||
'id_customer' => ((!empty($value['id_customer'])) ? (int)$value['id_customer'] : 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),
|
'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))
|
if (in_array($type, $this->types))
|
||||||
// We update the last item viewed
|
// We update the last item viewed
|
||||||
return Db::getInstance()->execute('
|
return Db::getInstance()->execute('
|
||||||
UPDATE `'._DB_PREFIX_.'employee`
|
UPDATE `'._DB_PREFIX_.'employee`
|
||||||
SET `id_last_'.bqSQL($type).'` = (
|
SET `id_last_'.bqSQL($type).'` = (
|
||||||
SELECT IFNULL(MAX(`id_'.$type.'`), 0)
|
SELECT IFNULL(MAX(`id_'.$type.'`), 0)
|
||||||
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s' : bqSQL($type)).'`
|
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s' : bqSQL($type)).'`
|
||||||
)
|
)
|
||||||
WHERE `id_employee` = '.(int)$cookie->id_employee);
|
WHERE `id_employee` = '.(int)$cookie->id_employee);
|
||||||
else
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-24
@@ -54,8 +54,7 @@ function getPush(refresh)
|
|||||||
|
|
||||||
// Add orders notifications to the list
|
// Add orders notifications to the list
|
||||||
html = "";
|
html = "";
|
||||||
nb_notifs = 0;
|
$.each(json.order.results, function(property, value) {
|
||||||
$.each(json.order, 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 += "<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='pull-left'><i class='icon-time'></i></span>";
|
||||||
html += "<span class='media-body'>";
|
html += "<span class='media-body'>";
|
||||||
@@ -67,23 +66,19 @@ function getPush(refresh)
|
|||||||
html += "<small class='text-muted'>1 minute ago</small>";
|
html += "<small class='text-muted'>1 minute ago</small>";
|
||||||
html += "</span></a>";
|
html += "</span></a>";
|
||||||
});
|
});
|
||||||
if (html != "")
|
if (json.order.total)
|
||||||
{
|
{
|
||||||
//$("#list_orders_notif").prev("p").hide();
|
//$("#list_orders_notif").prev("p").hide();
|
||||||
$("#list_orders_notif").empty().append(html);
|
$("#list_orders_notif").empty().append(html);
|
||||||
nb_notifs = $("#list_orders_notif").length;
|
$("#orders_notif_value").text(json.order.total);
|
||||||
$("#orders_notif_value").text(nb_notifs);
|
|
||||||
$("#orders_notif_number_wrapper").show();
|
$("#orders_notif_number_wrapper").show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
$("#orders_notif_number_wrapper").hide();
|
$("#orders_notif_number_wrapper").hide();
|
||||||
}
|
|
||||||
|
|
||||||
// Add customers notifications to the list
|
// Add customers notifications to the list
|
||||||
html = "";
|
html = "";
|
||||||
nb_notifs = 0;
|
$.each(json.customer.results, function(property, value) {
|
||||||
$.each(json.customer, 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 += "<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='pull-left'><i class='icon-time'></i></span>";
|
||||||
html += "<span class='media-body'>";
|
html += "<span class='media-body'>";
|
||||||
@@ -93,23 +88,19 @@ function getPush(refresh)
|
|||||||
html += "<small class='text-muted'>1 minute ago</small>";
|
html += "<small class='text-muted'>1 minute ago</small>";
|
||||||
html += "</span></a>";
|
html += "</span></a>";
|
||||||
});
|
});
|
||||||
if (html != "")
|
if (json.customer.total)
|
||||||
{
|
{
|
||||||
//$("#list_customers_notif").prev("p").hide();
|
//$("#list_customers_notif").prev("p").hide();
|
||||||
$("#list_customers_notif").empty().append(html);
|
$("#list_customers_notif").empty().append(html);
|
||||||
nb_notifs = $("#list_customers_notif").length;
|
$("#customers_notif_value").text(json.customer.total);
|
||||||
$("#customers_notif_value").text(nb_notifs);
|
|
||||||
$("#customers_notif_number_wrapper").show();
|
$("#customers_notif_number_wrapper").show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
$("#customers_notif_number_wrapper").hide();
|
$("#customers_notif_number_wrapper").hide();
|
||||||
}
|
|
||||||
|
|
||||||
// Add messages notifications to the list
|
// Add messages notifications to the list
|
||||||
html = "";
|
html = "";
|
||||||
nb_notifs = 0;
|
$.each(json.customer_message.results, function(property, value) {
|
||||||
$.each(json.customer_message, 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 += "<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='pull-left'><i class='icon-time'></i></span>";
|
||||||
html += "<span class='media-body'>";
|
html += "<span class='media-body'>";
|
||||||
@@ -120,20 +111,17 @@ function getPush(refresh)
|
|||||||
html += "</span></a>";
|
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);
|
$("#list_customer_messages_notif").empty().append(html);
|
||||||
nb_notifs = $("#list_customer_messages_notif li").length;
|
$("#customer_messages_notif_value").text(json.customer_message.total);
|
||||||
$("#customer_messages_notif_value").text(nb_notifs);
|
|
||||||
$("#customer_messages_notif_number_wrapper").show();
|
$("#customer_messages_notif_number_wrapper").show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
$("#customer_messages_notif_number_wrapper").hide();
|
$("#customer_messages_notif_number_wrapper").hide();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(refresh)
|
if (refresh)
|
||||||
setTimeout("getPush(1)",60000);
|
setTimeout("getPush(1)", 60000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user