diff --git a/ensiie-project/src/Model/db_data.php b/ensiie-project/src/Model/db_data.php index 7171415f0fe10f44a5f80cbfa98a6ad632e033cc..823b3e78cba83eb3ecf23e8172e782888abdff9e 100644 --- a/ensiie-project/src/Model/db_data.php +++ b/ensiie-project/src/Model/db_data.php @@ -257,17 +257,6 @@ function db_getCommandesUtilisateur($idUtilisateur){ $allComands[$res['idCommande']]->updateLastMenu($newMenu); } } - /* - $allComands[$res['idCommande']]->getMenus()[key($lastMenu)]-> - addSpecial( - new Special( - $res['specialItemID'], - $res['nomSpecialType'], - $res['specialTypeID'], - $res['nomSpecialItem'] - ) - ); - */ } return $allComands; @@ -281,12 +270,35 @@ function db_getCommandesUtilisateur($idUtilisateur){ * La variable contenant les informations de l'évenement pour lequel l'utilisateur commande * @param $commande * La variable contenant les informations de la commande - * @param $nom */ -function addCommande($utilisateur, $evenement, $commande, $nom){ +function addCommande($utilisateur, $evenement, $commande){ $actuel_evenement = db_getActuelEvenement(); - assert($evenement['id_evenement'] == $actuel_evenement['id_evenement']); - + assert(strtotime($commande->getDate()) < strtotime($actuel_evenement->getDate())); + $pdo = $GLOBALS['connection']; + $statement = $pdo->prepare( + "INSERT INTO commande (userID, eventID, dateTimeCommande, isPaid) + VALUES (?, ?, ?, ?)" + ); + $date = date_format($commande->getDate(), "Y-m-d H:i:s"); + if(!$statement->execute([$commande->getUtilisateurID(), + $actuel_evenement->getIDEvenement(), + $date, + 0, + ])) + { + throw new Exception("Can't insert Commande !"); + } + $idCommande = $pdo->lastInsertId(); + foreach($commande->getMenus() as $menu){ + $statement_commandeItem = $pdo->prepare( + "INSERT INTO idItemCommande (idCommande, idFood) + VALUES (?, ?)" + ); + if(!$statement_commandeItem->execute([$idCommande, + $menu->getNourriture()->getIDNourriture() + ]); + + } } ?> \ No newline at end of file