[-] BO : fixed bug #PSCFV-2502 - fixed bug on notification system in back office

This commit is contained in:
aFolletete
2012-05-23 16:41:02 +00:00
parent ab5547e837
commit ea1ca5348c
+31 -11
View File
@@ -74,17 +74,37 @@ class NotificationCore
*/ */
public static function getLastElementsIdsByType($type, $id_last_element) public static function getLastElementsIdsByType($type, $id_last_element)
{ {
if ($type == 'order' || $type == 'customer_message') switch ($type)
$sql = 'SELECT '.(($type == 'order') ? 'id_order, id_customer, total_paid' : 'c.id_customer_message as id_customer_message, ct.id_customer as id_customer, ct.id_customer_thread as id_customer_thread, ct.email as email').' {
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s`' : bqSQL($type).'` as c LEFT JOIN `'._DB_PREFIX_.'customer_thread` as ct ON c.id_customer_thread = ct.id_customer_thread').' case 'order':
WHERE '.(($type == 'customer_message') ? 'c.' : '').'`id_'.bqSQL($type).'` > '.(int)$id_last_element. $sql = '
(($type == 'customer_message') ? ' AND c.`id_employee` = 0' : '').' SELECT o.`id_order`, o.`id_customer`, o.`total_paid`
ORDER BY '.(($type == 'customer_message') ? 'c.' : '').'`id_'.bqSQL($type).'` DESC'; FROM `'._DB_PREFIX_.'orders` as o
else WHERE `id_order` > '.(int)$id_last_element.
$sql = 'SELECT id_'.bqSQL($type).' Shop::addSqlRestriction(false, 'o').'
FROM `'._DB_PREFIX_.bqSQL($type).'` ORDER BY `id_order` DESC
WHERE `id_'.bqSQL($type).'` > '.(int)$id_last_element.' ';
ORDER BY `id_'.bqSQL($type).'` DESC'; break;
case 'customer_message':
$sql = '
SELECT 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
ORDER BY c.`id_customer_message` DESC
';
break;
default:
$sql = '
SELECT t.`id_'.bqSQL($type).'`
FROM `'._DB_PREFIX_.bqSQL($type).'` t
WHERE t.`id_'.bqSQL($type).'` > '.(int)$id_last_element.
Shop::addSqlRestriction(false, 't').'
ORDER BY t.`id_'.bqSQL($type).'` DESC
';
break;
}
$json = array(); $json = array();
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql) as $key => $value) foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql) as $key => $value)