Browse Source

DAO について修正

sqlite
みてるぞ 7 months ago
parent
commit
d467d82a3e
2 changed files with 21 additions and 7 deletions
  1. +16
    -4
      daos/thread.php
  2. +5
    -3
      www/index.php

+ 16
- 4
daos/thread.php View File

@@ -53,11 +53,10 @@ Thread


public static function public static function
find ( find (
int $id)
: \Dto\Thread
SQLite3 $db,
int $id)
: ?\Dto\Thread
{ {
// TODO: 書くこと

$sql = " $sql = "
SELECT SELECT
t.id, t.id,
@@ -78,6 +77,19 @@ Thread
latest DESC"; latest DESC";


$result = $db -> query ($sql); $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;
} }






+ 5
- 3
www/index.php View File

@@ -5,6 +5,8 @@ require_once __DIR__ . '/../import.php';
use \Dto; use \Dto;




$db = new SQLite3 ('../db.sqlite3');

if (isset ($_GET['page'])) if (isset ($_GET['page']))
$page = $_GET['page']; $page = $_GET['page'];
else else
@@ -29,7 +31,7 @@ else
$dir = './images/'; $dir = './images/';
$handle = opendir ($dir); $handle = opendir ($dir);


if ($row = \Dao\Thread :: find ($thread))
if ($row = \Dao\Thread :: find ($db, $thread))
{ {
$title = $row -> title; $title = $row -> title;
$explain = $row -> explain; $explain = $row -> explain;
@@ -39,13 +41,13 @@ if (isset ($_GET['id']))
{ {
if (($_GET['evaluate'] ?? '') === 'good') if (($_GET['evaluate'] ?? '') === 'good')
{ {
\Dao\Response :: like ((int) $_GET['id']);
\Dao\Response :: like ($db, (int) $_GET['id']);
header ("Location: ./?thread=$thread&sort=$sort"); header ("Location: ./?thread=$thread&sort=$sort");
} }


if (($_GET['evaluate'] ?? '') === 'bad') if (($_GET['evaluate'] ?? '') === 'bad')
{ {
\Dao\Response :: dislike ((int) $_GET['id']);
\Dao\Response :: dislike ($db, (int) $_GET['id']);
header ("Location: ./?thread=$thread&sort=$sort"); header ("Location: ./?thread=$thread&sort=$sort");
} }
} }


Loading…
Cancel
Save