Split out feed parsing from document

WIP - still moving things around...
This commit is contained in:
2024-05-31 16:00:04 -04:00
parent 67747899ac
commit f7f5dba795
12 changed files with 371 additions and 396 deletions

View File

@@ -6,8 +6,11 @@
* This will display a button which will either add or remove a bookmark for a given item.
*/
use BitBadger\Documents\DocumentException;
use BitBadger\Documents\SQLite\Find;
use BitBadger\Documents\SQLite\Patch;
use FeedReaderCentral\Data;
use FeedReaderCentral\Domain\Item;
use FeedReaderCentral\Domain\Table;
use FeedReaderCentral\Key;
use FeedReaderCentral\Security;
@@ -36,21 +39,18 @@ if (key_exists('action', $_GET)) {
$flag = 0;
}
if (isset($flag)) {
Patch::byId(Table::ITEM, $id, ['is_bookmarked' => $flag], $db);
// $update = $db->prepare('UPDATE item SET is_bookmarked = :flag WHERE id = :id');
// $update->bindValue(':id', $id);
// $update->bindValue(':flag', $flag);
// if (!$update->execute()) die(Data::error($db)['error']);
try {
Patch::byId(Table::ITEM, $id, ['is_bookmarked' => $flag], $db);
} catch (DocumentException $ex) {
add_error("$ex");
}
}
}
$bookQuery = $db->prepare('SELECT id, is_bookmarked FROM item WHERE id = :id');
$bookQuery->bindValue(':id', $id);
$bookResult = $bookQuery->execute();
$bookmark = $bookResult ? $bookResult->fetchArray(SQLITE3_ASSOC) : ['id' => $id, 'is_bookmarked' => 0];
if (!$item = Find::byId(Table::ITEM, $id, Item::class)) not_found();
$action = $bookmark['is_bookmarked'] ? 'remove' : 'add';
$icon = $bookmark['is_bookmarked'] ? 'added' : 'add'; ?>
$action = $item->isBookmarked() ? 'remove' : 'add';
$icon = $item->isBookmarked() ? 'added' : 'add'; ?>
<button class="bookmark <?=$action?>" type=button role=button hx-patch="/bookmark?id=<?=$id?>&action=<?=$action?>"
hx-target=this hx-swap=outerHTML hx-push-url=false title="<?=init_cap($action)?> Bookmark">
<img src=/assets/bookmark-<?=$icon?>.png alt="<?=$action?> bookmark">

View File

@@ -15,7 +15,7 @@ include '../../start.php';
$db = Data::getConnection();
Security::verifyUser($db);
if (!($feed = Feed::retrieveById($_GET['id'], $db))) not_found();
if (!($feed = Feed::retrieveById($_GET['id']))) not_found();
$list = match (true) {
key_exists('unread', $_GET) => ItemList::unreadForFeed($feed->id, $db),

View File

@@ -1,6 +1,7 @@
<?php
include '../../start.php';
use FeedReaderCentral\Data;
use FeedReaderCentral\Key;
use FeedReaderCentral\Security;