Merge pull request #8444 from hregis/develop_multicompany

NEW add printUserListWhere hook
This commit is contained in:
Laurent Destailleur 2018-03-24 16:42:57 +01:00 committed by GitHub
commit 0d563ad0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 53 deletions

View File

@ -2745,6 +2745,10 @@ class User extends CommonObject
function get_full_tree($deleteafterid=0, $filter='') function get_full_tree($deleteafterid=0, $filter='')
{ {
global $conf, $user; global $conf, $user;
global $hookmanager;
// Actions hooked (by external module)
$hookmanager->initHooks(array('userdao'));
$this->users = array(); $this->users = array();
@ -2754,23 +2758,11 @@ class User extends CommonObject
// Init $this->users array // Init $this->users array
$sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity"; // Distinct reduce pb with old tables with duplicates $sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity"; // Distinct reduce pb with old tables with duplicates
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
// TODO add hook // Add fields from hooks
if (! empty($conf->multicompany->enabled)) { $parameters=array();
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
if (! empty($user->admin) && empty($user->entity)) { if ($reshook > 0) {
if ($conf->entity == 1) { $sql.=$hookmanager->resPrint;
$sql.= " WHERE u.entity IS NOT NULL";
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else {
$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
$sql.= " WHERE ug.fk_user = u.rowid";
$sql.= " AND ug.entity IN (".getEntity('user').")";
}
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else { } else {
$sql.= " WHERE u.entity IN (".getEntity('user').")"; $sql.= " WHERE u.entity IN (".getEntity('user').")";
} }

View File

@ -46,6 +46,10 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
$companystatic = new Societe($db); $companystatic = new Societe($db);
$fuserstatic = new User($db); $fuserstatic = new User($db);
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$contextpage=array('userhome');
$hookmanager->initHooks($contextpage);
/* /*
* View * View
@ -101,23 +105,11 @@ $sql.= ", s.code_client";
$sql.= ", s.canvas"; $sql.= ", s.canvas";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
// TODO add hook // Add fields from hooks
if (! empty($conf->multicompany->enabled)) { $parameters=array();
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
if (! empty($user->admin) && empty($user->entity)) { if ($reshook > 0) {
if ($conf->entity == 1) { $sql.=$hookmanager->resPrint;
$sql.= " WHERE u.entity IS NOT NULL";
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else {
$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
$sql.= " WHERE ug.fk_user = u.rowid";
$sql.= " AND ug.entity IN (".getEntity('user').")";
}
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else { } else {
$sql.= " WHERE u.entity IN (".getEntity('user').")"; $sql.= " WHERE u.entity IN (".getEntity('user').")";
} }

View File

@ -191,23 +191,11 @@ $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields as ef on (u.rowid = ef.fk_object)"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields as ef on (u.rowid = ef.fk_object)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid";
// TODO add hook // Add fields from hooks
if (! empty($conf->multicompany->enabled)) { $parameters=array();
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
if (! empty($user->admin) && empty($user->entity)) { if ($reshook > 0) {
if ($conf->entity == 1) { $sql.=$hookmanager->resPrint;
$sql.= " WHERE u.entity IS NOT NULL";
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else {
$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
$sql.= " WHERE ug.fk_user = u.rowid";
$sql.= " AND ug.entity IN (".getEntity('user').")";
}
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
} else { } else {
$sql.= " WHERE u.entity IN (".getEntity('user').")"; $sql.= " WHERE u.entity IN (".getEntity('user').")";
} }