* @license MIT */ declare(strict_types=1); use BitBadger\InspiredByFSharp\Option; use BitBadger\PDODocument\{DocumentException, Patch}; use FeedReaderCentral\{ItemWithFeed, Table}; include '../start.php'; FeedReaderCentral\Security::verifyUser(); $id = key_exists('id', $_GET) ? (int)$_GET['id'] : -1; $item = Option::getOrCall(not_found(...), ItemWithFeed::retrieveById($id)); if (key_exists('action', $_GET)) { Option::iter(function (int $flag) use ($id, &$item) { try { Patch::byId(Table::Item, $id, ['is_bookmarked' => $flag]); $item->is_bookmarked = $flag; } catch (DocumentException $ex) { add_error("$ex"); } }, match ($_GET['action']) { 'add' => Option::Some(1), 'remove' => Option::Some(0), default => Option::None(), }); } $action = $item->isBookmarked() ? 'remove' : 'add'; $icon = $item->isBookmarked() ? 'added' : 'add'; ?>