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

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. int $id)
  46. : \Dto\Thread
  47. {
  48. // TODO: 書くこと
  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. }
  69. public static function
  70. create_thread (
  71. SQLite3 $db,
  72. string $title,
  73. string $explain)
  74. : void
  75. {
  76. ;
  77. }
  78. public static function
  79. delete_thread (
  80. SQLite3 $db,
  81. int $id)
  82. : void
  83. {
  84. $db -> query ("
  85. DELETE FROM
  86. threads
  87. WHERE
  88. id = $id");
  89. }
  90. }