Merge pull request #20397 from hregis/new_add_hook_in_box_customer_and_product

NEW add hooks in customers and products boxes
This commit is contained in:
Laurent Destailleur 2022-03-23 16:04:23 +01:00 committed by GitHub
commit 9d2f59a10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 19 deletions

View File

@ -76,7 +76,7 @@ class box_clients extends ModeleBoxes
*/
public function loadBox($max = 5)
{
global $user, $langs, $conf;
global $user, $langs, $hookmanager;
$langs->load("boxes");
$this->max = $max;
@ -100,9 +100,15 @@ class box_clients extends ModeleBoxes
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($user->socid) {
$sql .= " AND s.rowid = ".((int) $user->socid);
// Add where from hooks
$parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
if (empty($reshook)) {
if ($user->socid > 0) {
$sql .= " AND s.rowid = ".((int) $user->socid);
}
}
$sql .= $hookmanager->resPrint;
$sql .= " ORDER BY s.tms DESC";
$sql .= $this->db->plimit($max, 0);

View File

@ -74,11 +74,15 @@ class box_contacts extends ModeleBoxes
*/
public function loadBox($max = 5)
{
global $user, $langs, $conf;
global $user, $langs, $conf, $hookmanager;
$langs->load("boxes");
$this->max = $max;
$contactstatic = new Contact($this->db);
$societestatic = new Societe($this->db);
$this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedContacts", $max));
if ($user->rights->societe->lire && $user->rights->societe->contact->lire) {
@ -110,9 +114,15 @@ class box_contacts extends ModeleBoxes
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($user->socid) {
$sql .= " AND sp.fk_soc = ".((int) $user->socid);
// Add where from hooks
$parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
if (empty($reshook)) {
if ($user->socid > 0) {
$sql .= " AND sp.fk_soc = ".((int) $user->socid);
}
}
$sql .= $hookmanager->resPrint;
$sql .= " ORDER BY sp.tms DESC";
$sql .= $this->db->plimit($max, 0);
@ -120,9 +130,6 @@ class box_contacts extends ModeleBoxes
if ($result) {
$num = $this->db->num_rows($result);
$contactstatic = new Contact($this->db);
$societestatic = new Societe($this->db);
$line = 0;
while ($line < $num) {
$objp = $this->db->fetch_object($result);

View File

@ -71,7 +71,7 @@ class box_fournisseurs extends ModeleBoxes
*/
public function loadBox($max = 5)
{
global $conf, $user, $langs;
global $conf, $user, $langs, $hookmanager;
$langs->load("boxes");
$this->max = $max;
@ -95,9 +95,15 @@ class box_fournisseurs extends ModeleBoxes
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($user->socid) {
$sql .= " AND s.rowid = ".((int) $user->socid);
// Add where from hooks
$parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
if (empty($reshook)) {
if ($user->socid > 0) {
$sql .= " AND s.rowid = ".((int) $user->socid);
}
}
$sql .= $hookmanager->resPrint;
$sql .= " ORDER BY s.tms DESC ";
$sql .= $this->db->plimit($max, 0);

View File

@ -103,8 +103,8 @@ class box_produits extends ModeleBoxes
}
// Add where from hooks
if (is_object($hookmanager)) {
$parameters = array('boxproductlist'=>1);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$parameters = array('boxproductlist' => 1, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $productstatic); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
}
$sql .= $this->db->order('p.datec', 'DESC');

View File

@ -103,8 +103,8 @@ class box_produits_alerte_stock extends ModeleBoxes
}
// Add where from hooks
if (is_object($hookmanager)) {
$parameters = array('boxproductalertstocklist'=>1);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$parameters = array('boxproductalertstocklist' => 1, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $productstatic); // 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.barcode, p.seuil_stock_alerte, p.entity,";

View File

@ -78,7 +78,7 @@ class box_prospect extends ModeleBoxes
*/
public function loadBox($max = 5)
{
global $user, $langs, $conf;
global $user, $langs, $hookmanager;
$this->max = $max;
@ -101,9 +101,15 @@ class box_prospect extends ModeleBoxes
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
if ($user->socid) {
$sql .= " AND s.rowid = ".((int) $user->socid);
// Add where from hooks
$parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
if (empty($reshook)) {
if ($user->socid > 0) {
$sql .= " AND s.rowid = ".((int) $user->socid);
}
}
$sql .= $hookmanager->resPrint;
$sql .= " ORDER BY s.tms DESC";
$sql .= $this->db->plimit($max, 0);