ajout d'une intervention vFinal

This commit is contained in:
pierre renaudot
2023-11-30 12:14:44 +01:00
parent 062e417a9c
commit 6f165b76f2
5 changed files with 204 additions and 34 deletions

View File

@@ -79,10 +79,10 @@ class PdoBD
public function getInfosPompier($login, $mdp)
{
/*
$req = "SELECT pCis, pId as id, pNom as nom, pPrenom as prenom, pStatut, pMail, pLogin, pMdp, pGrade, pAdresse, pCp, pVille, pBip, pCommentaire,
'la caserne' as cNom, 'adresse' as cAdresse, 'telephone' as cTel, 'le groupement' as cGroupement, 'le grade' as wGrade, 'le statut' as wStatut, 'le type' as wType
FROM pompier";
*/
$req = "SELECT pCis, pId as id, pNom as nom, pPrenom as prenom, pStatut, pMail, pLogin, pMdp, pGrade, pAdresse, pCp, pVille, pBip, pCommentaire,
'la caserne' as cNom, 'adresse' as cAdresse, 'telephone' as cTel, 'le groupement' as cGroupement, 'le grade' as wGrade, 'le statut' as wStatut, 'le type' as wType
FROM pompier";
*/
$req = "SELECT
pCis,
pId as id,
@@ -358,8 +358,8 @@ class PdoBD
$lesDispos[$pompier][$laDate][$couleur] = $uneLigne['dCouleur'];
}
/* echo "<PRE>";
print_r($lesDispos);
echo "</PRE>";*/
print_r($lesDispos);
echo "</PRE>";*/
return $lesDispos;
}
@@ -581,7 +581,7 @@ class PdoBD
$cat = PdoBD::$monPdo->query($req);
$cat = $cat->fetchAll();
//Valeur : nbUtil
//Valeur : nbUtilisation
//Plancher : Time
//Plafond: nbPompier estimé
$reqType = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond
@@ -655,6 +655,109 @@ class PdoBD
return $result->fetchAll();
}
public function getCurrentTranche()
{
$req = "SELECT pIndice
FROM parametre
WHERE pType = 'tranche' AND :heure >= pPlancher AND :heure < pPlafond;";
$result = PdoBD::$monPdo->prepare($req);
$hour = date("H");
$result->bindParam(':heure', $hour);
$result->execute();
$result = $result->fetch();
return $result['pIndice'];
}
public function getLastIdIntervention(int $cis)
{
$req = "SELECT iId
FROM `intervention`
WHERE iCis = :cis;";
$result = PdoBD::$monPdo->prepare($req);
$result->bindParam(':cis', $cis);
$result->execute();
$result = $result->fetch();
$id = isset($result['iId']) ? $result['iId'] : 0;
return $id;
}
/**
* Crée une nouvelle intervention
*/
public function newIntervention(
int $motif,
int $caserne,
string $adresse,
string $description,
array $pompier
) {
/**
* Nouvelle intervention
*/
$req = " INSERT INTO intervention
VALUES(:caserne, :id, :adresse, :description,
NOW(), :tranche, NOW(), NULL, :motif, :nbPompier);";
$result = PdoBD::$monPdo->prepare($req);
$result->bindParam(':caserne', $caserne);
$result->bindParam(':adresse', $adresse);
$result->bindParam(':description', $description);
$result->bindParam(':motif', $motif);
$nbPompier = count($pompier);
$result->bindParam(':nbPompier', $nbPompier);
$tranche = $this->getCurrentTranche();
$result->bindParam(':tranche', $tranche);
$idIntervention = $this->getLastIdIntervention($caserne) + 1;
$result->bindParam(':id', $idIntervention);
$result->execute();
/**
* Nouvelle équipe
*/
foreach ($pompier as $value) {
var_dump($value);
foreach ($value as $key => $value) {
$req2 = "INSERT INTO equipe
VALUES (:caserne, :pompier, :intervention)";
$result2 = PdoBD::$monPdo->prepare($req2);
$result2->bindParam('caserne', $caserne);
$result2->bindParam('intervention', $idIntervention);
if ($value == 0) {
$result2->bindParam('pompier', $key);
$result2->execute();
} else {
$currentIntervention = "SELECT iId
FROM intervention
LEFT OUTER JOIN equipe on intervention.iId = equipe.eIntervention AND intervention.iCis = equipe.eCis
WHERE iHeureFin IS NULL AND equipe.ePompier = :pompier AND equipe.eCis = :caserne;";
$curentId = PdoBD::$monPdo->prepare($currentIntervention);
$curentId->bindParam('pompier', $key);
$curentId->bindParam('caserne', $caserne);
$curentId->execute();
$curentId = $curentId->fetch();
$reqSuprInter = "DELETE FROM equipe
WHERE eCis = :caserne AND ePompier = :pompier AND eIntervention = :intervention";
$suprInter = PdoBD::$monPdo->prepare($reqSuprInter);
$suprInter->bindParam('caserne', $caserne);
$suprInter->bindParam('pompier', $key);
$suprInter->bindParam('intervention', $currentId['iId']);
$suprInter->execute();
}
}
}
}
}
/**