issue/report: activity widget to list latest messages
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 3 Jan 2020 08:46:05 +0000 (09:46 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 21 Dec 2020 16:46:33 +0000 (17:46 +0100)
issue/report.html [new file with mode: 0644]
widget/comments.sql
widget/issue/activity.php [new file with mode: 0644]

diff --git a/issue/report.html b/issue/report.html
new file mode 100644 (file)
index 0000000..9923980
--- /dev/null
@@ -0,0 +1,3 @@
+<h2>Laatste reacties</h2>
+
+[[issue/activity n=5]]
index 3dc9f07e95f58be22671d2dcb01ab8d041a2af74..3a5fcfc2fc6765c262ee484c012c9398379649bc 100644 (file)
@@ -27,3 +27,9 @@ CREATE TABLE journal (
        value      text,
        id         serial      NOT NULL PRIMARY KEY
 );
+
+CREATE OR REPLACE VIEW messages AS (
+       SELECT *, regexp_replace(page, '.*/', '')::int issue FROM comments
+               UNION ALL
+       SELECT concat(page,'/',id), body, created, author, NULL, id FROM issues
+);
diff --git a/widget/issue/activity.php b/widget/issue/activity.php
new file mode 100644 (file)
index 0000000..7829f93
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+global $Db;
+require_once 'database.inc.php';
+
+$limit = $Page->place['n'] ?? 50;
+$cols = 'm.*, i.subject, i.closed';
+$sql = "SELECT $cols FROM messages m JOIN issues i ON i.id = issue";
+$sql .= " ORDER BY m.created DESC LIMIT $limit";
+$query = $Db->query($sql);
+
+print '<ul class="replies">';
+
+while ($row = $query->fetch()) {
+       $rowuser = new User("profile/{$row->author}");
+       print '<li>';
+       printf('<strong>%s</strong> <small class="date">%s</small>',
+               $rowuser->html, showdate(preg_split('/\D/', $row->created))
+       );
+       printf("\n\t".'<a href="/%s">%s</a>', $row->page, $row->subject);
+       if ($row->closed) {
+               print ' <em>(opgelost)</em>';
+       }
+       printf("\n\t<blockquote>%s</blockquote>", $row->message);
+       print "</li>\n";
+}
+
+print "</ul>\n";