/
page.php
executable file
·84 lines (78 loc) · 1.96 KB
/
page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
class View
{
function __construct(string $type, array $data)
{
echo $this->main_view($this->$type($data));
}
// 基本となるViewで{$contents}の部分に固有の要素を組み込み表示する。
function main_view($contents = null)
{
$data = date("ymdhis");
return <<<EOF
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>kakera-lab</title>
<meta name="description" content="カード交換システム">
<link rel="stylesheet" href="style.css?{$data}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
{$contents}
</body>
</html>
EOF;
}
// チェックイン画面
function check_user(array $data): string
{
$id = $data["id"];
return <<<EOF
<form method="post" action="">
<div class="view">
{$this->card($id)}
</div>
<div><button class="button" type="submit" name="check_in" value=1>チェックイン</button></div>
<div><button class="button" type="submit" name="check_out" value=1>戻る</button></div>
</form>
EOF;
}
// 新規取得カードを表示
function card_add(array $data): string
{
$id = $data["id"];
return <<<EOF
<div class="view">
{$this->card($id)}
</div>
<div><button class="button" type="button" onclick="location.href='./index.php'">戻る</button></div>
EOF;
}
//カードリストを描画する
function card_list(array $ids): string
{
$data = "";
foreach ($ids as $id) {
$data = $data . $this->Card($id);
}
// 最大枚数を取得した場合
if (count($ids) === 39) {
$data = $data . $this->Card("full");
}
return <<<EOF
<div class="view">
{$data}
</div>
EOF;
}
// カードを描画する
protected function card(string $id): string
{
return <<<EOF
\t<div class="box"><img class="card" src="./image/{$id}.png" alt="no image"/></div>\n
EOF;
}
}
?>