public function orderHistory() { $this->lock(); $cartManager = new CartManager(); $bookManager = new BookManager(); $cartToBooks = []; $cartToBooksInRent = []; $orderEmpty = ""; $orderInRentEmpty = ""; // Récupérer tous les Ids des carts de l'user dont le statut est "1" $status = 1; $cartsInRent = $cartManager->findOrder($_SESSION['user']['id'], $status); if (!empty($cartsInRent)) { $cartsIdsInRent = []; foreach ($cartsInRent as $cartInRent) { $cartsIdsInRent[] = $cartInRent['id']; } // Récupérer les infos des Carts $carts = $cartManager->showCarts($cartsIdsInRent); // Associer les carts et les livres correspondants foreach ($carts as $cart) { $cartInRentBeginDate = $cart['begin_date']; // $cartEndDate = $cart['end_date']; $cartId = $cart['id']; $bookIds = $cartManager->findAllBooksIdsInCart($cartId); $booksInRent = $bookManager->showBooks($bookIds); $cartToBooksInRent[] = ['orderInRentEmpty' => $orderInRentEmpty, 'cartInRentBeginDate' => $cartInRentBeginDate, 'booksInRent' => $booksInRent]; } } else { $orderInRentEmpty = "Vous n'avez pas de commande en cours."; } // Récupérer tous les Ids des carts de l'user dont le statut est "2" $status = 2; $cartsAlreadyReturned = $cartManager->findOrder($_SESSION['user']['id'], $status); if (!empty($cartsAlreadyReturned)) { $cartsIdsAlreadyReturned = []; foreach ($cartsAlreadyReturned as $cartAlreadyReturned) { $cartsIdsAlreadyReturned[] = $cartAlreadyReturned['id']; } // Récupérer les infos des Carts $carts = $cartManager->showCarts($cartsIdsAlreadyReturned); // debug($carts); // Associer les carts et les livres correspondants foreach ($carts as $cart) { $cartBeginDate = $cart['begin_date']; $cartEndDate = $cart['end_date']; $cartId = $cart['id']; $bookIds = $cartManager->findAllBooksIdsInCart($cartId); $books = $bookManager->showBooks($bookIds); $cartToBooks[] = ['orderEmpty' => $orderEmpty, 'cartBeginDate' => $cartBeginDate, 'cartEndDate' => $cartEndDate, 'books' => $books]; } } else { $orderEmpty = "Vous n'avez pas encore effectué de commandes"; } $data = ['cartToBooks' => $cartToBooks, 'cartToBooksInRent' => $cartToBooksInRent, 'orderEmpty' => $orderEmpty, 'orderInRentEmpty' => $orderInRentEmpty]; $this->show('user/order_history', $data); }