Example #1
0
 private function associateRestaurants()
 {
     $user = Restaurateur::getOneBy(array('_mail' => "*****@*****.**"));
     $restaurant = Restaurant::getOneBy(array('name' => 'Ma Queue Mickey'));
     $user->addRestaurant($restaurant);
     $user->save();
 }
 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));
 }
Example #4
0
 /**
  * Set the associated Restaurateur
  * Be Careful ! To register a link between a Restaurateur and a Restaurant,
  * you should use Restaurateur->addRestaurant instead ! Otherwise the
  * Restaurant will not be added to the Restaurateur.
  * @param \App\Model\Restaurateur $restaurateur
  */
 public function setRestaurateur(Restaurateur $restaurateur)
 {
     $this->restaurateur = $restaurateur->getId();
 }
Example #5
0
 /**
  * Get all the Commande from the corresponding Restaurateur
  * @param \App\Model\Restaurateur $restaurateur
  * @return \App\Model\Commande[]
  */
 public static function getByRestaurateur(Restaurateur $restaurateur)
 {
     $commandes = self::getBy(array());
     $foundCommandes = array();
     foreach ($commandes as $commande) {
         $items = $commande->getItems();
         $item = ItemMenu::getOneBy(array('_id' => $items[0]->getId()));
         if ($item->getMenu()->getRestaurant()->getRestaurateur() && $item->getMenu()->getRestaurant()->getRestaurateur()->getId() == $restaurateur->getId()) {
             $foundCommandes[] = $commande;
         }
     }
     return $foundCommandes;
 }