<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; session_start(); if (empty($_SESSION['list_of_places'])) { $_SESSION['list_of_places'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get('/', function () use($app) { return $app['twig']->render('places.html.twig', array('places' => Place::getAll())); }); $app->post("/places", function () use($app) { $place = new Place($_POST['city']); $place->save(); return $app['twig']->render('create_place.html.twig', array('newplace' => $task)); }); return $app;
// routes $app->get("/", function () use($app) { return $app['twig']->render('home.html.twig', array('places' => Place::getAll())); }); $app->post('/add_place', function () use($app) { $place = new Place($_POST['city'], $_POST['country'], $_POST['year'], $_POST['image_src']); $place->save(); return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => "Sounds like a fun trip!", 'type' => 'info'))); }); $app->post('/delete_all', function () use($app) { Place::deleteAll(); return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => "Time to book a trip!", 'type' => 'info'))); }); $app->post('/delete_one', function () use($app) { $name_of_place = $_POST['delete_one']; $found = false; foreach ($_SESSION['list_of_places'] as $key => $place) { if ($place->getCity() == $name_of_place) { $found = true; $key_to_delete = $key; break; } } $place_to_delete = $_SESSION['list_of_places'][$key]; $place_to_delete->delete(); return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => $name_of_place . " was deleted!", 'type' => 'danger'))); }); $app->get('/show_form', function () use($app) { return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'form' => true)); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; //SESSION - Stores Cookies session_start(); if (empty($_SESSION['list_of_cities'])) { $_SESSION['list_of_cities'] = array(); } $app = new Silex\Application(); //Twig Path $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //Route and Controller $app->get("/", function () use($app) { $all_cities = Place::getAll(); return $app['twig']->render('city.html.twig', array('cities' => $all_cities)); }); /* $app->get("/", function() use ($app) { $all_times = Place::getAll(); return $app['twig']->render('city.html.twig', array('times' => $all_times)); }); */ //cities POST $app->post("/city", function () use($app) { $city = new Place($_POST['cityName'], $_POST['lengthOfTime'], $_POST['reasonOfVisit'], $_POST['imagePath']); $city->save(); return $app['twig']->render('create_city.html.twig', array('newcity' => $city)); }); //cities POST delete
function testDeleteAll() { //Arrange $place_name = "Director Park"; $address = "SW Park Ave"; $latitude = 45.518672; $longitude = -122.681211; $id = 1; $test_place = new Place($place_name, $address, $latitude, $longitude, $id); $test_place->save(); //Act Place::deleteAll(); $result = Place::getAll(); //Assert $this->assertEquals([], $result); }
static function generateLocation() { $places = Place::getAll(); $number_of_places = count($places); $random_number = rand(0, $number_of_places - 1); $random_location = $places[$random_number]; return $random_location; }