Fix several problem with hook printFieldListWhere

This commit is contained in:
Laurent Destailleur 2017-06-09 11:02:34 +02:00
parent bec6ad9fb3
commit 02781b41ca
4 changed files with 91 additions and 63 deletions

View File

@ -53,7 +53,7 @@ class box_produits extends ModeleBoxes
*/ */
function loadBox($max=5) function loadBox($max=5)
{ {
global $user, $langs, $db, $conf; global $user, $langs, $db, $conf, $hookmanager;
$this->max=$max; $this->max=$max;
@ -69,6 +69,13 @@ class box_produits extends ModeleBoxes
$sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')';
if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
// Add where from hooks
if (is_object($hookmanager))
{
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
}
$sql.= $db->order('p.datec', 'DESC'); $sql.= $db->order('p.datec', 'DESC');
$sql.= $db->plimit($max, 0); $sql.= $db->plimit($max, 0);

View File

@ -55,7 +55,7 @@ class box_produits_alerte_stock extends ModeleBoxes
*/ */
function loadBox($max=5) function loadBox($max=5)
{ {
global $user, $langs, $db, $conf; global $user, $langs, $db, $conf, $hookmanager;
$this->max=$max; $this->max=$max;
@ -74,6 +74,13 @@ class box_produits_alerte_stock extends ModeleBoxes
$sql.= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0"; $sql.= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0";
if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
// Add where from hooks
if (is_object($hookmanager))
{
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
}
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity"; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity";
$sql.= " HAVING SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") < p.seuil_stock_alerte"; $sql.= " HAVING SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") < p.seuil_stock_alerte";
$sql.= $db->order('p.seuil_stock_alerte', 'DESC'); $sql.= $db->order('p.seuil_stock_alerte', 'DESC');

View File

@ -4017,7 +4017,7 @@ class Product extends CommonObject
*/ */
function load_state_board() function load_state_board()
{ {
global $conf, $user; global $conf, $user, $hookmanager;
$this->nb=array(); $this->nb=array();
@ -4025,6 +4025,13 @@ class Product extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')';
$sql.= " AND p.fk_product_type <> 1"; $sql.= " AND p.fk_product_type <> 1";
// Add where from hooks
if (is_object($hookmanager))
{
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
}
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -56,7 +56,7 @@ class Service extends CommonObject
*/ */
function load_state_board() function load_state_board()
{ {
global $conf, $user; global $conf, $user, $hookmanager;
$this->nb=array(); $this->nb=array();
@ -64,6 +64,13 @@ class Service extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
$sql.= " AND p.fk_product_type = 1"; $sql.= " AND p.fk_product_type = 1";
// Add where from hooks
if (is_object($hookmanager))
{
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
}
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)