private function associateRestaurants() { $user = Restaurateur::getOneBy(array('_mail' => "*****@*****.**")); $restaurant = Restaurant::getOneBy(array('name' => 'Ma Queue Mickey')); $user->addRestaurant($restaurant); $user->save(); }
/** * Return the associated Restaurateur * @return \App\Model\Restaurateur */ public function getRestaurateur() { $restaurateur = Restaurateur::getOneBy(array('_id' => $this->restaurateur)); return $restaurateur; }
public function gererCommande($id = 0) { $restaurateur = Restaurateur::getOneBy(array('_id' => new \MongoId(Session::getUser()->getId()))); //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) { $commandes = Commande::getByRestaurateur($restaurateur); return View::render("restaurateur/gestionCommande.php", array('commandes' => $commandes)); } $commande = Commande::getOneBy(array('_id' => new \MongoId($id))); if ($commande->getStatus() < Commande::COMMAND_STATUS_PREPARING) { $commande->setStatus(Commande::COMMAND_STATUS_PREPARING); $commande->save(); } if (Form::exists('finir_commande_form')) { $commande->setStatus(commande::COMMAND_STATUS_READY); $commande->save(); $commandes = Commande::getByRestaurateur($restaurateur); return View::render("restaurateur/gestionCommande.php", array('commandes' => $commandes)); } return View::render("restaurateur/prepareCommande.php", array('commande' => $commande)); }
public function editeRestaurant($id = 0) { //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'); } //If id is not set, we display the list of restaurants if ($id == 0) { $restaurants = Restaurant::getBy(array()); return View::render("entrepreneur/listeEditeRestaurant.php", array('restaurants' => $restaurants)); } $restaurant = Restaurant::getOneBy(array('_id' => new \MongoId($id))); if (!$restaurant) { return Redirect::to('/entrepreneur/editeRestaurant'); } //We select all the Restaurateurs $restaurateurs = Restaurateur::getBy(array()); if (Form::exists('restaurant_edit_form')) { //We check if all the input are filled if (Form::checkEmpty(array('name')) || Form::checkEmpty(array('description'))) { Session::addFlashMessage("Erreur :", 'error', "Tous les champs ne sont pas remplis."); $error = "Veuillez remplir tous les champs"; return View::render("entrepreneur/editeRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); } //We check if the name is not already taken $found = Restaurant::getOneBy(array('name' => Form::get('name'))); if ($found && $found->getId() != $restaurant->getId()) { Session::addFlashMessage("Erreur :", 'error', "Ce nom de restaurant est non disponible."); $error = "Ce nom de restaurant existe déjà. Veuillez en choisir une autre."; return View::render("entrepreneur/editeRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); } //We create a new Restaurant, and associate the values $restaurant->setName(Form::get('name')); $restaurant->setDescription(Form::get('description')); //TODO: Set the picture from the form //We save this Restaurant in the DB $restaurant->save(); //We remove the current Restaurateur $restaurateur = $restaurant->getRestaurateur(); if ($restaurateur) { $restaurateur->removeRestaurant($restaurant); $restaurateur->save(); $restaurant->removeRestaurateur(); $restaurant->save(); } //We add the Restaurateur to the Restaurant $restaurateurId = Form::get('restaurateur'); if ($restaurateurId != "") { $restaurateur = Restaurateur::getOneBy(array('_id' => new \MongoId($restaurateurId))); //If the Restaurateur exist, we add the Restaurant to it if ($restaurateur) { $restaurateur->addRestaurant($restaurant); $restaurateur->save(); $restaurateurAdded = true; } } Session::addFlashMessage("Restaurant édité avec succès", 'success', "Le restaurant " . $restaurant->getName() . " a été édité avec succès."); Redirect::to('/entrepreneur'); } return View::render("entrepreneur/editeRestaurant.php", array('restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); }