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

thread.php 2.0 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. if ($row === false)
  69. return null;
  70. $row = $result -> fetchArray (SQLITE3_ASSOC);
  71. if ($row === false)
  72. return null;
  73. $thread = new \Dto\Thread;
  74. $thread -> id = $row['id'];
  75. $thread -> title = $row['title'];
  76. $thread -> explain = $row['explain'];
  77. $thread -> length = $row['length'];
  78. return $thread;
  79. }
  80. public static function
  81. create_thread (
  82. \SQLite3 $db,
  83. string $title,
  84. string $explain)
  85. : void
  86. {
  87. ;
  88. }
  89. public static function
  90. delete_thread (
  91. \SQLite3 $db,
  92. int $id)
  93. : void
  94. {
  95. $db -> query ("
  96. DELETE FROM
  97. threads
  98. WHERE
  99. id = $id");
  100. }
  101. }