NEW add printUserListWhere hook

This commit is contained in:
Regis Houssin 2018-03-23 10:42:36 +01:00
parent 171ad5dce2
commit 715852569b
3 changed files with 28 additions and 5 deletions

View File

@ -2744,7 +2744,11 @@ class User extends CommonObject
*/
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();
@ -2754,7 +2758,11 @@ class User extends CommonObject
// 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.= " FROM ".MAIN_DB_PREFIX."user as u";
// TODO add hook
// Add fields from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
/*
if (! empty($conf->multicompany->enabled)) {
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (! empty($user->admin) && empty($user->entity)) {
@ -2774,6 +2782,7 @@ class User extends CommonObject
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
*/
if ($filter) $sql.=" AND ".$filter;
dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG);

View File

@ -46,6 +46,10 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
$companystatic = new Societe($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
@ -101,7 +105,11 @@ $sql.= ", s.code_client";
$sql.= ", s.canvas";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
// TODO add hook
// Add fields from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
/*
if (! empty($conf->multicompany->enabled)) {
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (! empty($user->admin) && empty($user->entity)) {
@ -121,6 +129,7 @@ if (! empty($conf->multicompany->enabled)) {
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
*/
if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid;
$sql.= $db->order("u.datec","DESC");
$sql.= $db->plimit($max);
@ -225,7 +234,7 @@ if ($canreadperms)
$sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
$sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g";
if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
{
$sql.= " WHERE g.entity IS NOT NULL";
}

View File

@ -191,7 +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)";
$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";
// TODO add hook
// Add fields from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
/*
if (! empty($conf->multicompany->enabled)) {
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (! empty($user->admin) && empty($user->entity)) {
@ -211,6 +215,7 @@ if (! empty($conf->multicompany->enabled)) {
} else {
$sql.= " WHERE u.entity IN (".getEntity('user').")";
}
*/
if ($socid > 0) $sql.= " AND u.fk_soc = ".$socid;
//if ($search_user != '') $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_user);
if ($search_supervisor > 0) $sql.= " AND u.fk_user IN (".$db->escape($search_supervisor).")";