public function index() { //If the register form was sent if (Form::exists('register_form')) { //We check if all the input are filled if (Form::checkEmpty(array('mainAddress', 'firstName', 'mail', 'name', 'password', 'password_check', 'phoneNumber', 'birthday'))) { $error = "Veuillez remplir tous les champs"; return View::render("register/index.php", array('error' => $error)); } //We check if the mail address is not already taken if (Client::getOneBy(array('_mail' => Form::get('mail')))) { $error = "Cette adresse e-mail est déjà associée à un compte. Veuillez en choisir une autre."; return View::render("register/index.php", array('error' => $error)); } //We check if the password and the check are the same if (Form::get('password') != Form::get('password_check')) { $error = "Les mots de passe ne correspondent pas."; return View::render("register/index.php", array('error' => $error)); } //We create a new User, and associate the values $user = new Client(); $user->setFirstName(Form::get('firstName')); $user->setMail(Form::get('mail')); $user->setName(Form::get('name')); $user->setPassword(Form::get('password')); $user->setPhoneNumber(Form::get('phoneNumber')); $user->setBirthday(Form::get('birthday')); //We save this User in the DB $user->save(); $address = new \App\Model\Address(); $address->setAddress(Form::get('mainAddress')); $address->setUser($user); $address->save(); $user->setAddress($address); $user->save(); return View::render("register/complete.php", array('user' => $user)); } return View::render("register/index.php"); }
public function index() { //If the register form was sent if (Form::exists('profile_form')) { //We check if all the input are filled if (Form::checkEmpty(array('mainAddress', 'firstName', 'mail', 'name', 'password', 'password_check', 'phoneNumber', 'birthday'))) { $error = "Veuillez remplir tous les champs"; return View::render("register/index.php", array('error' => $error)); } $user = Session::getUser(); //We check if the password and the check are the same if (Form::exists('password') && Form::get('password') != "") { if (Form::get('password') != Form::get('password_check')) { $error = "Les mots de passe ne correspondent pas."; return View::render("register/index.php", array('error' => $error)); } else { $user->setPassword(Form::get('password')); } } //associate the values $user->setFirstName(Form::get('firstName')); $user->setName(Form::get('name')); $user->setPhoneNumber(Form::get('phoneNumber')); $user->setBirthday(Form::get('birthday')); //We save this User in the DB $user->save(); $adress = new \App\Model\Address(); $adress->setAddress(Form::get('mainAddress')); $adress->setUser($user); $adress->save(); $user->setAddress($adress); $user->save(); Session::connect($user); return View::render("profile/complete.php", array('user' => $user)); } $user = Session::getUser(); return View::render("profile/index.php", array('user' => $user)); }
public function editeMenu($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) { $restaurants = Restaurant::getBy(array()); return View::render("restaurateur/listeSelectRestaurant.php", array('restaurants' => $restaurants)); } $menu = Menu::getOneBy(array('_id' => new \MongoId($id))); if (Form::exists('menu_edit_form')) { $name = Form::get('name'); $price = Form::get('price'); if ($name == "" || is_null($name) || $price == "" || is_null($price)) { Session::addFlashMessage("Erreur :", 'error', "Tous les champs ne sont pas remplis."); $error = "Veuillez remplir tous les champs"; return View::render("restaurateur/editeMenu.php", array('error' => $error, 'menu' => $menu)); } $description = Form::get('description'); if ($description == "" || is_null($description)) { Session::addFlashMessage("Attention :", 'warning', "Vous n'avez pas rempli de description pour cet item."); } //We check if the name is not already taken $found = ItemMenu::getBy(array('name' => Form::get('name'), 'menu' => $menu->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/editeMenu.php", array('error' => $error, 'menu' => $menu)); } //We associate the values $itemMenu = new ItemMenu(); $itemMenu->setName(Form::get('name')); $itemMenu->setDescription(Form::get('description')); $itemMenu->setPrice(Form::get('price')); $itemMenu->setMenu($menu); $itemMenu->save(); $menu->addItem($itemMenu); $menu->save(); } if (Form::exists('menu_name_edit_form')) { if (Form::checkEmpty(array('menuName'))) { Session::addFlashMessage("Erreur :", 'error', "Tous les champs ne sont pas remplis."); $error = "Veuillez indiquer un nom de menu"; return View::render("restaurateur/editeMenu.php", array('error' => $error, 'menu' => $menu)); } if ($menu->getName() == Form::get('menuName')) { Session::addFlashMessage("Erreur :", 'error', "Le nom n'a pas été modifié."); $error = "Le nom n'a pas changé."; return View::render("restaurateur/editeMenu.php", array('error' => $error, 'menu' => $menu)); } $menu->setName(Form::get('menuName')); $menu->save(); } return View::render("restaurateur/editeMenu.php", array('menu' => $menu)); }
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)); }