2
0
forked from Wavyzz/dolibarr

add hook 'functionGetEntity' to manipulate entities for queries on the fly

This commit is contained in:
Christian Foellmann
2021-08-26 15:04:59 +02:00
parent ac2fc9c57f
commit ac7f0f8a4e
2 changed files with 22 additions and 3 deletions

View File

@@ -104,7 +104,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
*/
function getEntity($element, $shared = 1, $currentobject = null)
{
global $conf, $mc;
global $conf, $mc, $hookmanager, $object;
// fix different element names (France to English)
switch ($element) {
@@ -117,7 +117,7 @@ function getEntity($element, $shared = 1, $currentobject = null)
}
if (is_object($mc)) {
return $mc->getEntity($element, $shared, $currentobject);
$out = $mc->getEntity($element, $shared, $currentobject);
} else {
$out = '';
$addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
@@ -125,8 +125,26 @@ function getEntity($element, $shared = 1, $currentobject = null)
$out .= '0,';
}
$out .= ((int) $conf->entity);
return $out;
}
// Manipulate entities to query on the fly
$parameters = array(
'object' => $object,
'currentobject' => $currentobject,
'element' => $element,
'shared' => $shared,
);
$reshook = $hookmanager->executeHooks('functionGetEntity', $parameters, $out, $element); // Note that $action and $object may have been modified by some hooks
if (is_numeric($reshook)) {
if ($reshook == 0 && !empty($hookmanager->resprints)) {
$out .= ','.$hookmanager->resprints; // add
} elseif ($reshook == 1) {
$out = $hookmanager->resprints; // replace
}
}
return $out;
}
/**