108 lines
4.7 KiB
PHP
108 lines
4.7 KiB
PHP
<?php
|
|
namespace Module\ACM\Classe\GestionBD;
|
|
class gestionUtilisateur {
|
|
|
|
/**
|
|
* @return array|false renvoie tous les employés ou faux en cas d'erreur sql
|
|
*/
|
|
public static function getAllEmployer(){
|
|
global $db;
|
|
$db->query("SET NAMES 'utf8mb4'");
|
|
$list = [];
|
|
$sql = " SELECT rowid, entity, ref_employee, ref_ext, admin, employee, fk_establishment, login, gender, civility
|
|
, lastname, firstname, job, fk_member, fk_user, fk_user_holiday_validator, idpers1, idpers2,
|
|
idpers3, datelastlogin, dateendvalidity, statut, photo, color, barcode, fk_barcode_type,
|
|
nb_holiday, thm, tjm, salary, salaryextra, dateemployment, dateemploymentend, weeklyhours,
|
|
national_registration_number
|
|
FROM llx_user
|
|
WHERE employee = 1
|
|
ORDER BY fk_establishment, lastname, login";
|
|
$resql=$db->query($sql);
|
|
if ($resql) {
|
|
// Parcours des résultats avec fetch_array
|
|
while ($row = $db->fetch_array($resql)) {
|
|
// Accès aux colonnes via leur index ou alias
|
|
$list[] = ["id"=>$row['rowid'], "login"=>$row['login']];
|
|
}
|
|
} else { return false; }
|
|
return $list;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @param $nom string nom de l'utilisateur
|
|
* @return array|false return l'id de l'utilisateur
|
|
*/
|
|
public static function getIdParNom($nom) {
|
|
global $db;
|
|
$db->query("SET NAMES 'utf8mb4'");
|
|
$nom = $db->escape($nom);
|
|
$sql = "SELECT rowid FROM llx_user WHERE login = '$nom'";
|
|
$resql=$db->query($sql);
|
|
if ($resql) {
|
|
$row = $db->fetch_array($resql);
|
|
$row = $row['rowid'];
|
|
return $row;
|
|
} else { return false; }
|
|
}
|
|
|
|
/**
|
|
* @param $nom string nom de l'utilisateur
|
|
* @param $code string type de congee de dolibarr
|
|
* @return array|false return la liste des dates congées des utilisateurs ou faux en cas d'erreur sql
|
|
*/
|
|
public static function getListeCongeeParNomEtCode(string $nom, string $code) {
|
|
$id = self::getIdParNom($nom);
|
|
global $db;
|
|
$db->query("SET NAMES 'utf8mb4'");
|
|
$list = [];
|
|
$matin = "08:00"; $soir = "15:00";
|
|
$id = $db->escape($id); // pour protéger contre l'injection sql
|
|
$code = $db->escape($code);
|
|
$sql = "SELECT h.date_debut, h.date_fin, t.code, h.halfday FROM llx_holiday h JOIN llx_c_holiday_types t on h.fk_type = t.rowid WHERE h.fk_user = '$id' and h.date_approval IS NOT NULL and code = '$code'";
|
|
$resql=$db->query($sql);
|
|
if ($resql) {
|
|
while ($row = $db->fetch_array($resql)) {
|
|
$debut = $matin;
|
|
$fin = $soir;
|
|
if ($row['halfday'] == "2") {$debut = $soir;$fin = $matin;}
|
|
if ($row['halfday'] == "-1") {$debut = $soir;}
|
|
if ($row['halfday'] == "1") {$fin = $matin;}
|
|
$list[] = ["date_debut" => $row['date_debut']." ".$debut, "date_fin" => $row['date_fin']." ".$fin, "type" => $row['code']];
|
|
}
|
|
} else { return false; }
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* @param $nom string nom de l'utilisateur
|
|
* @param $code1 string type de congé à recuperer
|
|
* @param $code2 string type de congé à recuperer
|
|
* @return array|false renvoie la liste des congés correspondent à au moins un des deux codes ou faux en cas d'erreur sql
|
|
*/
|
|
public static function getListeCongeeParNomEtDeuxCode(string $nom, string $code1, string $code2) {
|
|
$id = self::getIdParNom($nom);
|
|
global $db;
|
|
$db->query("SET NAMES 'utf8mb4'");
|
|
$list = [];
|
|
$matin = "08:00"; $soir = "15:00";
|
|
$id = $db->escape($id); // pour protéger contre l'injection sql
|
|
$code1 = $db->escape($code1);
|
|
$code2 = $db->escape($code2);
|
|
$sql = "SELECT h.date_debut, h.date_fin, t.code, h.halfday FROM llx_holiday h JOIN llx_c_holiday_types t on h.fk_type = t.rowid WHERE h.fk_user = '$id' and h.date_approval IS NOT NULL and (code = '$code1' OR code = '$code2')";
|
|
$resql=$db->query($sql);
|
|
if ($resql) {
|
|
while ($row = $db->fetch_array($resql)) {
|
|
$debut = $matin;
|
|
$fin = $soir;
|
|
if ($row['halfday'] == "2") {$debut = $soir;$fin = $matin;}
|
|
if ($row['halfday'] == "-1") {$debut = $soir;}
|
|
if ($row['halfday'] == "1") {$fin = $matin;}
|
|
$list[] = ["date_debut" => $row['date_debut']." ".$debut, "date_fin" => $row['date_fin']." ".$fin, "type" => $row['code']];
|
|
}
|
|
} else { return false; }
|
|
return $list;
|
|
}
|
|
|
|
} |