git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8262 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+11
-19
@@ -43,10 +43,10 @@ class Notification
|
|||||||
public function getLastElements()
|
public function getLastElements()
|
||||||
{
|
{
|
||||||
$notifications = array();
|
$notifications = array();
|
||||||
$sql = 'SELECT id_last_order, id_last_message, id_last_customer
|
$employee_infos = Db::getInstance()->getRow('
|
||||||
|
SELECT id_last_order, id_last_message, id_last_customer
|
||||||
FROM `'._DB_PREFIX_.'employee`
|
FROM `'._DB_PREFIX_.'employee`
|
||||||
WHERE `id_employee` = '.(int)$this->context->employee->id;
|
WHERE `id_employee` = '.(int)$this->context->employee->id);
|
||||||
$employee_infos = Db::getInstance()->getRow($sql);
|
|
||||||
|
|
||||||
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]);
|
||||||
@@ -58,53 +58,45 @@ class Notification
|
|||||||
* getLastElementsIdsByType return all the element ids to show (order, customer registration, and customer message)
|
* getLastElementsIdsByType return all the element ids to show (order, customer registration, and customer message)
|
||||||
* Get all the element ids
|
* Get all the element ids
|
||||||
*
|
*
|
||||||
|
* @param string $type contains the field name of the Employee table
|
||||||
|
* @param integer $id_last_element contains the id of the last seen element
|
||||||
* @return array containing the notifications
|
* @return array containing the notifications
|
||||||
*/
|
*/
|
||||||
public static function getLastElementsIdsByType($type, $id_last_element)
|
public static function getLastElementsIdsByType($type, $id_last_element)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($type == 'order' || $type == 'message')
|
if ($type == 'order' || $type == 'message')
|
||||||
{
|
|
||||||
$sql = 'SELECT id_order
|
$sql = 'SELECT id_order
|
||||||
FROM `'._DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'`
|
FROM `'._DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'`
|
||||||
WHERE `id_'.$type.'` > '.$id_last_element.'
|
WHERE `id_'.$type.'` > '.$id_last_element.'
|
||||||
ORDER BY `id_'.$type.'` DESC LIMIT 5');
|
ORDER BY `id_'.$type.'` DESC LIMIT 5';
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
$sql = 'SELECT id_'.$type.'
|
$sql = 'SELECT id_'.$type.'
|
||||||
FROM `'._DB_PREFIX_.$type.'`
|
FROM `'._DB_PREFIX_.$type.'`
|
||||||
WHERE `id_'.$type.'` > '.$id_last_element.'
|
WHERE `id_'.$type.'` > '.$id_last_element.'
|
||||||
ORDER BY `id_'.$type.'` DESC LIMIT 5');
|
ORDER BY `id_'.$type.'` DESC LIMIT 5';
|
||||||
}
|
|
||||||
|
|
||||||
return Db::getInstance()->ExecuteS($sql);
|
return Db::getInstance()->ExecuteS($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateEmployeeLastElement return 0 if the field doesn't exists in Employee table.
|
* updateEmployeeLastElement return 0 if the field doesn't exists in Employee table.
|
||||||
* Updates the last element seen by the employee
|
* Updates the last seen element by the employee
|
||||||
*
|
*
|
||||||
* @param boolean $type contains the field name of the Employee table
|
* @param string $type contains the field name of the Employee table
|
||||||
* @return boolean if type exists or not
|
* @return boolean if type exists or not
|
||||||
*/
|
*/
|
||||||
public function updateEmployeeLastElement($type)
|
public function updateEmployeeLastElement($type)
|
||||||
{
|
{
|
||||||
if (in_array($type, $this->types))
|
if (in_array($type, $this->types))
|
||||||
{
|
|
||||||
// We update the last item viewed
|
// We update the last item viewed
|
||||||
$sql = 'UPDATE `'._DB_PREFIX_.'employee`
|
return Db::getInstance()->Execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'employee`
|
||||||
SET `id_last_'.$type.'` = (SELECT MAX(`id_'.$type.'`)
|
SET `id_last_'.$type.'` = (SELECT MAX(`id_'.$type.'`)
|
||||||
FROM `'._DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'`)
|
FROM `'._DB_PREFIX_.(($type == 'order') ? $type.'s' : $type).'`)
|
||||||
WHERE `id_employee` = '.(int)$this->context->employee->id);
|
WHERE `id_employee` = '.(int)$this->context->employee->id);
|
||||||
Db::getInstance()->Execute($sql);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user