beta4 changes (#26)
These changes are mostly in underlying libraries; however, this now uses the [inspired by F#](https://git.bitbadger.solutions/bit-badger/inspired-by-fsharp) library to handle the feed parsing pipeline and optional return values Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Item View Page
|
||||
*
|
||||
* Retrieves and displays an item from a feed belonging to the current user
|
||||
*
|
||||
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use BitBadger\PDODocument\{Delete, DocumentException, Patch};
|
||||
use FeedReaderCentral\{ItemWithFeed, Table};
|
||||
|
||||
@@ -16,35 +20,38 @@ FeedReaderCentral\Security::verifyUser();
|
||||
$id = match (true) {
|
||||
key_exists('id', $_POST) => (int)$_POST['id'],
|
||||
key_exists('id', $_GET) => (int)$_GET['id'],
|
||||
default => -1
|
||||
default => -1,
|
||||
};
|
||||
$from = match ($_SERVER['REQUEST_METHOD']) {
|
||||
'POST' => $_POST['from'],
|
||||
default => $_GET['from'] ?? '/',
|
||||
};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
try {
|
||||
// "Keep as New" button sends a POST request to reset the is_read flag before going back to the item list
|
||||
if (ItemWithFeed::existsById($id)) {
|
||||
Patch::byId(Table::ITEM, $id, ['is_read' => 0]);
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case 'POST':
|
||||
try {
|
||||
// "Keep as New" button sends a POST request to reset the is_read flag before going back to the item list
|
||||
if (ItemWithFeed::existsById($id)) {
|
||||
Patch::byId(Table::Item, $id, ['is_read' => 0]);
|
||||
}
|
||||
frc_redirect($from);
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
frc_redirect($_POST['from']);
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
try {
|
||||
if (ItemWithFeed::existsById($id)) Delete::byId(Table::Item, $id);
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
frc_redirect($from);
|
||||
}
|
||||
|
||||
$from = $_GET['from'] ?? '/';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
||||
try {
|
||||
if (ItemWithFeed::existsById($id)) Delete::byId(Table::ITEM, $id);
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
frc_redirect($from);
|
||||
}
|
||||
|
||||
if (!$item = ItemWithFeed::retrieveById($id)) not_found();
|
||||
$item = ItemWithFeed::retrieveById($id)->getOrCall(not_found(...));
|
||||
try {
|
||||
Patch::byId(Table::ITEM, $id, ['is_read' => 1]);
|
||||
Patch::byId(Table::Item, $id, ['is_read' => 1]);
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user