Move list retrieve/render to class (#15)

- array_key_exists -> key_exists
This commit is contained in:
2024-05-25 23:03:39 -04:00
parent c4e85e6734
commit 210377b4da
9 changed files with 215 additions and 126 deletions

View File

@@ -10,60 +10,28 @@ include '../start.php';
$db = Data::getConnection();
Security::verifyUser($db);
if (array_key_exists('refresh', $_GET)) {
if (key_exists('refresh', $_GET)) {
$refreshResult = Feed::refreshAll($db);
if (array_key_exists('ok', $refreshResult)) {
if (key_exists('ok', $refreshResult)) {
add_info('All feeds refreshed successfully');
} else {
add_error(nl2br($refreshResult['error']));
}
}
if (key_exists('bookmarked', $_GET)) {
$itemCriteria = 'item.is_bookmarked = 1';
$returnURL = '&from=' . urlencode('/?bookmarked');
$type = 'Bookmarked';
} else {
$itemCriteria = 'item.is_read = 0';
$returnURL = '';
$type = 'Unread';
$list = match (true) {
key_exists('bookmarked', $_GET) => ItemList::allBookmarked($db),
default => ItemList::allUnread($db)
};
$title = "Your $list->itemType Items";
page_head($title);
echo "<h1>$title";
if ($list->itemType == 'Unread') {
echo ' &nbsp; ' . hx_get('/?refresh', '(Refresh All Feeds)', 'class=refresh hx-indicator="closest h1"')
. '<span class=loading>Refreshing&hellip;</span>';
}
$title = "Your $type Items";
$query = $db->prepare(<<<SQL
SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
feed.title AS feed_title
FROM item
INNER JOIN feed ON feed.id = item.feed_id
WHERE feed.user_id = :userId
AND $itemCriteria
ORDER BY coalesce(item.updated_on, item.published_on) DESC
SQL);
$query->bindValue(':userId', $_SESSION[Key::USER_ID]);
$result = $query->execute();
$item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false;
page_head($title); ?>
<h1>
<?=$title?><?php
if ($type == 'Unread'): ?> &nbsp;
<?=hx_get('/?refresh', '(Refresh All Feeds)', 'class=refresh hx-indicator="closest h1"')?>
<span class=loading>Refreshing&hellip;</span><?php
endif; ?>
</h1>
<article><?php
if ($item) {
while ($item) { ?>
<p><?=hx_get("/item?id={$item['id']}$returnURL", strip_tags($item['item_title']))?><br>
<small><?=date_time($item['as_of'])?> &bull;
<?=hx_get("/feed/items?id={$item['feed_id']}&" . strtolower($type), htmlentities($item['feed_title']))?>
</small><?php
$item = $result->fetchArray(SQLITE3_ASSOC);
}
} else { ?>
<p>There are no <?=strtolower($type)?> items<?php
} ?>
</article><?php
echo '</h1>';
$list->render();
page_foot();
$db->close();