From d467d82a3e25acf2da4efe9c2929268ba1893209 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Tue, 13 Feb 2024 12:49:38 +0900 Subject: [PATCH] =?UTF-8?q?DAO=20=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daos/thread.php | 20 ++++++++++++++++---- www/index.php | 8 +++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/daos/thread.php b/daos/thread.php index 2eecbba..9f7ecb7 100644 --- a/daos/thread.php +++ b/daos/thread.php @@ -53,11 +53,10 @@ Thread public static function find ( - int $id) - : \Dto\Thread + SQLite3 $db, + int $id) + : ?\Dto\Thread { - // TODO: 書くこと - $sql = " SELECT t.id, @@ -78,6 +77,19 @@ Thread latest DESC"; $result = $db -> query ($sql); + $row = $result -> fetchArray (SQLITE3_ASSOC); + + if ($row === false) + return null; + + $thread = new \Dto\Thread; + + $thread -> id = $row['id']; + $thread -> title = $row['title']; + $thread -> explain = $row['explain']; + $thread -> length = $row['length']; + + return $thread; } diff --git a/www/index.php b/www/index.php index f83c3d8..4ff9194 100644 --- a/www/index.php +++ b/www/index.php @@ -5,6 +5,8 @@ require_once __DIR__ . '/../import.php'; use \Dto; +$db = new SQLite3 ('../db.sqlite3'); + if (isset ($_GET['page'])) $page = $_GET['page']; else @@ -29,7 +31,7 @@ else $dir = './images/'; $handle = opendir ($dir); -if ($row = \Dao\Thread :: find ($thread)) +if ($row = \Dao\Thread :: find ($db, $thread)) { $title = $row -> title; $explain = $row -> explain; @@ -39,13 +41,13 @@ if (isset ($_GET['id'])) { if (($_GET['evaluate'] ?? '') === 'good') { - \Dao\Response :: like ((int) $_GET['id']); + \Dao\Response :: like ($db, (int) $_GET['id']); header ("Location: ./?thread=$thread&sort=$sort"); } if (($_GET['evaluate'] ?? '') === 'bad') { - \Dao\Response :: dislike ((int) $_GET['id']); + \Dao\Response :: dislike ($db, (int) $_GET['id']); header ("Location: ./?thread=$thread&sort=$sort"); } }