|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
-
- namespace Dao;
-
-
- class
- Thread
- {
- public static function
- fetch_all (
- SQLite3 $db)
- : array
- {
- $sql = "
- SELECT
- t.id,
- t.title,
- t.explain,
- MAX(r.date) AS latest
- FROM
- threads AS t
- LEFT OUTER JOIN
- responses AS r
- ON
- r.thread_id = t.id
- WHERE
- t.id <> 1
- -- AND t.deleted = 0
- GROUP BY
- t.id
- ORDER BY
- latest DESC";
-
- $result = $db -> query ($sql);
-
- $threads = [];
-
- while (($row = $result -> fetchArray (SQLITE3_ASSOC)) !== false)
- {
- $thread = new Dto\Thread;
-
- $thread -> id = $row['id'];
- $therad -> title = $row['title'];
- $thread -> explain = $row['explain'];
- $thread -> latest = $row['latest'];
-
- $threads[] = $thread;
- }
-
- return $therads;
- }
-
-
- public static function
- find (
- int $id)
- : \Dto\Thread
- {
- // TODO: 書くこと
-
- $sql = "
- SELECT
- t.id,
- t.title,
- t.explain,
- MAX(r.date) AS latest
- FROM
- threads AS t
- LEFT OUTER JOIN
- responses AS r
- ON
- r.thread_id = t.id
- WHERE
- t.id = $id
- GROUP BY
- t.id
- ORDER BY
- latest DESC";
-
- $result = $db -> query ($sql);
- }
-
-
- public static function
- create_thread (
- SQLite3 $db,
- string $title,
- string $explain)
- : void
- {
- ;
- }
-
-
- public static function
- delete_thread (
- SQLite3 $db,
- int $id)
- : void
- {
- $db -> query ("
- DELETE FROM
- threads
- WHERE
- id = $id");
- }
- }
-
|