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

100 lines
1.8 KiB

  1. <?php
  2. namespace Dao;
  3. class
  4. Response
  5. {
  6. public static function
  7. fetch_all (
  8. \SQLite3 $db,
  9. int $thread_id)
  10. : array
  11. {
  12. $sql = "
  13. SELECT
  14. thread_id,
  15. response_id,
  16. name,
  17. message,
  18. date,
  19. image,
  20. held,
  21. deleted,
  22. pass,
  23. good,
  24. bad
  25. FROM
  26. responses
  27. WHERE
  28. id = $thread_id";
  29. $result = $db -> query ($sql);
  30. $responses = [];
  31. while (($row = $result -> fetchArray (SQLITE_ASSOC)) !== false)
  32. {
  33. $response = new Dto\Response;
  34. $response -> thread_id = $row['thread_id'];
  35. $response -> response_id = $row['response_id'];
  36. $response -> name = $row['name'];
  37. $response -> message = $row['message'];
  38. $response -> date = $row['date'];
  39. $response -> image = $row['image'];
  40. $response -> held = $row['held'];
  41. $response -> deleted = $row['deleted'];
  42. $response -> pass = $row['pass'];
  43. $response -> good = $row['good'];
  44. $response -> bad = $row['bad'];
  45. $responses[] = $response;
  46. }
  47. return $responses;
  48. }
  49. public static function
  50. like (
  51. \SQLite3 $db,
  52. int $thread_id,
  53. int $response_id)
  54. : void
  55. {
  56. $sql = "
  57. UPDATE
  58. responses
  59. SET
  60. good = good + 1
  61. WHERE
  62. (thread_id = $thread_id)
  63. AND (response_id = $response_id)";
  64. $db -> query ($sql);
  65. }
  66. public static function
  67. dislike (
  68. \SQLite3 $db,
  69. int $thread_id,
  70. int $response_id)
  71. : void
  72. {
  73. $sql = "
  74. UPDATE
  75. responses
  76. SET
  77. bad = bad + 1
  78. WHERE
  79. (thread_id = $thread_id)
  80. AND (response_id = $response_id)";
  81. $db -> query ($sql);
  82. }
  83. }