Skip to content
Extraits de code Groupes Projets
Valider 1219b4d9 rédigé par Olivier BÈGUE's avatar Olivier BÈGUE
Parcourir les fichiers

?

parent 4024486f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -6,7 +6,9 @@
* Time: 08:37
*/
require_once('db_connect.php');
require_once('Evenement.php');
require_once('Commande.php');
require_once('Utilisateur.php');
/**@brief récupère le nom de l'evenement actuel
*
* @return NULL Si il n'y a aucun evenement courant
......@@ -15,7 +17,7 @@ require_once('db_connect.php');
function db_getActuelEvenement(){
$pdo = $GLOBALS['connection'];
$dateToday = date("Y-m-d");
$statement = $pdo->prepare("SELECT * FROM event WHERE event.date_debut < '?' AND event.date_fin > '?'");
$statement = $pdo->prepare("SELECT * FROM event WHERE event.date_start < '?' AND event.date_end > '?'");
$statement->execute([$dateToday, $dateToday]);
$event = $statement->fetch();
......@@ -42,7 +44,7 @@ function db_getAllFoods(){
$typeFoods['idPart'] = $part['idPartenariat'];
$typeFoods['typeFood'] = array();
$statement_typeFoods = $pdo->prepare(
"SELECT TF.foodTypeID, TF.nomTypeFood
"SELECT DISTINCT TF.foodTypeID, TF.nomTypeFood
FROM foods AS F INNER JOIN foodtype AS TF ON F.foodTypeID = TF.foodtypeID
WHERE F.partID = ?
GROUP BY foodTypeID"
......@@ -124,21 +126,151 @@ function db_getAllSpecials(){
return $specials;
}
function db_getActuelCommandes($idUtilisateur){
function db_getAllUsers(){
$pdo = $GLOBALS['connection'];
$statement = $pdo->prepare("
SELECT ariseID FROM utilisateur ORDER BY CASE WHEN pseudo IS NULL THEN prenom ELSE pseudo END
");
$statement->execute();
$res = $statement->fetch();
if($res == FALSE){
return NULL;
}
$users = array();
do{
array_push($users, db_getUser($res['ariseID']));
}while($res = $statement->fetch());
return $users;
}
function db_getUser($idUser){
$pdo = $GLOBALS['connection'];
$statement = $pdo->prepare("
SELECT * FROM utilisateur WHERE utilisateur.ariseID = ?
");
$statement->execute([$idUser]);
$res = $statement->fetch();
if($res == FALSE){
return NULL;
}
assert($idUser == $res['ariseID']);
return new Utilisateur( $idUser,
$res['prenom'],
$res['nom'],
$res['pseudo'],
(($res['isAdmin'] == 0)? FALSE : TRUE),
db_getCommandesUtilisateur($idUser)
);
}
/** A ne pas utiliser en dehors de "db_getUser"
**/
function db_getCommandesUtilisateur($idUtilisateur){
//Get numero de l'evenement actuel
//SI pas d'evenement actuel : throw exception
//Sinon, appel SQL, get commande with USERID=$id AND EVENTID=$eventID
$id_evenement = db_getActuelEvenement()->id_evenement;
if ($id_evenement == NULL)
{
//throw exception Invalid_Evenement("Il n'y a pas d'évènement actuellement");
}
else
$evenement = db_getActuelEvenement();
if ($evenement == NULL)
{
//$actuel_commandes = ...;
return array();
}
$pdo = $GLOBALS['connection'];
$statement = $pdo->prepare(
"SELECT C.idCommande, C.dateTimeCommande, C.isPaid,
I.idItemCommande,
F.foodID, FT.nomTypeFood, F.foodTypeID, F.nomFood,
P.nomPartenariat, P.idPartenariat,
F.priceIIE, F.pricePart,
S.specialItemID, S.nomSpecialItem,
T.specialTypeID, T.nomSpecialType
FROM commande AS C
LEFT OUTER JOIN commande_item AS I ON C.idCommande = I.idCommande
LEFT OUTER JOIN foods AS F ON F.foodID = I.idFood
LEFT OUTER JOIN foodtype AS FT ON FT.foodTypeID = F.foodTypeID
LEFT OUTER JOIN partenariat AS P ON P.idPartenariat = F.partID
LEFT OUTER JOIN item_commande_has_special HS ON HS.idItemCommande = I.idItemCommande
LEFT OUTER JOIN special_item S ON S.specialItemID = HS.idItemSpecial
LEFT OUTER JOIN special_type T ON T.specialTypeID = S.specialTypeID
WHERE C.userID = ? AND C.eventID = ?
ORDER BY C.dateTimeCommande,
P.nomPartenariat,
FT.nomTypeFood,
F.nomFood"
);
$statement->execute([$idUtilisateur, $evenement->getIDEvenement()]);
$allComands = array();
while($res = $statement->fetch()){
if(!isset($allComands[$res['idCommande']])){
$allComands[$res['idCommande']]
= new Commande($res['idCommande'],
$idUtilisateur,
$res['dateTimeCommande'],
$res['isPaid'],
array()
);
}
$tmpArray = $allComands[$res['idCommande']]->getMenus();
$lastMenu = end($tmpArray);
$idLastMenu = -1;
if($lastMenu != FALSE){
$idLastMenu = $lastMenu->getIDMenu();
}
if($lastMenu == FALSE || $idLastMenu != $res['idItemCommande']){
$lastMenu = new Menu(
$res['idItemCommande'],
new Nourriture(
$res['foodID'],
$res['nomTypeFood'],
$res['foodTypeID'],
$res['nomFood'],
$res['nomPartenariat'],
$res['idPartenariat'],
$res['priceIIE'],
$res['pricePart']
),
array()
);
if($res['specialItemID'] != NULL){
$lastMenu->addSpecial(new Special(
$res['specialItemID'],
$res['nomSpecialType'],
$res['specialTypeID'],
$res['nomSpecialItem']
)
);
}
$allComands[$res['idCommande']]->addMenus($lastMenu);
//$lastMenu = end($allComands[$res['idCommande']]->getMenus());
}else{
assert($idLastMenu == $res['idItemCommande']);
if($res['specialItemID'] != NULL){
$tempArray =$allComands[$res['idCommande']]->getMenus();
$newMenu = end($tempArray);
$newMenu->addSpecial(new Special(
$res['specialItemID'],
$res['nomSpecialType'],
$res['specialTypeID'],
$res['nomSpecialItem']
)
);
$allComands[$res['idCommande']]->updateLastMenu($newMenu);
}
}
/*
$allComands[$res['idCommande']]->getMenus()[key($lastMenu)]->
addSpecial(
new Special(
$res['specialItemID'],
$res['nomSpecialType'],
$res['specialTypeID'],
$res['nomSpecialItem']
)
);
*/
}
return $allComands;
}
/**
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter