Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 /**
  * Seed the Database with Users
  */
 private function addUsers()
 {
     //Add the Entrepreneur if he doesn't exist
     if (!Entrepreneur::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Entrepreneur();
         $user->setFirstName("Bill");
         $user->setName("Gates");
         $user->setMail("*****@*****.**");
         $user->setPassword("123123");
         $user->save();
     }
     //Add a Restaurateur if he doesn't exist
     if (!Restaurateur::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Restaurateur();
         $user->setFirstName("MacDonald");
         $user->setName("Ronald");
         $user->setMail("*****@*****.**");
         $user->setPassword("123123");
         $user->save();
     }
     //Add a Restaurateur if he doesn't exist
     if (!Restaurateur::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Restaurateur();
         $user->setFirstName("Tiki");
         $user->setName("Ming");
         $user->setMail("*****@*****.**");
         $user->setPassword("123123");
         $user->save();
     }
     //Add a Restaurateur if he doesn't exist
     if (!Restaurateur::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Restaurateur();
         $user->setFirstName("Jean");
         $user->setName("Bono");
         $user->setMail("*****@*****.**");
         $user->setPassword("123123");
         $user->save();
     }
     //Add a Client if he doesn't exist
     $address = Address::getOneBy(array('address' => '18 Rue des Roses'));
     if (!$address) {
         $address = new Address();
         $address->setAddress('18 Rue des Roses');
         $address->save();
     }
     if (!Client::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Client();
         $user->setFirstName("Jean");
         $user->setName("Bon");
         $user->setMail("*****@*****.**");
         $user->setAddress($address);
         $user->setBirthday("10 Janvier 1973");
         $user->setPhoneNumber("593 489 2354");
         $user->setPassword("123123");
         $user->save();
         $address->setUser($user);
         $address->save();
     }
     //Add a Livreur if he doesn't exist
     if (!Livreur::getOneBy(array('_mail' => "*****@*****.**"))) {
         $user = new Livreur();
         $user->setFirstName("Jiang");
         $user->setName("Li");
         $user->setMail("*****@*****.**");
         $user->setPassword("123123");
         $user->save();
     }
 }