Exemplo n.º 1
0
 public function buyCar(Car $car)
 {
     if ($this->getMoney() >= $car->getPrice()) {
         $this->setMoney($this->getMoney() - $car->getPrice());
         $this->setCar($car);
     }
 }
Exemplo n.º 2
0
 public function buyCar(Car $car)
 {
     if ($this->money >= $car->getPrice()) {
         $this->money -= $car->getPrice();
         echo ' Purchase successful!', PHP_EOL;
         $this->car = $car;
         $car->changeOwner($this);
         return $this->money;
     } else {
         echo ' You need more money! ';
     }
 }
 public function buyCar($car)
 {
     $car = new Car();
     $carPrice = $car->getPrice();
     //return $car->getModel;
     if ($this->money > $carPrice) {
         $this->ownedCar = $car;
         return $carPrice;
         //$this->money -= $carPrice;
     } else {
         return $this->money;
     }
 }
Exemplo n.º 4
0
{
    public $brand;
    public $model;
    public $year;
    public $driver;
    private $price;
    public function showBrand()
    {
        echo $this->brand;
    }
    public function showModel()
    {
        echo $this->model;
    }
    public function setPrice($price)
    {
        $this->price = round($price, 2);
    }
    public function getPrice($bool)
    {
        if ($bool === true) {
            return number_format($this->price, 2, '.', ',');
        } else {
            return $this->price;
        }
    }
}
$bmw = new Car();
$bmw->setPrice(25700.358);
echo $bmw->getPrice(true);
Exemplo n.º 5
0
$app->get('/', function () use($app) {
    return $app['twig']->render('home.html.twig');
});
$app->get('/post', function () use($app) {
    return $app['twig']->render('cars.html.twig', array('cars' => Car::getAll()));
});
$app->get("/search", function () use($app) {
    return $app['twig']->render('search_cars.html.twig');
});
$app->post("/cars", function () use($app) {
    $car = new Car($_POST['model'], $_POST['price'], $_POST['miles'], $_POST['image_path']);
    $car->save();
    return $app['twig']->render('create_car.html.twig', array('newcar' => $car));
});
$app->post("/delete_car", function () use($app) {
    Car::deleteAll();
    return $app['twig']->render('delete_cars.html.twig', array('cars' => Car::getAll()));
});
$app->get("/view_car", function () use($app) {
    $cars_matching_search = array();
    $cars = Car::getAll();
    $user_price = $_GET["price"];
    $user_miles = $_GET["miles"];
    foreach ($cars as $car) {
        if ($car->getPrice() < $user_price && $car->getMiles() < $user_miles) {
            array_push($cars_matching_search, $car);
        }
    }
    return $app['twig']->render('car_posting.html.twig', array('cars' => $cars_matching_search));
});
return $app;
Exemplo n.º 6
0
// Direct app to twig.path
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// Home page: car search form.
$app->get("/", function () use($app) {
    return $app['twig']->render('cars.html.twig', array('cars' => Car::getAll()));
});
// Page: car newly added.
$app->post('/car_added', function () use($app) {
    $car = new Car($_POST['model'], $_POST['price'], $_POST['miles'], $_POST['image']);
    $car->save();
    return $app['twig']->render('car_added.html.twig', array('newcar' => $car));
});
// Page: Delete cars
$app->post('/delete_cars', function () use($app) {
    Car::deleteAll();
    return $app['twig']->render('delete_cars.html.twig');
});
// Page: results display.
$app->get('/results', function () use($app) {
    // $cars = array(Car::getAll());
    $cars_we_want = array();
    foreach ($_SESSION['list_of_cars'] as $car) {
        if ($car->getPrice() < $_GET["price"] && $car->getMiles() < $_GET["miles"]) {
            array_push($cars_we_want, $car);
        }
    }
    // Set the array "cars" as equal to "$cars_we_want", pass it to results page
    return $app['twig']->render('results.html.twig', array('cars' => $cars_we_want));
});
return $app;