diff --git a/commandes_njv_mySql.sql b/commandes_njv_mySql.sql index e1c5972ee75d969799aca980a5f221275c27f5a4..7c4ab0312adf3313f0451688805fafb72fe9b63a 100644 --- a/commandes_njv_mySql.sql +++ b/commandes_njv_mySql.sql @@ -75,7 +75,8 @@ INSERT INTO `event` (`eventID`, `typeEvent`, `numeroEvent`, `date_start`, `date_ (1, 'NJV', 55, '2019-02-22', '2019-03-01'), (2, 'NJV', 56, '2019-03-29', '2019-04-05'), (3, 'NJV', 57, '2019-04-26', '2019-05-03'), -(4, 'NJV', 58, '2019-09-01', '2019-09-05'); +(4, 'NJV', 58, '2019-09-01', '2019-09-05'), +(5, 'ObiLan', 42, '2019-05-09', '2019-06-30'); -- -------------------------------------------------------- @@ -181,9 +182,9 @@ ALTER TABLE commande -- INSERT INTO `commande` (`idCommande`, `userID`, `eventID`, `dateTimeCommande`, `isPaid`) VALUES -(1, 'maret2016', 3, '2019-05-01 18:23:24.000000', 0), -(2, 'maret2016', 3, '2019-05-01 18:25:10.000000', 0), -(3, 'wang2017', 2, '2019-04-04 18:25:10.000000', 1); +(1, 'maret2016', 5, '2019-05-01 18:23:24.000000', 0), +(2, 'maret2016', 5, '2019-05-01 18:25:10.000000', 0), +(3, 'wang2017', 5, '2019-04-04 18:25:10.000000', 1); -- -------------------------------------------------------- @@ -368,7 +369,9 @@ ALTER TABLE item_commande_has_special INSERT INTO `item_commande_has_special` (`idItemCommande`, `idItemSpecial`) VALUES (2, 5), (2, 6), -(2, 7); +(2, 7), +(2, 1), +(2, 2); -- -------------------------------------------------------- diff --git a/ensiie-project/src/Model/Classes/Commande.php b/ensiie-project/src/Model/Classes/Commande.php index 7c6c10e662da491b5b3004b2af10c9c40696c0d2..16500ae427a1560f140481040949bbe3cd4c1c2c 100644 --- a/ensiie-project/src/Model/Classes/Commande.php +++ b/ensiie-project/src/Model/Classes/Commande.php @@ -55,7 +55,7 @@ class Commande public function setDate($date) { - $this->date = $date + $this->date = $date; } public function getPaid() //je trouve ca drole comme blague :/ @@ -72,6 +72,11 @@ class Commande array_push($this->menus, $menu); } + public function updateLastMenu($newMenu){ + array_pop($this->menus); + $this->addMenus($newMenu); + } + public function toString(){ $str = ""; foreach($this->getMenus() as $menu) diff --git a/ensiie-project/src/Model/Classes/Menu.php b/ensiie-project/src/Model/Classes/Menu.php index c363ccc18129ecd49ccce438a033c002752bc04c..8758da4db9fcbf6b052255eb71b9e952eb0258c9 100644 --- a/ensiie-project/src/Model/Classes/Menu.php +++ b/ensiie-project/src/Model/Classes/Menu.php @@ -58,7 +58,11 @@ class Menu $this->specials = $specials; } - public getNbSauces() + public function addSpecial($special){ + array_push($this->specials, $special); + } + + public function getNbSauces() { $nb = 0; foreach($specials as $special) diff --git a/ensiie-project/src/Model/db_data.php b/ensiie-project/src/Model/db_data.php index ef4ff583fb67f1fad910cd9b119992626f15c1e8..7171415f0fe10f44a5f80cbfa98a6ad632e033cc 100644 --- a/ensiie-project/src/Model/db_data.php +++ b/ensiie-project/src/Model/db_data.php @@ -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 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 = 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; } /** @@ -152,7 +284,7 @@ function getActuelCommandes($idUtilisateur){ * @param $nom */ function addCommande($utilisateur, $evenement, $commande, $nom){ - $actuel_evenement = getActuelEvenement(); + $actuel_evenement = db_getActuelEvenement(); assert($evenement['id_evenement'] == $actuel_evenement['id_evenement']); }