This repository has been archived on 2026-03-14. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kekec_bbs/daos/thread.php
T
2024-02-13 12:49:38 +09:00

121 lines
2.0 KiB
PHP

<?php
namespace Dao;
class
Thread
{
public static function
fetch_all (
SQLite3 $db)
: array
{
$sql = "
SELECT
t.id,
t.title,
t.explain,
MAX(r.date) AS latest
FROM
threads AS t
LEFT OUTER JOIN
responses AS r
ON
r.thread_id = t.id
WHERE
t.id <> 1
-- AND t.deleted = 0
GROUP BY
t.id
ORDER BY
latest DESC";
$result = $db -> query ($sql);
$threads = [];
while (($row = $result -> fetchArray (SQLITE3_ASSOC)) !== false)
{
$thread = new Dto\Thread;
$thread -> id = $row['id'];
$therad -> title = $row['title'];
$thread -> explain = $row['explain'];
$thread -> latest = $row['latest'];
$threads[] = $thread;
}
return $therads;
}
public static function
find (
SQLite3 $db,
int $id)
: ?\Dto\Thread
{
$sql = "
SELECT
t.id,
t.title,
t.explain,
MAX(r.date) AS latest
FROM
threads AS t
LEFT OUTER JOIN
responses AS r
ON
r.thread_id = t.id
WHERE
t.id = $id
GROUP BY
t.id
ORDER BY
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;
}
public static function
create_thread (
SQLite3 $db,
string $title,
string $explain)
: void
{
;
}
public static function
delete_thread (
SQLite3 $db,
int $id)
: void
{
$db -> query ("
DELETE FROM
threads
WHERE
id = $id");
}
}