キケッツ掲示板のリポジトリです. 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.
 
 
 
 
 

121 lines
2.0 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.thread_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. find (
  45. SQLite3 $db,
  46. int $id)
  47. : ?\Dto\Thread
  48. {
  49. $sql = "
  50. SELECT
  51. t.id,
  52. t.title,
  53. t.explain,
  54. MAX(r.date) AS latest
  55. FROM
  56. threads AS t
  57. LEFT OUTER JOIN
  58. responses AS r
  59. ON
  60. r.thread_id = t.id
  61. WHERE
  62. t.id = $id
  63. GROUP BY
  64. t.id
  65. ORDER BY
  66. latest DESC";
  67. $result = $db -> query ($sql);
  68. $row = $result -> fetchArray (SQLITE3_ASSOC);
  69. if ($row === false)
  70. return null;
  71. $thread = new \Dto\Thread;
  72. $thread -> id = $row['id'];
  73. $thread -> title = $row['title'];
  74. $thread -> explain = $row['explain'];
  75. $thread -> length = $row['length'];
  76. return $thread;
  77. }
  78. public static function
  79. create_thread (
  80. SQLite3 $db,
  81. string $title,
  82. string $explain)
  83. : void
  84. {
  85. ;
  86. }
  87. public static function
  88. delete_thread (
  89. SQLite3 $db,
  90. int $id)
  91. : void
  92. {
  93. $db -> query ("
  94. DELETE FROM
  95. threads
  96. WHERE
  97. id = $id");
  98. }
  99. }