issue: count number of replies in overview
[minimedit.git] / issue / index.php
index ff99064574b88658893271e011dd49f0f97e09e1..f950861f98c4181e459e9cb1cbe925b1637baf7c 100644 (file)
@@ -7,16 +7,16 @@ if ($id) {
        $Article->title = "Issue #$id";
 
        $Issue = $Db->query(
-               'SELECT * FROM issues WHERE id = ?', [$id]
+               'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
        )->fetch();
        if (!$Issue) throw new Exception('Issuenummer niet gevonden');
 
        $Article->title .= ': '.htmlspecialchars($Issue->subject);
        print "<h2>{$Article->title}</h2>\n";
-       print $Issue->body;
+       $author = $Issue->author ? new User('profile/'.$Issue->author, FALSE) : NULL;
        printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
                'Geplaatst',
-               $Issue->author ? " door <strong>{$Issue->author}</strong>" : '',
+               $author ? " door <strong>{$author->name}</strong>" : '',
                showdate(preg_split('/\D/', $Issue->created))
        );
        if ($Issue->assign) {
@@ -30,6 +30,7 @@ if ($id) {
                        showdate(preg_split('/\D/', $Issue->closed))
                );
        }
+       print $Issue->body;
        $Args = "/$id";  # minimal reference
        print placeholder_include('reply');
        return;
@@ -50,21 +51,27 @@ if ($_POST) {
                $_POST = [];
 }
 
-$sql = 'SELECT * FROM issues';
+$cols = "*, (SELECT count(*) FROM comments WHERE"
+       . " page=i.page||'/'||i.id AND message IS NOT NULL) AS replycount";
+$sql = "SELECT $cols FROM issues i WHERE page = ?";
 if (isset($_GET['open'])) {
-       $sql .= ' WHERE closed IS NULL';
+       $sql .= ' AND closed IS NULL';
 }
 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
-$query = $Db->query($sql);
+$query = $Db->query($sql, [$Page]);
 
 ob_start();
 print '<ul>';
 while ($row = $query->fetch()) {
-       printf('<li><a href="%s">%s <small class="date">%s</small></a>',
+       printf('<li><a href="%s">%s <small class="date">%s</small>%s</a>',
                "/$Page/{$row->id}/{$row->link}",
                sprintf($row->closed ? '<strike>%s</strike>' : '%s',
                        htmlspecialchars($row->subject)),
-               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
+               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
+               implode(' ', [
+                       $row->replycount ? sprintf('<span class=right>+%d</span>', $row->replycount) : '',
+                       isset($row->assign) ? ' <em class="right">'.$row->assign.'</em>' : '',
+               ])
        );
        print "</li>\n";
 }