public function see($idRestaurant)
 {
     //Get the restaurant by its id
     $restaurant = Restaurant::getOneBy(array('_id' => new \MongoId($idRestaurant)));
     //If User is not logged in
     if (!Session::isConnected() || Session::getUser()->getType() != USER_CLIENT) {
         Session::addFlashMessage("Non connecté", "error", "Veuillez vous connecter avant de continuer.");
         return Redirect::to('/restaurant');
     }
     //If it doesn't exist, return to the list
     if (!$restaurant) {
         return Redirect::to('/restaurant');
     }
     $client = Session::getUser();
     $addresses = Address::getBy(array('user' => $client->getId()));
     if (Form::exists('order_form')) {
         $commande = new Commande();
         $menus = $restaurant->getMenus();
         $total = 0;
         foreach ($menus as $menu) {
             $menuItems = $menu->getMenuItems();
             foreach ($menuItems as $menuItem) {
                 $quantity = Form::get($menuItem->getId()->__toString());
                 if ($quantity > 0) {
                     $commande->setItem($menuItem, $quantity);
                 }
                 $total += $menuItem->getPrice() * $quantity;
             }
         }
         //If we didn't choose any item
         if ($total == 0) {
             return Redirect::to('/restaurant/see/' . $idRestaurant);
         }
         $commande->setPrice($total);
         $commande->setClient($client);
         $addressId = Form::get('address');
         $address = null;
         if ($addressId == 'altAddress') {
             //Then we take in accout the altAdress field
             $address = new Address();
             $address->setAddress(Form::get('altAdress'));
             $address->setUser($client);
         } else {
             $address = Address::getOneBy(array('_id' => new \MongoId($addressId)));
             if (!$address) {
                 die("Erreur à gérer.");
             }
         }
         $address->setByDefault();
         $address->save();
         $commande->setAddress($address);
         $commande->setStatus(Commande::COMMAND_STATUS_TEMPORARY);
         $commande->save();
         return Redirect::to("/restaurant/validateCommand/" . $commande->getId());
     }
     return View::render("restaurant/see.php", array('restaurant' => $restaurant, 'client' => Session::getUser(), 'addresses' => $addresses));
 }
 public function selectRestaurant($id = 0)
 {
     //If we are not connected as a Restaurateur, send to the login page
     if (!Session::isConnected() || Session::getUser()->getType() != USER_RESTAURATEUR) {
         return Redirect::to('/restaurateur/login');
     }
     //If no restaurant is specified, display the list
     if ($id == 0) {
         $restaurateur = Restaurateur::getOneBy(array('_id' => new \MongoId(Session::getUser()->getId())));
         $restaurants = $restaurateur->getRestaurants();
         return View::render("restaurateur/listeSelectRestaurant.php", array('restaurants' => $restaurants));
     }
     $restaurant = Restaurant::getOneBy(array('_id' => new \MongoId($id)));
     $menus = $restaurant->getMenus();
     if (Form::exists('menu_edit_form')) {
         $name = Form::get('name');
         if ($name == "" || is_null($name)) {
             Session::addFlashMessage("Erreur :", 'error', "Tous les champs ne sont pas remplis.");
             $error = "Veuillez remplir tous les champs";
             return View::render("restaurateur/listeEditeMenu.php", array('error' => $error, 'restaurant' => $restaurant, 'menus' => $menus));
         }
         //We check if the name is not already taken
         $found = Menu::getBy(array('name' => Form::get('name'), 'restaurant' => $restaurant->getId()));
         if ($found) {
             Session::addFlashMessage("Erreur :", 'error', "Le nom déjà pris.");
             $error = "Ce nom est déjà enregistré dans le menu.";
             return View::render("restaurateur/listeEditeMenu.php", array('error' => $error, 'restaurant' => $restaurant, 'menus' => $menus));
         }
         //We associate the values
         $menu = new Menu();
         $menu->setName(Form::get('name'));
         $menu->setRestaurant($restaurant);
         $menu->save();
         $restaurant->addMenu($menu);
         $restaurant->save();
     }
     $menus = $restaurant->getMenus();
     return View::render("restaurateur/listeEditeMenu.php", array('menus' => $menus, 'restaurant' => $restaurant));
 }
Beispiel #3
0
 private function addCommande()
 {
     $commandes = Commande::getBy(array());
     $mail = true;
     while (count($commandes) <= 5) {
         $commande = new Commande();
         $restaurant = Restaurant::getOneBy(array('name' => 'Ma Queue Mickey'));
         $item = ItemMenu::getOneBy(array('name' => 'Burger'));
         $address = Address::getOneBy(array('address' => '18 Rue des Roses'));
         $commande->setItem($item, 2);
         $commande->setStatus(Commande::COMMAND_STATUS_PAYED);
         $commande->setDatetime('12/12/12 12:12');
         $commande->createConfirmationCode();
         $commande->setAddress($address);
         $client = Client::getOneBy(array('_mail' => "*****@*****.**"));
         $commande->setClient($client);
         $commande->save();
         $restaurant->save();
         $commandes = Commande::getBy(array());
     }
 }
 public function doSupprimeRestaurant($id)
 {
     //If we are not connected as an entrepreneur, send to the login page
     if (!Session::isConnected() || Session::getUser()->getType() != USER_ENTREPRENEUR) {
         Redirect::to('/entrepreneur/login');
     }
     $restaurant = Restaurant::getOneBy(array('_id' => new \MongoId($id)));
     if (!$restaurant) {
         //If the restaurateur doesn't exist, we redirect to the list
         Session::addFlashMessage("Suppression impossible :", 'error', "Ce restaurant n'existe pas.");
         Redirect::to('/entrepreneur/supprimeRestaurant');
     }
     //Then we delete the restaurateur
     $restaurant->delete();
     Session::addFlashMessage("Restaurant supprimé", 'success', "Le restaurant a été supprimé avec succès.");
     Redirect::to('/entrepreneur/supprimeRestaurant');
 }
Beispiel #5
0
 /**
  * Return the restaurant associated
  * @return \App\Model\Restaurant
  */
 public function getRestaurant()
 {
     $restaurant = Restaurant::getOneBy(array('_id' => $this->restaurant));
     return $restaurant;
 }