総合演習
<?php
require_once('data.php');
require_once('menu.php');
?>
<html>
<head>
<meta charset="utf-8">
<title>Café Progate</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link href='https://fonts.googleapis.com/css?family=Pacifico|Lato' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="menu-wrapper container">
<h1 class="logo">Café Progate</h1>
<h3>メニュー<?php echo Menu::getCount() ?>品</h3>
<form method="post" action="confirm.php">
<div class="menu-items">
<?php foreach ($menus as $menu): ?>
<div class="menu-item">
<img src="<?php echo $menu->getImage() ?>" class="menu-item-image">
<h3 class="menu-item-name"><?php echo $menu->getName() ?></h3>
<?php if ($menu instanceof Drink): ?>
<p class="menu-item-type"><?php echo $menu->getType() ?></p>
<?php else: ?>
<?php for($i=0;$i<$menu->getSpiciness();$i++): ?>
<img src="https://s3-ap-northeast-1.amazonaws.com/progate/shared/images/lesson/php/chilli.png" class="icon-spiciness">
<?php endfor ?>
<?php endif ?>
<p class="price">¥<?php echo $menu->getTaxIncludedPrice() ?>(税込)</p>
<input type="text" value="0" name="<?php echo $menu->getName() ?>">
<span>個</span>
</div>
<?php endforeach ?>
</div>
<input type="submit" value="注文する">
</form>
</div>
</body>
</html>
<?php
require_once('drink.php');
require_once('food.php');
$juice = new Drink('JUICE', 600, 'https://s3-ap-northeast-1.amazonaws.com/progate/shared/images/lesson/php/juice.png', 'アイス');
$coffee = new Drink('COFFEE', 500, 'https://s3-ap-northeast-1.amazonaws.com/progate/shared/images/lesson/php/coffee.png', 'ホット');
$curry = new Food('CURRY', 900, 'https://s3-ap-northeast-1.amazonaws.com/progate/shared/images/lesson/php/curry.png', 3);
$pasta = new Food('PASTA', 1200, 'https://s3-ap-northeast-1.amazonaws.com/progate/shared/images/lesson/php/pasta.png', 1);
$menus = array($juice, $coffee, $curry, $pasta);
?>
<?php
class Menu {
protected $name;
protected $price;
protected $image;
private $orderCount = 0;
protected static $count = 0;
public function __construct($name, $price, $image) {
$this->name = $name;
$this->price = $price;
$this->image = $image;
self::$count++;
}
public function hello() {
echo '私は'.$this->name.'です';
}
public function getName() {
return $this->name;
}
public function getImage() {
return $this->image;
}
public function getOrderCount() {
return $this->orderCount;
}
public function setOrderCount($orderCount) {
$this->orderCount = $orderCount;
}
public function getTaxIncludedPrice() {
return floor($this->price * 1.08);
}
public function getTotalPrice() {
return $this->getTaxIncludedPrice() * $this->orderCount;
}
public static function getCount() {
return self::$count;
}
}
?>
<?php
require_once('menu.php');
class Drink extends Menu {
private $type;
public function __construct($name, $price, $image, $type) {
parent::__construct($name, $price, $image);
$this->type = $type;
}
public function getType() {
return $this->type;
}
public function setType($type) {
$this->type = $type;
}
}
?>
<?php
require_once('menu.php');
class Food extends Menu {
private $spiciness;
public function __construct($name, $price, $image, $spiciness) {
parent::__construct($name, $price, $image);
$this->spiciness = $spiciness;
}
public function getSpiciness() {
return $this->spiciness;
}
}
?>