generated from teknasyon-bootcamp/homework5
-
Notifications
You must be signed in to change notification settings - Fork 4
/
book.php
145 lines (121 loc) · 3.75 KB
/
book.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require "vendor/autoload.php";
$config = require "config.php";
$engine = $config['engine'];
$host = $config['host'];
$user = $config['user'];
$pass = $config['password'];
$log_type = $config['logging'];
$log_file_dir = __DIR__."/storage/logs/logs.log";
use App\DB\Engine\Mysql;
use App\DB\Engine\MongoDB;
use App\Db\Database;
use App\Logger\Driver\Database as LoggerDatabase;
use App\Logger\Driver\File;
use App\Logger\Logger;
use App\Logger\LoggableInterface;
if ($engine == "mysql") {
$driver = new Mysql($host, $user, $pass, "book_app");
} elseif ($engine =="mongodb") {
$driver = new MongoDB("", "", "", "", "", []);
}
if($log_type =="file"){
$logger = new Logger(new File($log_file_dir));
}else{
$logger = new Logger(new LoggerDatabase($driver));
}
try{
$db = new Database();
$db->setDriver($driver);
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
if (isset($_GET['id'])){
try {
$book = $db->find("book",$_GET['id']);
$authors = $db->all("author");
$sections = $db->all("section");
$posts = $db->all("posts");
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
foreach ($authors as $author){
if ($book['id'] == $author['bookId']){
$author_name =$author['author_name'];
}
}
foreach ($sections as $section){
if($book['id'] == $section['bookId']){
$content_list[] = $section['content'];
$sectionID = $section['id'];
$section_operations_arr[] = [
$section['id'] => $section['section_name']
];
}
}
}
?>
<?php include "_shared/header.php";?>
<div class="container">
<div class="d-flex justify-content-end">
<div>
<a href="section-create.php?id=<?=$_GET['id']?>" class="btn btn-primary mr-3">Bölüm Ekle</a>
</div>
<div>
<a href="post-create.php?id=<?=$_GET['id']?>" class="btn btn-primary">Yazı Ekle</a>
</div>
</div>
<hr>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Bölüm id</th>
<th scope="col">Kitap</th>
<th>Yazar</th>
<th>Bölüm</th>
<th scope="col">Düzenle&Sil</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_GET['id'] ) && isset($section_operations_arr)){
foreach ($section_operations_arr as $section) {
foreach ($section as $section_id => $section_name){
echo "
<tr>
<th scope='row'>$section_id</th>
<td>$book[name]</td>
<td>$author_name</td>
<td>$section_name</td>
<td>
<div class=''>
<a href='section-edit.php?id=$section_id' class='btn btn-warning mr-3 '>Bölüm Düzenle</a>
<a href='section-delete.php?id=$section_id' class='btn btn-danger '>Bölümü Sil</a>
</div>
</td>
</tr>";
}
}
}
?>
</tbody>
</table>
<div class="mt-5">
<h1 class="text-center"><?= $book['name']??''?></h1>
<h3 class="text-center mt-3"><?= $author_name??'' ?></h3>
</div>
<div class="mt-5">
<?php
foreach ($posts as $post){
if($book['id'] == $post['bookId']){
echo "<div class='mt-5'><p>$post[post]</p></div>
<div class='mt-3'>
<a href='post-edit.php?id=$post[id]' class='btn btn-warning mr-3 '>Post Düzenle</a>
<a href='post-delete.php?id=$post[id]' class='btn btn-danger '>Post Sil</a>
</div> ";
}
}
?>
</div>
</div>
<?php include "_shared/footer.php";?>