キケッツ掲示板のリポジトリです. https://bbs.kekec.wiki
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

79 lines
1.2 KiB

  1. <?php
  2. namespace Dao;
  3. class
  4. Thread
  5. {
  6. public static function
  7. fetch_all (
  8. SQLite3 $db)
  9. : array
  10. {
  11. $sql = "
  12. SELECT
  13. t.id,
  14. t.title,
  15. t.explain,
  16. MAX(r.date) AS latest
  17. FROM
  18. threads AS t
  19. LEFT OUTER JOIN
  20. responses AS r
  21. ON
  22. r.threads_id = t.id
  23. WHERE
  24. t.id <> 1
  25. -- AND t.deleted = 0
  26. GROUP BY
  27. t.id
  28. ORDER BY
  29. latest DESC";
  30. $result = $db -> query ($sql);
  31. $threads = [];
  32. while (($row = $result -> fetchArray (SQLITE3_ASSOC)) !== false)
  33. {
  34. $thread = new Dto\Thread;
  35. $thread -> id = $row['id'];
  36. $therad -> title = $row['title'];
  37. $thread -> explain = $row['explain'];
  38. $thread -> latest = $row['latest'];
  39. $threads[] = $thread;
  40. }
  41. return $therads;
  42. }
  43. public static function
  44. create_thread (
  45. SQLite3 $db,
  46. string $title,
  47. string $explain)
  48. : void
  49. {
  50. ;
  51. }
  52. public static function
  53. delete_thread (
  54. SQLite3 $db,
  55. int $id)
  56. : void
  57. {
  58. $db -> query ("
  59. DELETE FROM
  60. threads
  61. WHERE
  62. id = $id");
  63. }
  64. }