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

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. find (
  45. int $id)
  46. : \Dto\Thread
  47. {
  48. ;
  49. }
  50. public static function
  51. create_thread (
  52. SQLite3 $db,
  53. string $title,
  54. string $explain)
  55. : void
  56. {
  57. ;
  58. }
  59. public static function
  60. delete_thread (
  61. SQLite3 $db,
  62. int $id)
  63. : void
  64. {
  65. $db -> query ("
  66. DELETE FROM
  67. threads
  68. WHERE
  69. id = $id");
  70. }
  71. }