First cut of item-with-feed and list impl
- Add strict types to all files - Convert many queries to document commands
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
<?php
|
||||
namespace FeedReaderCentral;
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use BitBadger\Documents\DocumentException;
|
||||
use BitBadger\Documents\Field;
|
||||
use BitBadger\Documents\JsonMapper;
|
||||
use BitBadger\Documents\Query;
|
||||
use BitBadger\Documents\SQLite\Configuration;
|
||||
use BitBadger\Documents\SQLite\Custom;
|
||||
use BitBadger\Documents\SQLite\Parameters;
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
/**
|
||||
* An item from a feed
|
||||
@@ -71,27 +64,4 @@ class Item
|
||||
updated_on: $item->updatedOn,
|
||||
content: $item->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item by its ID, ensuring that its owner matches the current user
|
||||
*
|
||||
* @param int $id The ID of the item to retrieve
|
||||
* @return Item|false The item if it exists and is owned by the current user, false if not
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function retrieveByIdForUser(int $id): Item|false
|
||||
{
|
||||
$idField = Field::EQ(Configuration::idField(), $id, '@id');
|
||||
$idField->qualifier = Table::ITEM;
|
||||
$userField = Field::EQ('user_id', $_SESSION[Key::USER_ID], '@user');
|
||||
$userField->qualifier = Table::FEED;
|
||||
$fields = [$idField, $userField];
|
||||
|
||||
$where = Query::whereByFields($fields);
|
||||
$item = Table::ITEM;
|
||||
$feed = Table::FEED;
|
||||
return Custom::single(
|
||||
"SELECT $item.data FROM $item INNER JOIN $feed ON $item.data->>'feed_id' = $feed.data->>'id' WHERE $where",
|
||||
Parameters::addFields($fields, []), new JsonMapper(Item::class));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user