return $app->json(array('success' => true)); }); $app->get('/pessoas', function () use($app) { $stmt = $app['db']->query("Select * from pessoas"); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); return $app->json($result); }); $app->get('/pessoas/{id}', function ($id) use($app) { $stmt = $app['db']->prepare("Select * from pessoas where id=:id"); $stmt->bindParam('id', $id); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $app->json($result); }); $app->put('/pessoas/{id}', function (Request $request, $id) use($app) { $data = $request->getContent(); parse_str($data, $out); $stmt = $app['db']->prepare("update pessoas set nome=:nome, email=:email where id=:id"); $stmt->bindParam('id', $id); $stmt->bindParam('nome', $out['nome']); $stmt->bindParam('email', $out['email']); $stmt->execute(); return $app->json(array('success' => true)); }); $app->delete('/pessoas/{id}', function ($id) use($app) { $stmt = $app['db']->prepare("delete from pessoas where id=:id"); $stmt->bindParam('id', $id); $stmt->execute(); return $app->json(array('success' => true)); }); $app->run();
$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); $store->delete(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'form_check' => false)); }); $app->get("/form_brand", function () use($app) { $store = Store::find($_GET['store_id']); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => true, 'store_update' => false)); }); $app->post("/add_brand", function () use($app) { $name = $_POST['name']; $brand = new Brand($name, $id = null); $brand->save(); $store_id = $_POST['store_id']; $store = Store::find($store_id); $store->addBrand($brand->getId()); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => false, 'store_update' => false)); });
}); //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;
$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_edit.html.twig', array('category' => $category)); }); $app->patch("/categories/{id}", function ($id) use($app) { $category = Category::find($id); $category->update($_POST['name']);
//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) { //takes the input values and builds a new restaurant and saves restaurant to database $restaurant_name = $_POST['restaurant_name']; $phone = $_POST['phone']; $address = $_POST['address']; $website = $_POST['website']; $cuisine_id = $_POST['cuisine_id'];
$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) { return $app['twig']->render('students.html.twig', array('students' => Student::getAll())); }); $app->post("/students", function () use($app) { $student = new Student($_POST['name'], $_POST['date']); $student->save();
//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); return $app['twig']->render('client.html.twig', array('client' => $client)); }); //Allows the user to update the client $app->patch("/clients/{id}", function ($id) use($app) { $client_name = $_POST['client_name']; $client = Client::find($id);
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;
$promptr_name = $_POST['promptr_name']; $topic_id = $_POST['topic_id']; $new_promptr = new Promptr($promptr_name, $topic_id); $new_promptr->save(); return $app['twig']->render('promptrs.html.twig', array('promptrs' => Promptr::getAll(), 'topic' => $topic_id, 'topic_picked' => true)); // flag for included template }); $app->get("/topic/{id}", function ($id) use($app) { $topic = Topic::find($id); $promptrs = $topic->getPromptrs(); $allT = Topic::getAll(); return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs, 'all_topics' => $allT)); }); // PROMPTR.HTML.TWIG //delete question from NEW PROMPTR route -- then displays promptr page $app->get("promptr/{id}", function ($id) use($app) { $promptr = Promptr::find($id); $questions = $promptr->getQuestions(); return $app['twig']->render("promptr.html.twig", array('promptr' => $promptr, 'questions' => $questions)); }); //delete question route $app->delete("/promptr/{id}/delete_question/{qId}", function ($id, $qId) use($app) { $question_id = $qId; $promptr = Promptr::find($id); $topic = Topic::find($promptr->getTopicId()); $question = Question::findById($question_id); $question->delete(); $questions = $promptr->getQuestions(); return $app['twig']->render("promptr.html.twig", array('promptr' => $promptr, 'questions' => $questions, 'topic' => $topic)); }); return $app;
return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll())); }); $app->post("/librarian", function () use($app) { $title = $_POST['title']; $book = new Book($title); $book->save(); $name = $_POST['author']; $author = new Author($name); $author->save(); $book->addAuthor($author); $book->addCopy($_POST['copies']); return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll())); }); $app->delete("/book/{id}/delete", function ($id) use($app) { $book = Book::find($id); $book->deleteBook(); 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));
$data['idp'] = !empty($content['idp']) ? $content['idp'] : ''; $data['login'] = !empty($content['login']) ? $content['login'] : ''; $insert = $app['db']->insert('services', array('idp' => $data['idp'], 'login' => $data['login'])); $result = array('success' => $insert !== false); return $app->json($result); }); /** * Delete service item * @param int $itemIdp * @returns string */ $app->delete('/items/{itemId}', function (Silex\Application $app, $itemId) { if ($app['session']->get('user_id') === null) { $app->abort(403, "Request is not allowed."); exit; } $itemId = intval($itemId); $delete = $app['db']->delete('services', array('id' => $itemId)); $result = array('success' => $delete != false); return $app->json($result); }); /** * Get service data * @param object $app * @param int $itemId * @returns string */ $app->get('/items/data/{itemId}', function (Silex\Application $app, $itemId) { if ($app['session']->get('user_id') === null) { $app->abort(403, "Request is not allowed."); exit; }
$m = new Mongo(); $post = $m->annotator->annotations->findOne(array('_id' => new MongoId($id))); $post['id'] = (string) $post['_id']; unset($post['_id']); return $app->json($post); }); $app->put('/annotations/{id}', function (Request $request, $id) use($app) { $post = $app['data']; unset($post['id']); $m = new Mongo(); $m->annotator->annotations->update(array('_id' => new MongoId($id)), array('$set' => $post)); return new Response('', 303, array('Location' => $request->getUri())); }); $app->delete('/annotations/{id}', function (Request $request, $id) use($app) { $m = new Mongo(); $m->annotator->annotations->remove(array('_id' => new MongoId($id))); return new Response('', 204); }); /*** * * Auth Endpoint. * @see https://github.com/okfn/annotator/wiki/Authentication * */ $app->get('/auth/token', function () use($app) { $jwt = jwt::encode(array('consumerKey' => CONSUMER_KEY, 'userId' => USER_ID, 'issuedAt' => time(), 'ttl' => CONSUMER_TTL), CONSUMER_SECRET); return new Response($jwt); }); /*** * * Run, App, Run!
$app->get('/', function () use($app) { return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); //Get stores page $app->get('/stores', function () use($app) { return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); //Add a shoe store to stores page $app->post('/stores/add_store', function () use($app) { $store = new Store($_POST['name']); $store->save(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); //Delete all stores from stores page $app->delete('delete_stores', function () use($app) { Store::deleteAll(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); //Get brands page $app->get('/brands', function () use($app) { return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); //Add a brand to brands page $app->post('/brands/add_brand', function () use($app) { $brand = new Brand($_POST['name']); $brand->save(); return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); //Delete all brands from brands page $app->delete('delete_brands', function () use($app) { Brand::deleteAll(); return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll()));
$app->get('/', function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get('/databases/{databaseName}', function ($databaseName) use($app) { $tableDao = new \SmartAdminer\DAO\TableDao(); $databaseSchema = $tableDao->getDatabaseTables($databaseName); $databaseSchemaParsed = array_map(function ($item) { return array('name' => $item); }, $databaseSchema); return new \Symfony\Component\HttpFoundation\JsonResponse(array('name' => $databaseName, 'tables' => $databaseSchemaParsed)); }); $app->get('/databases', function () use($app) { $tableDao = new \SmartAdminer\DAO\TableDao(); $databaseList = $tableDao->getAllDatabaseName(); $databaseListParsed = array_map(function ($item) { return array('name' => $item); }, $databaseList); return new \Symfony\Component\HttpFoundation\JsonResponse($databaseListParsed); }); $app->get('/tables/{databaseName}/{tableName}', function (Request $request, $databaseName, $tableName) use($app) { $tableDao = new \SmartAdminer\DAO\TableDao(); $table = $tableDao->getTableSchema($databaseName, $tableName); return new \Symfony\Component\HttpFoundation\JsonResponse(array('schema' => $table)); }); $app->delete('/tables/{tableName}', function (Request $request, $tableName) use($app) { $tableDao = new \SmartAdminer\DAO\TableDao(); $databaseName = $request->get('databaseName'); $removeResult = $tableDao->removeTableByName($tableName, $databaseName); return new \Symfony\Component\HttpFoundation\JsonResponse(array('result' => $removeResult)); }); $app->run();
} }); $app->post('/eventos/{id}', function ($id, Request $request) use($app) { $evento = json_decode($request->getContent()); $db = Database::open(); if ($evento->id == 0) { $r = $db->executeUpdate('INSERT INTO eventos(nome, estado, cidade) VALUES(?, ?, ?)', array($evento->nome, $evento->estado, $evento->cidade)); $evento->id = $db->lastInsertId(); } else { $r = $db->executeUpdate('UPDATE eventos SET nome = ?, estado = ?, cidade = ? WHERE id = ?', array($evento->nome, $evento->estado, $evento->cidade, $evento->id)); } return $app->json(array('data' => $evento)); }); $app->delete('/eventos/{id}', function ($id) use($app) { $db = Database::open(); $r = $db->executeUpdate('DELETE FROM eventos WHERE id = ?', array($id)); return $app->json(array('data' => $r)); }); $app->post('/login', function (Request $request) use($app) { $vars = json_decode($request->getContent(), true); try { if (empty($vars['_username']) || empty($vars['_password'])) { throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $vars['_username'])); } /** * @var $user User */ $user = $app['users']->loadUserByUsername($vars['_username']); if (!$app['security.encoder.digest']->isPasswordValid($user->getPassword(), $vars['_password'], '')) { throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $vars['_username'])); } else {
$silex->get('/api/{resource}/{id}/', function ($resource, $id) use($silex) { $res = array(); $q = mysql_query("SELECT * FROM {$resource} WHERE id = '{$id}'"); while ($c = mysql_fetch_assoc($q)) { $res[] = $c; } return new Response(json_encode($res), 200, array('Content-Type' => 'application/json')); }); // POST /{resource} Create $silex->post('/api/{resource}/', function ($resource, Request $request) use($silex) { parse_str($request->getContent(), $data); $query = "INSERT INTO {$resource} (" . implode(', ', array_keys($data)) . ") VALUES ('" . implode("', '", $data) . "')"; mysql_query($query); return new Response(mysql_affected_rows(), 200); }); // PUT /{resource}/{id} Update $silex->put('/api/{resource}/{id}/', function ($resource, $id, Request $request) use($silex) { parse_str($request->getContent(), $data); $data_mod = array(); foreach ($data as $key => $value) { $data_mod[] = "{$key} = '{$value}'"; } $query = "UPDATE {$resource} SET " . implode(', ', $data_mod) . " WHERE id = {$id}"; mysql_query($query); return new Response(mysql_affected_rows(), 200); }); // DELETE /{resource}/{id} Destroy $silex->delete('/api/{resource}/{id}/', function ($resource, $id) use($silex) { $q = mysql_query("DELETE FROM {$resource} WHERE id = '{$id}'"); return new Response(mysql_affected_rows(), 200); });
$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())); }); $app->get("/stylists/{id}/edit", function ($id) use($app) { $stylist = Stylist::find($id); return $app['twig']->render('stylist_edit.html.twig', array('stylist' => $stylist)); }); $app->post("/delete_stylists", function () use($app) { Stylist::deleteAll(); return $app['twig']->render('delete_stylists.html.twig'); }); $app->post("/delete_clients", function () use($app) { // echo "ID is: " . $id . " "; Client::deleteAll(); return $app['twig']->render('delete_clients.html.twig'); });
return $app['twig']->render('store.html.twig', array('store' => $store, 'store_brands' => $store->getBrands(), 'all_brands' => Brand::getAll(), 'stores' => Store::getAll())); }); $app->get("/all_brands", function () use($app) { return $app['twig']->render('all_brands.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->get("/store/{id}", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store.html.twig', array('store' => $store, 'brand_stores' => $store->getBrands(), 'all_brands' => Brand::getAll(), 'stores' => Store::getAll())); }); $app->get("/edit_store", function () use($app) { $store = Store::find($_GET['store_id']); return $app['twig']->render('edit_store.html.twig', array('store' => $store, 'stores' => Store::getAll())); }); $app->patch("/stores/{id}", function ($id) use($app) { $name = $_POST['name']; $store = Store::find($id); $store->update($name); return $app['twig']->render('store.html.twig', array('store' => $store, 'store_brands' => $store->getBrands(), 'all_brands' => Brand::getAll(), 'stores' => Store::getAll())); }); $app->delete("/stores/{id}", function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render('store_brand.html.twig', array('stores' => Store::getAll(), 'display_form' => false)); }); $app->post("/delete_all", function () use($app) { $GLOBALS['DB']->exec("DELETE FROM brands_stores_t;"); Store::deleteAll(); Brand::deleteAll(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); return $app;
return $controller->createFile($name); return json_encode(['status'=>"got here POST", 'name' => $name]); }); $app->get('api/v1.0/document/{name}', function($name) use ($app) { $controller = new \Controller\Json(); return $controller->openFile($name); return json_encode(['status'=>"got here GET", 'name' => $name]); }); $app->put('api/v1.0/document/{name}', function(Request $request) use ($app) { $controller = new \Controller\Json(); return $controller->saveFile($request); return json_encode(['status'=>"got here PUT", 'req' => $request]); }); $app->delete('api/v1.0/document/{name}', function($name) use ($app) { $controller = new \Controller\Json(); return $controller->deleteFile($name); return json_encode(['status'=>"got here DELETE", 'name' => $name]); }); $app->match('/api/v1.0/document/update', '\\Controller\\Json::saveFile'); // // Photo upload // $app->match('/api/v1.0/upload', function (Request $request) use ($app) { $r = []; $r['name'] = $_FILES['file']['name']; $r['type'] = $_FILES['file']['type']; $r['tmp_name'] = $_FILES['file']['tmp_name']; $r['size'] = $_FILES['file']['size'];
<?php require_once __DIR__ . '/../../vendor/autoload.php'; $app = new Silex\Application(); $app['debug'] = true; define('TMP_DIR', sys_get_temp_dir() . '/testarstatic'); $app->get('/{application}/{slug}', function ($application, $slug) use($app) { $file = TMP_DIR . '/' . $application . '/' . $slug; if (!file_exists($file)) { return $app->json(null, 404); } return new Symfony\Component\HttpFoundation\BinaryFileResponse($file); }); $app->delete('/{application}/{slug}', function ($application, $slug) use($app) { $file = TMP_DIR . '/' . $application . '/' . $slug; if (!file_exists($file)) { return $app->json('', 404); } unlink($file); return $app->json('', 204); }); $app->post('/{application}', function ($application) use($app) { $request = $app['request']; @mkdir(TMP_DIR); @mkdir(TMP_DIR . '/' . $application); $request->files->get('file')->move(TMP_DIR . '/' . $application, $request->request->get('slug')); return ''; }); $app->run();
} $entity->set($data); $entity->setUpdated(new \DateTime("now")); if (count($app['validator']->validate($entity)) > 0) { return new Response('Invalid parameters.', 400, array('Content-Type' => 'text/json')); } //Filter entity $filter->filterEntity($entity); $em->persist($entity); $em->flush(); return new Response($entity->toJson(), 200); }); $app->delete('/{entity}/{id}', function ($entity, $id) use($app, $em) { if (!($entity = $em->find('model\\' . ucfirst($entity), $id))) { return new Response('Data not found.', 404, array('Content-Type' => 'text/json')); } $em->remove($entity); $em->flush(); return new Response('Data deleted.', 200); }); //rpc $app->post('/rpc/{procedure}', function ($procedure, Request $request) use($app) { $data = json_decode($request->getContent()); if (!isset($data->parameters)) { return new Response('Missing parameters.', 400, array('Content-Type' => 'text/json')); } $procedure = "procedure\\" . ucfirst($procedure); if (!class_exists($procedure)) { return new Response('Invalid procedure.', 400, array('Content-Type' => 'text/json')); } $class = new $procedure(); $result = $class->execute($data->parameters);
$bar = Bar::find($id); $tokens = $bar->getAllTokens(); return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => true, 'show_menu' => false, 'edit_bar' => false)); }); $app->get('/token/{token_id}', function ($token_id) use($app) { $token = Token::find($token_id); $menu_item = $token->getMenuItem(); $item_id = $menu_item[1]; $item = Item::find($item_id); $bar_id = $menu_item[0]; $bar = Bar::find($bar_id); return $app['twig']->render('redeem_token.html.twig', array('token' => $token, 'item' => $item, 'bar' => $bar)); }); $app->delete('/redeem_token/{token_id}', function ($token_id) use($app) { $token = Token::find($token_id); $token->delete(); return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => false, 'edit_bar' => false)); }); $app->get('/redeem_token/{token_id}', function ($token_id) use($app) { $token = Token::find($token_id); $menu_item = $token->getMenuItem(); $bar_id = $menu_item[0]; $bar = Bar::find($bar_id); $token->delete(); return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => false, 'edit_bar' => false)); }); //Get call to link to a bar with what the token is valid for $app->get('/view_token/{token_id}', function ($token_id) use($app) { $token = Token::find($token_id); $menu_item = $token->getMenuItem(); $bar_id = $menu_item[0];
} }); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__)); $app->register(new Silex\Provider\ServiceControllerServiceProvider()); $app->register(new Shop\Database\DatabaseServiceProvider()); $app['illuminate.capsule']->bootEloquent(); $app['illuminate.capsule']->setAsGlobal(); $app['db.controller'] = $app->share(function () use($app) { return new Shop\Database\DBController($app, new \Shop\Database\Schema()); }); $app['db.controller']->createDB(); $app['home.controller'] = $app->share(function () use($app) { return new Shop\Home\HomeController($app); }); $app['products.controller'] = $app->share(function () use($app) { return new Shop\Products\ProductsController($app, $app['request'], new Shop\Products\ProductModel()); }); $app->get('/', 'home.controller:index'); $app->get('/products', 'products.controller:index'); $app->put('/products/{id}', 'products.controller:update'); $app->post('/products', 'products.controller:insert'); $app->delete('/products/{id}', 'products.controller:delete'); $app->post('/admin', function () use($app) { $admin = (require_once $app['base_dir'] . '/backend/config/admin.php'); $input = $app['request']->request->all(); if ($admin['username'] == $input['username'] && $admin['password'] == $input['password']) { return new Symfony\Component\HttpFoundation\Response(200); } // return new Symfony\Component\HttpFoundation\Response(500); }); $app->run();
<?php require_once 'silex.phar'; require_once dirname(__DIR__) . '/src/MaintenanceExtension.php'; $app = new Silex\Application(); $app->register(new \MaintenanceExtension(), array('maintenance.lock' => __DIR__ . '/maintenance', 'maintenance.file' => __DIR__ . '/maintenance.html')); $app->get('/', function () use($app) { return '/'; }); $app->post('/', function () use($app) { return '/'; }); $app->put('/', function () use($app) { return '/'; }); $app->delete('/', function () use($app) { return '/'; }); if (getenv('SILEX_TEST')) { return $app; } $app->run();
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) { $brand = Brand::find($_POST['brand_id']); $store = Store::find($_POST['store_id']); $brand->addStore($store); $stores = $brand->getStores(); $all_stores = Store::getAll(); return $app['twig']->render('brands.html.twig', array('brand' => $brand, 'stores' => $stores, 'all_stores' => $all_stores));
}); $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())); }); $app->delete("/delete_category/{id}", function ($id) use($app) { $id = $_POST['category_id']; $category = Category::find($id); $category->delete(); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->delete("/delete_task/{id}", function ($id) use($app) { $id = $_POST['task_id']; $task = Task::find($id); $task->delete(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::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('tasks' => Task::getAll()));
} $updateData = $DataProvider->getRequestData(); $result = $DataProvider->updateClient($clientId, $updateData); return $app->json(['message' => 'Client updated!']); }); $app->post('/client', function (Request $request) use($app, $DataProvider) { $insertData = $DataProvider->getRequestData(); $newClientId = $DataProvider->saveNewClient($insertData); if (false == $newClientId) { return $app->json(['errorMessage' => 'Can not insert user'], 500); } $clientDetails = $DataProvider->getClient($newClientId); return $app->json(['message' => 'Client created!', 'client' => $clientDetails]); }); $app->delete('/client/{clientId}', function (Request $request, $clientId) use($app, $DataProvider) { $DataProvider->deleteClient($clientId); return $app->json(['message' => 'Client deleted!']); }); /*======================================= = COMPANY SECTORS = =======================================*/ $app->get('/company-sectors', function () use($app, $DataProvider) { $sectors = $DataProvider->getSectors(); return $app->json($sectors); }); /*============================= = USERS = =============================*/ $app->get('/users', function () use($app, $DataProvider) { $users = $DataProvider->getUsers(); return $app->json($users); });
return $app['twig']->render('pub.html.twig', array('pubs' => $all_pubs)); }); //posts the new pub to the pubs homepage $app->post('/pub_login', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $name = $_POST['name']; $location = $_POST['location']; $link = $_POST['link']; $new_pub = new Pub($name, $location, $link); $new_pub->save(); return $app['twig']->render('pub.html.twig', array('pubs' => Pub::getAll())); }); //deletes all the pubs $app->delete('/pub_login', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); Pub::deleteAll(); return $app['twig']->render('pub.html.twig', array('all_pubs' => Pub::getAll())); }); //takes user to an individual's pub page $app->get('/pub/{id}', function ($id) use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $pub = Pub::find($id); return $app['twig']->render('pub_profile.html.twig', array('pub' => $pub, 'beers' => $pub->getBeers())); }); //allows user to add a particular beer to a particular pub $app->post('/pub/{id}', function ($id) use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $pub = Pub::find($id); $beer_name = $_POST['keyword']; $beer = Beer::findByName($beer_name); $all_beers = $pub->getBeers();
$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); $books = $author->getBooks(); return $app['twig']->render('author.html.twig', array('author' => $author, "books" => $books)); }); //Add book on the individual author page $app->post("/author/{id}/add_book", function ($id) use($app) { $find_author = Author::find($id); $title = $_POST['title']; $new_book = new Book($title); $new_book->save(); $find_author->addBook($new_book);
/* [R] Landing page - display all shoe Stores ** Allow user to add a store or delete all stores. ** Each store listing is a link to its individual page. */ $app->get("/", function () use($app) { return $app['twig']->render('all_stores.html.twig', array('all_stores' => Store::getAll())); }); // [C] Create a new Store, then display all existing stores. $app->post("/", function () use($app) { $escaped_post = escapeCharsInArray($_POST); $new_store = new Store($escaped_post['name'], $escaped_post['location'], $escaped_post['phone']); $new_store->save(); return $app['twig']->render('all_stores.html.twig', array('all_stores' => Store::getAll())); }); // [D] Delete all stores, then show the landing page. $app->delete("/", function () use($app) { Store::deleteAll(); return $app['twig']->render('all_stores.html.twig', array('all_stores' => Store::getAll())); }); /*************Individual Store routes *******************/ /* [R] Display a Store and its brands. ** Allow user to update or delete this store. ** Allow user to add an existing brand to this store, ** or create a new brand to be added to this store. */ $app->get("/store/{id}", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); /* [C] Create a new brand associated with this store. ** Then display all of this store's brands. */ $app->post("/store/{id}", function ($id) use($app) { $store = Store::find($id); $escaped_post = escapeCharsInArray($_POST);