Beispiel #1
0
 private function addRestaurants()
 {
     if (!Restaurant::getOneBy(array('name' => 'Ma Queue Mickey'))) {
         $restaurant = new Restaurant();
         $restaurant->setName('Ma Queue Mickey');
         $restaurant->setDescription('Un sympathique petit restaurant aux allures pitoresques, et qui ne manque pas de joyeux serveurs prêts à répondre à vos exigences !');
         $restaurant->setPicture("img/generic.jpg");
         $restaurant->save();
     }
     if (!Restaurant::getOneBy(array('name' => 'Kitchen For Chinese'))) {
         $restaurant = new Restaurant();
         $restaurant->setName('Kitchen For Chinese');
         $restaurant->setDescription('Venez manger chinois dans ce joli restaurant. KFC et toute son équipe vous accueillent 24h/24, et travaillerons durs, comme des vrais petits chinois pour que vous puissiez profiter du buffet à volonté.');
         $restaurant->setPicture("img/chinois.jpg");
         $restaurant->save();
     }
     if (!Restaurant::getOneBy(array('name' => 'Sous-marins express'))) {
         $restaurant = new Restaurant();
         $restaurant->setName('Sous-marins express');
         $restaurant->setDescription('Si tu veux des sous-marins, et vite, tu es au bon endroit. Notre chef, Pablo, est recordman du nombre de sou-marins préparés en 10 minutes. Goûte à notre spécial "moutarde/sirop d\'érable" !');
         $restaurant->setPicture("img/generic.jpg");
         $restaurant->save();
     }
 }
 public function ajoutRestaurant()
 {
     //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');
     }
     //We select all the Restaurateur
     $restaurateurs = Restaurateur::getBy(array());
     if (Form::exists('restaurant_add_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/ajoutRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs));
         }
         //We check if the name is not already taken
         if (Restaurant::getOneBy(array('name' => Form::get('name')))) {
             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/ajoutRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs));
         }
         //We create a new Restaurant, and associate the values
         $restaurant = new Restaurant();
         $restaurant->setName(Form::get('name'));
         $restaurant->setDescription(Form::get('description'));
         $restaurant->setPicture('img/generic.jpg');
         //We save this Restaurant in the DB
         $restaurant->save();
         //We add the Restaurateur to the Restaurant
         $restaurateurAdded = false;
         $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;
             }
         }
         if ($restaurateurAdded) {
             Session::addFlashMessage("Restaurant ajouté avec succès", 'success', "Le restaurant " . $restaurant->getName() . " a été ajouté avec succès.");
         } else {
             Session::addFlashMessage("Restaurant ajouté sans restaurateur", 'warning', "Le restaurant " . $restaurant->getName() . " a été ajouté sans restaurateur associé.");
         }
         Redirect::to('/entrepreneur');
     }
     return View::render("entrepreneur/ajoutRestaurant.php", array('restaurateurs' => $restaurateurs));
 }