$new_brand = new Brand($escaped_post['name'], $escaped_post['website']); $new_brand->save(); $store->addBrand($new_brand); } return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); // [U] Update a Store, then display that store and its brands. $app->patch("/store/{id}", function ($id) use($app) { $store = Store::find($id); //For some reason my escaped chars function behaves //strangely when updating DB rows. Omit it for now. // Check for which post variables we have and update those // Could be just one or all three if (!empty($_POST['new_name'])) { $store->updateName($_POST['new_name']); } if (!empty($_POST['new_location'])) { $store->updateLocation($_POST['new_location']); } if (!empty($_POST['new_phone'])) { $store->updatePhone($_POST['new_phone']); } return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); /* [D] Remove all connections between brands and this store. ** Don't actually delete any brands or this store. ** Then display the normal store page. */ $app->delete("/store/{id}/removeBrands", function ($id) use($app) { $store = Store::find($id); $store->removeBrands(); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll()));
$app->post('/add_brands', function () use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $store->addBrand($brand); $brands = $store->getBrands(); $all_brands = Brand::getAll(); return $app['twig']->render('stores.html.twig', array('store' => $store, 'brands' => $brands, 'all_brands' => $all_brands)); }); $app->get('/store/{id}', function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store_edit.html.twig', array('store' => $store)); }); $app->patch('/stores/{id}', function ($id) use($app) { $store = Store::find($id); $store->update($_POST['name']); $brands = $store->getBrands(); $all_brands = Brand::getAll(); return $app['twig']->render('stores.html.twig', array('store' => $store, 'brands' => $brands, 'all_brands' => $all_brands)); }); $app->delete('/stores/{id}', function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->get('/brands/{id}', function ($id) use($app) { $brand = Brand::find($id); $stores = $brand->getStores(); $all_stores = Store::getAll(); return $app['twig']->render('brands.html.twig', array('brand' => $brand, 'stores' => $stores, 'all_stores' => $all_stores)); }); $app->post('/add_stores', function () use($app) {
}); //POSTS (ADDS) $app->post("/add_stores", function () use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $brand->addStore($store); return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'brands' => Brand::getAll(), 'stores' => $brand->getStores(), 'all_stores' => Store::getAll())); }); $app->post("/add_brands", function () use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $store->addBrand($brand); return $app['twig']->render('store.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); //GET AND EDIT AND DELETE STORE ROUTE $app->get("/stores/{id}/edit", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store-edit.html.twig', array('store' => $store, 'brands' => $store->getBrands())); }); $app->patch("/stores/{id}", function ($id) use($app) { $store = Store::find($id); $new_name = $_POST['new_name']; $store->update($new_name); return $app['twig']->render('stores.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands())); }); $app->delete("/stores/{id}", function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); return $app;
$app->post("/delete_all_stores", function () use($app) { Store::deleteAll(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); //goes to an update page for a store $app->get("/stores/{id}/edit", function ($id) use($app) { $store = Store::find($id); $brands = $store->getBrands(); return $app['twig']->render('store_edit.html.twig', array('store' => $store, 'brands' => $brands, 'all_brands' => Brand::getAll())); }); //update a store name and return to the store page $app->patch("/stores/{id}/edit", function ($id) use($app) { $store = Store::find($id); foreach ($_POST as $key => $value) { if (!empty($value)) { $store->update($key, $value); } } $brand = $store->getBrands(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); //adds a brand to a store $app->post("/stores/{id}/add_brand", function ($id) use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $store->addBrand($brand); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); //deletes an individual store $app->delete("/stores/{id}/delete", function ($id) use($app) { $store = Store::find($id); $store->delete();
$brand = Brand::find($_POST['brand_id']); $store = Store::find($_POST['store_id']); $brand->addStore($store); return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll())); }); $app->get("/stores/{id}/edit", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store_edit.html.twig', array('store' => $store)); }); $app->get("/brands/{id}/edit", function ($id) use($app) { $brand = Brand::find($id); return $app['twig']->render('brand_edit.html.twig', array('brand' => $brand)); }); $app->patch("/store/{id}", function ($id) use($app) { $store = Store::find($id); $store->update($_POST['name']); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); $app->patch("/brand/{id}", function ($id) use($app) { $brand = Brand::find($id); $brand->update($_POST['name']); return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll())); }); $app->delete("/store/{id}", function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); $app->delete("/brand/{id}", function ($id) use($app) { $brand = Brand::find($id); $brand->delete();
return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); $app->get("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); $app->post("/cuisines", function () use($app) { $cuisine = new Cuisine($_POST['name']); $cuisine->save(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); $app->post("/delete_cuisines", function () use($app) { Cuisine::deleteAll(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); $app->get("/cuisines/{id}/edit", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisine' => $cuisine)); }); $app->patch("/cuisines/{id}", function ($id) use($app) { $name = $_POST['name']; $cuisine = Cuisine::find($id); $cuisine->update($name); return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); $app->delete("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); $cuisine->delete(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); return $app;
$brand->save(); return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); $app->post("/add_brand", function () use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $store->addBrand($brand); return $app['twig']->render('store.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); $app->get("/store/{id}/edit", function ($id) use($app) { $store = store::find($id); return $app['twig']->render('store_edit.html.twig', array('store' => $store)); }); $app->patch("/store/{id}", function ($id) use($app) { $store = Store::find($id); $brands = $store->getBrands(); $store->update($_POST['name']); return $app['twig']->render('store_edit.html.twig', array('store' => $store, 'brands' => $store->getBrands())); }); $app->delete("/store/{id}", function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render("stores.html.twig", array('stores' => Store::getAll())); }); $app->post("/delete_stores", function () use($app) { $GLOBALS['DB']->exec("DELETE FROM stores_brands;"); Store::deleteAll(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); $app->get("/brand/{id}", function ($id) use($app) { $brand = Brand::find($id); $stores = $brand->getStores();
//Showing a book's schedule of authors. Renders to particular book's page with crud function $app->get("/books/{id}", function ($id) use($app) { $book = Book::find($id); return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll())); }); //Adds authors to books in the book.html file. $app->post("/add_author", function () use($app) { $author = Author::find($_POST['author_id']); $book = Book::find($_POST['book_id']); $book->addAuthor($author); return $app['twig']->render('book.html.twig', array('book' => $book, 'books' => Book::getAll(), 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll())); }); //Updates book, comes from book.html, posts back to books.html with updated book info $app->patch("/book/{id}/edit", function ($id) use($app) { $new_book_name = $_POST['new_book_name']; $book = Book::find($id); $book->update($new_book_name); return $app['twig']->render('books.html.twig', array('books' => Book::getAll())); }); //Deletes book, comes from book.html, posts back to books.html minus deleted book $app->get("/book/{id}/delete", function ($id) use($app) { $book = Book::find($id); $book->deleteOne(); return $app['twig']->render('books.html.twig', array('books' => Book::getAll())); }); //Delete All Books from DB $app->post("/delete_books", function () use($app) { Book::deleteAll(); return $app['twig']->render('index.html.twig'); }); // -------------------------End Book Routes ------------------------- // -------------------------Begin Author Routes -------------------------
return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll())); }); $app->get("/book/{id}/edit", function ($id) use($app) { $book = Book::find($id); return $app['twig']->render("edit_book.html.twig", array("book" => $book)); }); $app->patch("/book/{id}", function ($id) use($app) { $book = Book::find($id); if (!empty($_POST['title'])) { $new_title = $_POST['title']; $book->updateTitle($new_title); } if (!empty($_POST['author'])) { $author_name = $_POST['author']; $book->updateAuthor($book->checkAuthor($author_name)); } if (!empty($_POST['add_author'])) { $author_name = $_POST['add_author']; $book->addAuthor($book->checkAuthor($author_name)); } if (!empty($_POST['add_copies'])) { $add_copies = $_POST['add_copies']; $book->updateCopies($add_copies); } return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll())); }); $app->post("/delete_all_books", function () use($app) { Book::deleteAll(); return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll())); }); $app->delete("/book/{id}/delete_author", function ($id) use($app) { $book = Book::find($id);
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/myClass.php"; $server = 'mysql:host=localhost;dbname=BRiT'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app = new Silex\Application(); $app['debug'] = true; $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('cuisine' => Cuisine::getAll())); }); $app->get("/restaurants/{id}", function ($id) use($app) { //shows a certain restaurant based on id return $app['twig']->render('index.html.twig', array('cuisine' => Cuisine::getAll())); }); $app->patch("/update_restaurant", function ($id) use($app) { //shows a certain restaurant based on id return $app['twig']->render('index.html.twig', array('cuisine' => Cuisine::getAll())); }); return $app;
}); //this can be used to show all restaurants, regardless of cuisine id $app->get("/restaurants", function () use($app) { return $app['twig']->render('restaurants.html.twig', array('restaurants' => Restaurant::getAll())); }); $app->get("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('restaurants.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); $app->get("/cuisines/{id}/edit", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisine' => $cuisine)); }); $app->patch("/cuisines/{id}", function ($id) use($app) { $name = $_POST['name']; $cuisine = Cuisine::find($id); $cuisine->update($name); return $app['twig']->render('restaurants.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); $app->delete("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); $cuisine->delete(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); $app->post("/cuisines", function () use($app) { $cuisine = new Cuisine($_POST['name']); $cuisine->save(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); $app->post("/deleteAll", function () use($app) { Cuisine::deleteAll(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll()));
}); //from profile //find user //show profile_edit $app->get("/{user_id}/edit_profile", function ($user_id) use($app) { $user = User::find("id", $user_id); return $app['twig']->render('profile_edit.html.twig', array('user' => $user[0])); }); //from profile_edit //update profile fields //show profile $app->patch("/{user_id}/user", function ($user_id) use($app) { $user = User::find("id", $user_id); $user[0]->updateUserName($_POST['user_name']); $user[0]->updatePreferredStyle($_POST['preferred_style']); $user[0]->updateRegion($_POST['region']); $reviews = Review::find("user_id", $user[0]->getId()); $new_beers = User::findBeerStyle($user[0]->getId(), $user[0]->getPreferredStyle()); $local_stores = Store::find("region", $user[0]->getRegion()); return $app['twig']->render('profile.html.twig', array('user' => $user[0], 'reviews' => $reviews, 'new_beers' => $new_beers, 'local_stores' => $local_stores)); }); //------------------------------- Begin Beer Functionality ----------------------------------- //from beers //add and save new beer //show all beers $app->post("/{user_id}/beers", function ($user_id) use($app) { $beer = new Beer($_POST['beer_name'], $_POST['style'], $_POST['abv'], $_POST['ibu'], $_POST['container'], $_POST['brewery'], $_POST['image']); $beer->save(); $user = User::find("id", $user_id); return $app['twig']->render('beers.html.twig', array('all_beers' => Beer::getAll(), 'user' => $user[0])); }); //from profile
}); //Renders an individual stylists page with all their clients listed $app->get("/stylists/{id}", function ($id) use($app) { $stylist = Stylist::find($id); return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients(), 'form_check' => false)); }); //Renders a page to enter new information about the stylist $app->get("/stylist_update_form", function () use($app) { $stylist = Stylist::find($_GET['stylist_id']); return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients(), 'form_check' => false)); }); //Updates stylist information and renders the stylists' page $app->patch("/update_stylist", function () use($app) { $name = $_POST['name']; $stylist_id = $_POST['stylist_id']; $stylist = Stylist::find($stylist_id); $stylist->update($name, $stylist_id); return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients(), 'form_check' => false)); }); //Deletes a single stylist and renders the main page $app->delete("/stylists/{id}", function ($id) use($app) { $stylist = Stylist::find($id); $stylist->delete(); return $app['twig']->render('index.html.twig', array('stylists' => Stylist::getAll(), 'form_check' => false)); }); //Shows form on stylists page to add a new client $app->get("/show_client_form", function () use($app) { $stylist = Stylist::find($_GET['stylist_id']); return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients(), 'form_check' => true)); }); //Posts a new client and renders the stylists page
return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'form_check' => true)); }); $app->post("/add_store", function () use($app) { $store = new Store($_POST['type']); $store->save(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'form_check' => false)); }); $app->get("/form_store_update", function () use($app) { $store = Store::find($_GET['store_id']); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'store_update' => true, 'form_check' => false)); }); // This route updates a specific store $app->patch("/update_store", function () use($app) { $name = $_POST['name']; $store_id = $_POST['store_id']; $store = Store::find($store_id); $store->updateName($name); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'store_update' => false, 'form_check' => false)); }); $app->post("/delete_stores", function () use($app) { Store::deleteAll(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'form_check' => false)); }); $app->get("/stores/{id}", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => false, 'store_update' => false)); }); // This route deletes specific store $app->delete("/delete_store/{id}", function ($id) use($app) { $id = $_POST['store_id']; $store = Store::find($id);
//Showing a student's schedule of courses. Renders to particular student's page with crud function $app->get("/students/{id}", function ($id) use($app) { $student = Student::find($id); return $app['twig']->render('student.html.twig', array('student' => $student, 'courses' => $student->getCourses(), 'all_courses' => Course::getAll())); }); //Linking student to a course $app->post("/add_students", function () use($app) { $course = Course::find($_POST['course_id']); $student = Student::find($_POST['student_id']); $course->addStudent($student); return $app['twig']->render('course.html.twig', array('course' => $course, 'courses' => Course::getAll(), 'students' => $course->getStudents(), 'all_students' => Student::getAll())); }); //Updates student, comes from student.html, posts back to students.html with updated student info $app->patch("/student/{id}/edit", function ($id) use($app) { $new_student_name = $_POST['new_student_name']; $student = Student::find($id); $student->update($new_student_name); return $app['twig']->render('students.html.twig', array('students' => Student::getAll())); }); //Deletes student, comes from student.html, posts back to students.html minus deleted student $app->delete("/student/{id}/edit", function ($id) use($app) { $student = Student::find($id); $student->deleteOne(); return $app['twig']->render('students.html.twig', array('students' => Student::getAll())); }); //Delete All Students from DB $app->post("/delete_students", function () use($app) { Student::deleteAll(); return $app['twig']->render('index.html.twig'); }); // -------------------------End Student Routes ------------------------- // -------------------------Begin Course Routes -------------------------
return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //View list of restaurants after save: $app->get("/restaurants", function () use($app) { $cuisine = Cuisine::find($cuisine_id); return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => Restaurant::getAll())); }); //Page for editing a cuisine: $app->get("/cuisines/{id}/edit", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisine' => $cuisine)); }); //Update a cuisine form: $app->patch("/cuisines/{id}", function ($id) use($app) { $type = $_POST['type']; $cuisine = Cuisine::find($id); $cuisine->update($type); return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //Edit a restaurant page: $app->get("/restaurants/{id}/edit", function ($id) use($app) { $restaurant = Restaurant::find($id); $cuisine = Cuisine::find($restaurant->getCuisineId()); return $app['twig']->render('restaurant_edit.html.twig', array('restaurant' => $restaurant, 'cuisine' => $cuisine)); }); //Show cuisine page with update restaurant: $app->patch("/restaurants/{id}", function ($id) use($app) { $name = $_POST['name']; $phone = $_POST['phone']; $price = $_POST['price']; $restaurant = Restaurant::find($id); $restaurant->update($name, $phone, $price);
//EDIT A BRAND link $app->get("/brand/{id}/edit", function ($id) use($app) { $brand = Brand::find($id); return $app['twig']->render("edit_brand.html.twig", array("brand" => $brand, "brands" => Brand::getAll(), "stores" => $brand->getStores(), 'stores' => Store::getAll())); }); //DELETE ALL STORES/BRANDS $app->post("/delete_all", function () use($app) { Store::deleteAll(); Brand::deleteAll(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); //DELETE INDIVIDUAL STORE $app->delete("/store/{id}/delete", function ($id) use($app) { $store = Store::find($id); $store->deleteStore(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); //UPDATE $app->patch("/store/{id}", function ($id) use($app) { $store = Store::find($id); if (!empty($_POST['name'])) { $new_name = $_POST['name']; $store->updateName($new_name); } if (!empty($_POST['add_brand'])) { $brand_name = $_POST['add_brand']; $store->addBrand($store->checkBrand($brand_name)); } return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); return $app;
$menu_item = $token->getMenuItem(); $bar_id = $menu_item[0]; $bar = Bar::find($bar_id); $item_id = $menu_item[1]; $item = Item::find($item_id); return $app['twig']->render("view_token.html.twig", array('bar' => $bar, 'item' => $item, 'token' => $token)); }); //Get Show Menu Items $app->get("/show_menu_items/{id}", function ($id) use($app) { $bar = Bar::find($id); $items = $bar->getAllItems(); return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => true, 'edit_bar' => false)); }); $app->patch("/edit_item/{bar_id}/{item_id}", function ($bar_id, $item_id) use($app) { $item = Item::find($item_id); $item->update($_POST['description'], $_POST['cost']); $bar = Bar::find($bar_id); return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => true, 'edit_bar' => false)); }); $app->post("/add_item/{bar_id}", function ($bar_id) use($app) { $bar = Bar::find($bar_id); $item = new Item($_POST['description'], $_POST['cost']); $item->save(); $bar->addItem($item); return $app['twig']->render("bar.html.twig", array('item' => $item, 'bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => true, 'edit_bar' => false)); }); $app->delete('/delete_item/{bar_id}/{item_id}', function ($bar_id, $item_id) use($app) { $bar = Bar::find($bar_id); $item = Item::find($item_id); $item->delete(); return $app['twig']->render("bar.html.twig", array('item' => $item, 'bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => true, 'edit_bar' => false)); });
return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => true, 'token_form' => false, 'edit_user' => false)); }); $app->get("/show_user_tokens/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => false, 'token_form' => true, 'edit_user' => false)); }); $app->get("/show_user_edit/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => false, 'token_form' => false, 'edit_user' => true)); }); $app->patch("/edit_user/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); $new_name = $_POST['name']; $new_email = $_POST['email']; $user->updatePatron($new_name, $new_email); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => false, 'token_form' => false, 'edit_user' => false)); }); $app->get("/show_preferred_bars/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => true, 'send_token' => false, 'token_form' => false, 'edit_user' => false)); }); $app->get("/about", function () use($app) { return $app['twig']->render("about.html.twig"); }); $app->post("/email_send", function () use($app) { $mail = new PHPMailer(); // $mail->SMTPDebug = 3; $mail->isSMTP();
return $app['twig']->render('category.html.twig', array('category' => $category, 'categories' => Category::getAll(), 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->post("/add_categories", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $task->addCategory($category); return $app['twig']->render('task.html.twig', array('task' => $task, 'tasks' => Task::getAll(), 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->get("/categories/{id}/edit", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category_edit.html.twig', array('category' => $category, 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->patch("/edit_confirm/{id}", function ($id) use($app) { $name = $_POST['name']; $id = $_POST['category_id']; $category = Category::find($id); $category->update($name, $id); return $app['twig']->render('category.html.twig', array('category' => $category, 'categories' => Category::getAll(), 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->get("/task/{id}/edit", function ($id) use($app) { $task = Task::find($id); return $app['twig']->render('task_edit.html.twig', array('task' => $task, 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->patch("/editTask_confirm/{id}", function ($id) use($app) { $description = $_POST['description']; $id = $_POST['task_id']; $due_date = $_POST['due_date']; $task = Task::find($id); $task->update($description, $id, $due_date); return $app['twig']->render('task.html.twig', array('task' => $task, 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); });
}); //Allows the user to delete the list of stylists on the front page //Error: Variable 'stylists' does not exist in 'stylists.html.twig' at line 11 $app->post("/delete_stylists", function () use($app) { Stylist::deleteAll(); return $app['twig']->render('stylists.html.twig'); }); //route which allows the user to edit one stylist $app->get("/stylists/{id}/edit", function ($id) use($app) { $stylist = Stylist::find($id); return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist)); }); //allows the user to use the update method $app->patch("/stylists/{id}", function ($id) use($app) { $stylist_name = $_POST['stylist_name']; $stylist = Stylist::find($id); $stylist->update($stylist_name); return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients())); }); //allows the user to delete a stylist $app->delete("/stylists/{id}", function ($id) use($app) { $stylist = Stylist::find($id); $stylist->delete(); return $app['twig']->render('index.html.twig', array('stylists' => Stylist::getAll())); }); //allows the user to find a client's id $app->get("/clients/{id}", function ($id) use($app) { $client = Client::find($id); return $app['twig']->render('client.html.twig', array('client' => $client)); }); $app->get("/clients/{id}/edit", function ($id) use($app) { $client = Client::find($id);
$app->get("/categories/{id}", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); $app->get("/categories/{id}/edit", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category_edit.html.twig', array('category' => $category)); }); $app->delete("/categories/{id}", function ($id) use($app) { $category = Category::find($id); $category->delete(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->patch("/categories/{id}", function ($id) use($app) { $name = $_POST['name']; $category = Category::find($id); $category->update($name); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Category::deleteAll(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_tasks", function () use($app) { Task::deleteAll(); return $app['twig']->render('index.html.twig', array('categories' => Category::getAll())); });
$app->post("/courses", function () use($app) { $course = new Course($_POST['name'], $_POST['number']); $course->save(); return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->get("/courses/{id}", function ($id) use($app) { $course = Course::find($id); return $app['twig']->render('course.html.twig', array('course' => $course, 'students' => $course->getStudents(), 'all_students' => Student::getAll())); }); $app->get("/courses/{id}/edit", function ($id) use($app) { $course = Course::find($id); return $app['twig']->render('course_edit.html.twig', array('course' => $course)); }); $app->patch("/courses/{id}", function ($id) use($app) { $name = $_POST['name']; $course = Course::find($id); $course->update($name); return $app['twig']->render('course.html.twig', array('course' => $course, 'all_students' => Student::getAll(), 'students' => $course->getStudents())); }); $app->delete("/courses/{id}", function ($id) use($app) { $course = Course::find($id); $course->delete(); return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->post("/add_courses", function () use($app) { $course = Course::find($_POST['course_id']); $student = Student::find($_POST['student_id']); $student->addCourse($course); return $app['twig']->render('student.html.twig', array('student' => $student, 'students' => Student::getAll(), 'courses' => $student->getCourses(), 'all_courses' => Course::getAll())); }); //Students $app->get("/students", function () use($app) {
$course->addStudent($student); return $app["twig"]->render("course.html.twig", array("course" => $course, "courses" => Course::getAll(), "students" => $course->getStudents(), "all_students" => Student::getAll())); }); $app->post("/add_courses", function () use($app) { $course = Course::find($_POST['course_id']); $student = Student::find($POST['student_id']); $student->addCourse($course); return $app["twig"]->render("student.html.twig", array("student" => $student, "students" => Student::getAll(), "course" => $student->getCourses(), "all_courses" => Course::getAll())); }); $app->get("/courses/{id}/edit", function ($id) use($app) { $course = Course::find($id); return $app["twig"]->render("course_edit.html.twig", array("course" => $course)); }); $app->patch("/courses/{id}", function ($id) use($app) { $name = $_POST["name"]; $course = Course::find($id); $course->update($name); return $app["twig"]->render("course_edit.html.twig", array("course" => $course)); }); $app->delete("/courses/{id}", function ($id) use($app) { $course = Course::find($id); $course->delete(); return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->get("/students/{id}/edit", function ($id) use($app) { $student = Student::find($id); return $app['twig']->render('student_edit.html.twig', array('student' => $student)); }); $app->patch("/students/{id}", function ($id) use($app) { $description = $_POST['description']; $student = Student::find($id); $student->update($description);
return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //brings user to specific cuisine page $app->get("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //brings user to a page that allows a specific cuisine to be edited $app->get('/cuisines/{id}/edit', function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisines' => $cuisine)); }); //posts edited data to the database to update a property in the existing cuisine $app->patch("/cuisines/{id}", function ($id) use($app) { $name = $_POST['name']; $cuisine = Cuisine::find($id); $cuisine->update($name); return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //deletes one specific cuisine $app->delete("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); $cuisine->delete(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //clear database of all cuisines $app->post('/delete_cuisines', function () use($app) { Cuisine::deleteAll(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //creates new restaurants and displays them on the same page $app->post('/restaurants', function () use($app) {
return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->get("/categories/{id}", function ($id) use($app) { $category = Category::find($id); $tasks = $category->getTasks(); var_dump($tasks[0]); var_dump($tasks[1]); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->post("/add_tasks", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $category->addTask($task); return $app['twig']->render('category.html.twig', array('category' => $category, 'categories' => Category::getAll(), 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->post("/add_categories", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $task->addCategory($category); return $app['twig']->render('task.html.twig', array('task' => $task, 'tasks' => Task::getAll(), 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->patch("/task_update", function () use($app) { $mark = $_POST['mark']; $task_id = $_POST['task_id']; var_dump($mark); $task = Task::find($task_id); $task->updateMark($mark); $category = Category::find($_POST['category_id']); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks())); }); return $app;
$task = Task::find($id); return $app['twig']->render('task.html.twig', array('task' => $task, 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->post("/add_tasks", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $category->addTask($task); return $app['twig']->render('category.html.twig', array('category' => $category, 'categories' => Category::getAll(), 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->get("/tasks/{id}/edit", function ($id) use($app) { $task = Task::find($id); return $app['twig']->render('task_edit.html.twig', array('task' => $task)); }); $app->patch("/tasks/{id}", function ($id) use($app) { $task = Task::find($id); $task->update($_POST['description'], $_POST['due_date']); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->delete("/tasks/{id}", function ($id) use($app) { $task = Task::find($id); $task->delete(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->post("/add_categories", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $task->addCategory($category); return $app['twig']->render('task.html.twig', array('task' => $task, 'tasks' => Task::getAll(), 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->get("/categories/{id}/edit", function ($id) use($app) { $category = Category::find($id);
// return $app['twig']->render('category.html.twig', // array('category' => $category, 'tasks' => $category->getTasks())); }); $app->post("/clients/{id}", function ($id) use($app) { $stylist_id = $_POST['stylist_id']; $client_name = preg_quote($_POST['client_name'], "'"); $client = new Client($client_name, $stylist_id, $id = null); $client->save(); $stylist = Stylist::find($stylist_id); return $app['twig']->render('clients_edit.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients())); // return $app['twig']->render('category.html.twig', // array('category' => $category, 'tasks' => $category->getTasks())); }); $app->patch("/stylists/{id}/edit", function ($id) use($app) { $name = preg_quote($_POST['name'], "'"); $stylist = Stylist::find($id); $stylist->update($name); return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients())); }); $app->patch("/clients/{id}/edit", function ($id) use($app) { $name = preg_quote($_POST['client_name'], "'"); $client = Client::find($id); // echo "Name: " . $name . " Id: " . $id . " "; // var_dump($client); $client->update($name); return $app['twig']->render('client_edit.html.twig', array('client' => Client::find($id))); }); $app->delete("/stylists/{id}", function ($id) use($app) { $stylist = Stylist::find($id); $stylist->delete(); return $app['twig']->render('index.html.twig', array('stylists' => Stylist::getAll())); });
$find_book = Book::find($id); $name = $_POST['name']; $new_author = new Author($name); $new_author->save(); $find_book->addAuthor($new_author); $authors = $find_book->getAuthors(); return $app['twig']->render("book.html.twig", array('book' => $find_book, 'authors' => $authors, 'copies' => count($book->getCopies()))); }); //update book info $app->patch("/book/{id}", function ($id) use($app) { $book = Book::find($id); $book_copies = $book->getCopies(); $new_copies = $_POST['new_copies']; if ($new_copies < 1000) { foreach ($book_copies as $copy) { $copy->delete(); } $book->addCopies($new_copies); } $book->update($_POST['title']); $authors = $book->getAuthors(); return $app['twig']->render("book.html.twig", array('book' => $book, 'authors' => $authors, 'copies' => count($book->getCopies()))); }); //delete book info $app->delete("/book/{id}", function ($id) use($app) { $book = Book::find($id); $book->delete(); return $app['twig']->render("main_admin.html.twig", array('books' => Book::getAll())); }); //INDIVIDUAL AUTHOR PAGE $app->get("/author/{id}", function ($id) use($app) { $author = Author::find($id);
return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist)); }); //EDIT CLIENT PAGE $app->get("/client/{id}/edit", function ($id) use($app) { $client = Client::find($id); return $app['twig']->render('client_edit.html.twig', array('client' => $client)); }); //DELETE CLIENT $app->delete("/client/{id}/delete", function ($id) use($app) { $client = Client::find($id); $client->delete(); $stylist_id = $client->getStylistId(); $stylist = Stylist::find($stylist_id); return $app['twig']->render('stylist.html.twig', array('clients' => $stylist->getAllClients(), 'stylist' => $stylist)); }); //UPDATE CLIENT $app->patch("/client/{id}", function ($id) use($app) { $new_client_name = $_POST['name']; $client = Client::find($id); $client->updateName($new_client_name); $stylist = Stylist::find($client->getStylistId()); return $app['twig']->render('stylist.html.twig', array('stylists' => Stylist::getAll(), 'stylist' => $stylist, 'clients' => $stylist->getAllClients())); }); //UPDATE Stylist $app->patch("/stylist/{id}", function ($id) use($app) { $new_stylist_name = $_POST['name']; $stylist = Stylist::find($id); $stylist->updateName($new_stylist_name); return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getAllClients())); }); return $app;