cut fonction in two parts
This commit is contained in:
parent
8430b66214
commit
4578411c23
@ -1600,201 +1600,229 @@ class Holiday extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function fetchUsers($stringlist = true, $type = true, $filters = '')
|
public function fetchUsers($stringlist = true, $type = true, $filters = '')
|
||||||
{
|
{
|
||||||
global $conf;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
|
||||||
|
|
||||||
if ($stringlist)
|
if ($stringlist) {
|
||||||
|
$this->fetchUsersById($type, $filters);
|
||||||
|
} else {
|
||||||
|
$this->fetchUsersByDetail($type, $filters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of Users or list of vacation balance by User Id
|
||||||
|
*
|
||||||
|
* @param boolean $type If true, read Dolibarr user list, if false, return vacation balance list.
|
||||||
|
* @param string $filters Filters
|
||||||
|
* @return array|string|int Return an array
|
||||||
|
*/
|
||||||
|
public function fetchUsersById($type = true, $filters = '')
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::fetchUsersById", LOG_DEBUG);
|
||||||
|
|
||||||
|
if ($type)
|
||||||
{
|
{
|
||||||
if ($type)
|
// If user of Dolibarr
|
||||||
|
$sql = "SELECT";
|
||||||
|
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||||
|
$sql .= " DISTINCT";
|
||||||
|
}
|
||||||
|
$sql .= " u.rowid";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||||
|
|
||||||
|
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
||||||
{
|
{
|
||||||
// If user of Dolibarr
|
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
|
||||||
$sql = "SELECT";
|
$sql .= " WHERE ((ug.fk_user = u.rowid";
|
||||||
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
|
||||||
$sql .= " DISTINCT";
|
$sql .= " OR u.entity = 0)"; // Show always superadmin
|
||||||
}
|
|
||||||
$sql .= " u.rowid";
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
|
||||||
|
|
||||||
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
|
||||||
{
|
|
||||||
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
|
|
||||||
$sql .= " WHERE ((ug.fk_user = u.rowid";
|
|
||||||
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
|
|
||||||
$sql .= " OR u.entity = 0)"; // Show always superadmin
|
|
||||||
} else {
|
|
||||||
$sql .= " WHERE u.entity IN (".getEntity('user').")";
|
|
||||||
}
|
|
||||||
$sql .= " AND u.statut > 0";
|
|
||||||
if ($filters) $sql .= $filters;
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
|
|
||||||
// Si pas d'erreur SQL
|
|
||||||
if ($resql) {
|
|
||||||
$i = 0;
|
|
||||||
$num = $this->db->num_rows($resql);
|
|
||||||
$stringlist = '';
|
|
||||||
|
|
||||||
// Boucles du listage des utilisateurs
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($resql);
|
|
||||||
|
|
||||||
if ($i == 0) {
|
|
||||||
$stringlist .= $obj->rowid;
|
|
||||||
} else {
|
|
||||||
$stringlist .= ', '.$obj->rowid;
|
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
// Retoune le tableau des utilisateurs
|
|
||||||
return $stringlist;
|
|
||||||
} else {
|
|
||||||
// Erreur SQL
|
|
||||||
$this->error = "Error ".$this->db->lasterror();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// We want only list of vacation balance for user ids
|
$sql .= " WHERE u.entity IN (".getEntity('user').")";
|
||||||
$sql = "SELECT DISTINCT cpu.fk_user";
|
}
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
|
$sql .= " AND u.statut > 0";
|
||||||
$sql .= " WHERE cpu.fk_user = u.rowid";
|
if ($filters) $sql .= $filters;
|
||||||
if ($filters) $sql .= $filters;
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
// Si pas d'erreur SQL
|
// Si pas d'erreur SQL
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
$stringlist = '';
|
$stringlist = '';
|
||||||
|
|
||||||
// Boucles du listage des utilisateurs
|
// Boucles du listage des utilisateurs
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
if ($i == 0) {
|
if ($i == 0) {
|
||||||
$stringlist .= $obj->fk_user;
|
$stringlist .= $obj->rowid;
|
||||||
} else {
|
} else {
|
||||||
$stringlist .= ', '.$obj->fk_user;
|
$stringlist .= ', '.$obj->rowid;
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
// Retoune le tableau des utilisateurs
|
|
||||||
return $stringlist;
|
$i++;
|
||||||
} else {
|
|
||||||
// Erreur SQL
|
|
||||||
$this->error = "Error ".$this->db->lasterror();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
// Retoune le tableau des utilisateurs
|
||||||
|
return $stringlist;
|
||||||
|
} else {
|
||||||
|
// Erreur SQL
|
||||||
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Si faux donc return array
|
// We want only list of vacation balance for user ids
|
||||||
// List for Dolibarr users
|
$sql = "SELECT DISTINCT cpu.fk_user";
|
||||||
if ($type)
|
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
|
||||||
{
|
$sql .= " WHERE cpu.fk_user = u.rowid";
|
||||||
// If user of Dolibarr
|
if ($filters) $sql .= $filters;
|
||||||
$sql = "SELECT";
|
|
||||||
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
||||||
$sql .= " DISTINCT";
|
|
||||||
}
|
|
||||||
$sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
|
||||||
|
|
||||||
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
|
// Si pas d'erreur SQL
|
||||||
|
if ($resql) {
|
||||||
|
$i = 0;
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
$stringlist = '';
|
||||||
|
|
||||||
|
// Boucles du listage des utilisateurs
|
||||||
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
|
$obj = $this->db->fetch_object($resql);
|
||||||
$sql .= " WHERE ((ug.fk_user = u.rowid";
|
|
||||||
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
|
|
||||||
$sql .= " OR u.entity = 0)"; // Show always superadmin
|
|
||||||
} else {
|
|
||||||
$sql .= " WHERE u.entity IN (".getEntity('user').")";
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql .= " AND u.statut > 0";
|
if ($i == 0) {
|
||||||
if ($filters) $sql .= $filters;
|
$stringlist .= $obj->fk_user;
|
||||||
|
} else {
|
||||||
$resql = $this->db->query($sql);
|
$stringlist .= ', '.$obj->fk_user;
|
||||||
|
|
||||||
// Si pas d'erreur SQL
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$i = 0;
|
|
||||||
$tab_result = $this->holiday;
|
|
||||||
$num = $this->db->num_rows($resql);
|
|
||||||
|
|
||||||
// Boucles du listage des utilisateurs
|
|
||||||
while ($i < $num) {
|
|
||||||
$obj = $this->db->fetch_object($resql);
|
|
||||||
|
|
||||||
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
|
||||||
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
|
||||||
$tab_result[$i]['lastname'] = $obj->lastname;
|
|
||||||
$tab_result[$i]['firstname'] = $obj->firstname;
|
|
||||||
$tab_result[$i]['gender'] = $obj->gender;
|
|
||||||
$tab_result[$i]['status'] = $obj->statut;
|
|
||||||
$tab_result[$i]['employee'] = $obj->employee;
|
|
||||||
$tab_result[$i]['photo'] = $obj->photo;
|
|
||||||
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
|
||||||
//$tab_result[$i]['type'] = $obj->type;
|
|
||||||
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
// Retoune le tableau des utilisateurs
|
|
||||||
return $tab_result;
|
$i++;
|
||||||
} else {
|
|
||||||
// Erreur SQL
|
|
||||||
$this->errors[] = "Error ".$this->db->lasterror();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
// Retoune le tableau des utilisateurs
|
||||||
|
return $stringlist;
|
||||||
} else {
|
} else {
|
||||||
// List of vacation balance users
|
// Erreur SQL
|
||||||
$sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
|
return -1;
|
||||||
$sql .= " WHERE cpu.fk_user = u.rowid";
|
}
|
||||||
if ($filters) $sql .= $filters;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
/**
|
||||||
|
* Get list of Users or list of vacation balance by detail
|
||||||
|
*
|
||||||
|
* @param boolean $type If true, read Dolibarr user list, if false, return vacation balance list.
|
||||||
|
* @param string $filters Filters
|
||||||
|
* @return array|string|int Return an array
|
||||||
|
*/
|
||||||
|
public function fetchUsersByDetail($type = true, $filters = '')
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
// Si pas d'erreur SQL
|
dol_syslog(get_class($this)."::fetchUsersByDetail", LOG_DEBUG);
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$i = 0;
|
|
||||||
$tab_result = $this->holiday;
|
|
||||||
$num = $this->db->num_rows($resql);
|
|
||||||
|
|
||||||
// Boucles du listage des utilisateurs
|
// List for Dolibarr users
|
||||||
while ($i < $num)
|
if ($type)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
// If user of Dolibarr
|
||||||
|
$sql = "SELECT";
|
||||||
|
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||||
|
$sql .= " DISTINCT";
|
||||||
|
}
|
||||||
|
$sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||||
|
|
||||||
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
||||||
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
{
|
||||||
$tab_result[$i]['lastname'] = $obj->lastname;
|
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
|
||||||
$tab_result[$i]['firstname'] = $obj->firstname;
|
$sql .= " WHERE ((ug.fk_user = u.rowid";
|
||||||
$tab_result[$i]['gender'] = $obj->gender;
|
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
|
||||||
$tab_result[$i]['status'] = $obj->statut;
|
$sql .= " OR u.entity = 0)"; // Show always superadmin
|
||||||
$tab_result[$i]['employee'] = $obj->employee;
|
} else {
|
||||||
$tab_result[$i]['photo'] = $obj->photo;
|
$sql .= " WHERE u.entity IN (".getEntity('user').")";
|
||||||
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
}
|
||||||
|
|
||||||
$tab_result[$i]['type'] = $obj->fk_type;
|
$sql .= " AND u.statut > 0";
|
||||||
$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
if ($filters) $sql .= $filters;
|
||||||
|
|
||||||
$i++;
|
$resql = $this->db->query($sql);
|
||||||
}
|
|
||||||
// Retoune le tableau des utilisateurs
|
// Si pas d'erreur SQL
|
||||||
return $tab_result;
|
if ($resql)
|
||||||
} else {
|
{
|
||||||
// Erreur SQL
|
$i = 0;
|
||||||
$this->error = "Error ".$this->db->lasterror();
|
$tab_result = $this->holiday;
|
||||||
return -1;
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
|
// Boucles du listage des utilisateurs
|
||||||
|
while ($i < $num) {
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
||||||
|
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
||||||
|
$tab_result[$i]['lastname'] = $obj->lastname;
|
||||||
|
$tab_result[$i]['firstname'] = $obj->firstname;
|
||||||
|
$tab_result[$i]['gender'] = $obj->gender;
|
||||||
|
$tab_result[$i]['status'] = $obj->statut;
|
||||||
|
$tab_result[$i]['employee'] = $obj->employee;
|
||||||
|
$tab_result[$i]['photo'] = $obj->photo;
|
||||||
|
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
||||||
|
//$tab_result[$i]['type'] = $obj->type;
|
||||||
|
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
||||||
|
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
// Retoune le tableau des utilisateurs
|
||||||
|
return $tab_result;
|
||||||
|
} else {
|
||||||
|
// Erreur SQL
|
||||||
|
$this->errors[] = "Error ".$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// List of vacation balance users
|
||||||
|
$sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
|
||||||
|
$sql .= " WHERE cpu.fk_user = u.rowid";
|
||||||
|
if ($filters) $sql .= $filters;
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
|
// Si pas d'erreur SQL
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$i = 0;
|
||||||
|
$tab_result = $this->holiday;
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
|
// Boucles du listage des utilisateurs
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
||||||
|
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
||||||
|
$tab_result[$i]['lastname'] = $obj->lastname;
|
||||||
|
$tab_result[$i]['firstname'] = $obj->firstname;
|
||||||
|
$tab_result[$i]['gender'] = $obj->gender;
|
||||||
|
$tab_result[$i]['status'] = $obj->statut;
|
||||||
|
$tab_result[$i]['employee'] = $obj->employee;
|
||||||
|
$tab_result[$i]['photo'] = $obj->photo;
|
||||||
|
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
||||||
|
|
||||||
|
$tab_result[$i]['type'] = $obj->fk_type;
|
||||||
|
$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
// Retoune le tableau des utilisateurs
|
||||||
|
return $tab_result;
|
||||||
|
} else {
|
||||||
|
// Erreur SQL
|
||||||
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1805,7 +1833,7 @@ class Holiday extends CommonObject
|
|||||||
* Return list of people with permission to validate leave requests.
|
* Return list of people with permission to validate leave requests.
|
||||||
* Search for permission "approve leave requests"
|
* Search for permission "approve leave requests"
|
||||||
*
|
*
|
||||||
* @return array Array of user ids
|
* @return array|int Array of user ids
|
||||||
*/
|
*/
|
||||||
public function fetch_users_approver_holiday()
|
public function fetch_users_approver_holiday()
|
||||||
{
|
{
|
||||||
@ -1936,7 +1964,8 @@ class Holiday extends CommonObject
|
|||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql)
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$error++; $this->errors[] = "Error ".$this->db->lasterror();
|
$error++;
|
||||||
|
$this->errors[] = "Error ".$this->db->lasterror();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
@ -2007,7 +2036,7 @@ class Holiday extends CommonObject
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On liste les résultats et on les ajoutent dans le tableau
|
// On liste les résultats et on les ajoute dans le tableau
|
||||||
while ($i < $num) {
|
while ($i < $num) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user