* @license MIT */ declare(strict_types=1); use BitBadger\PDODocument\{Custom, Field, Query}; use BitBadger\PDODocument\Mapper\{ArrayMapper, DocumentMapper}; use FeedReaderCentral\{Feed, Key, Table}; include '../start.php'; FeedReaderCentral\Security::verifyUser(); $field = Field::EQ('user_id', $_SESSION[Key::UserId], ':user'); $feeds = Custom::list(Query\Find::byFields(Table::Feed, [$field]) . " ORDER BY lower(data->>'title')", $field->appendParameter([]), new DocumentMapper(Feed::class)); page_head('Your Feeds'); echo '

Your Feeds

' . hx_get('/feed/?id=-1', 'Add Feed') . '

'; $feeds->iter(function (Feed $feed) { $item = Table::Item; $counts = Custom::single(<<>'feed_id' = :feed) AS total, (SELECT COUNT(*) FROM $item WHERE data->>'feed_id' = :feed AND data->>'is_read' = 0) AS unread, (SELECT COUNT(*) FROM $item WHERE data->>'feed_id' = :feed AND data->>'is_bookmarked' = 1) AS marked SQL, [':feed' => $feed->id], new ArrayMapper())->getOrDefault(['total' => 0, 'unread' => 0, 'marked' => 0]); echo '

' . htmlentities($feed->title) . '
' . 'Last Updated ' . date_time($feed->updated_on) . ' • ' . 'As of ' . date_time($feed->checked_on) . '
' . hx_get("/feed/?id=$feed->id", 'Edit') . ' • ' . 'Read ' . ($counts['unread'] > 0 ? hx_get("/feed/items?id=$feed->id&unread", 'Unread') : 'Unread') . " ({$counts['unread']}) | " . ($counts['total'] > 0 ? hx_get("/feed/items?id=$feed->id", 'All') : 'All') . " ({$counts['total']}) | " . ($counts['marked'] > 0 ? hx_get("/feed/items?id=$feed->id&bookmarked", 'Bookmarked') : 'Bookmarked') . " ({$counts['marked']}) • " . "id hx-delete=/feed/?id=$feed->id " . ' hx-confirm="Are you sure you want to delete “' . htmlspecialchars($feed->title) . '”? This will remove the feed and all its items, including unread and bookmarked.">Delete' . '
'; }); echo '

'; page_foot();