WIP on document conversion
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
<?php
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use SQLite3;
|
||||
use SQLite3Result;
|
||||
use SQLite3Stmt;
|
||||
|
||||
/**
|
||||
* A list of items to be displayed
|
||||
@@ -39,7 +44,8 @@ class ItemList {
|
||||
* @param string $itemType The type of item being displayed (unread, bookmark, etc.)
|
||||
* @param string $returnURL The URL to which the item page should return once the item has been viewed
|
||||
*/
|
||||
private function __construct(SQLite3 $db, SQLite3Stmt $query, public string $itemType, public string $returnURL = '') {
|
||||
private function __construct(SQLite3 $db, SQLite3Stmt $query, public string $itemType, public string $returnURL = '')
|
||||
{
|
||||
$result = $query->execute();
|
||||
if (!$result) {
|
||||
$this->error = Data::error($db)['error'];
|
||||
@@ -56,7 +62,8 @@ class ItemList {
|
||||
* @param array $parameters Parameters to be added to the query (key index 0, value index 1; optional)
|
||||
* @return SQLite3Stmt The query, ready to be executed
|
||||
*/
|
||||
private static function makeQuery(SQLite3 $db, array $criteria, array $parameters = []): SQLite3Stmt {
|
||||
private static function makeQuery(SQLite3 $db, array $criteria, array $parameters = []): SQLite3Stmt
|
||||
{
|
||||
$where = empty($criteria) ? '' : 'AND ' . implode(' AND ', $criteria);
|
||||
$sql = <<<SQL
|
||||
SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
|
||||
@@ -77,7 +84,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list with all bookmarked items
|
||||
*/
|
||||
public static function allBookmarked(SQLite3 $db): static {
|
||||
public static function allBookmarked(SQLite3 $db): static
|
||||
{
|
||||
$list = new static($db, self::makeQuery($db, ['item.is_bookmarked = 1']), 'Bookmarked', '/?bookmarked');
|
||||
$list->linkFeed = true;
|
||||
return $list;
|
||||
@@ -89,7 +97,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list with all unread items
|
||||
*/
|
||||
public static function allUnread(SQLite3 $db): static {
|
||||
public static function allUnread(SQLite3 $db): static
|
||||
{
|
||||
$list = new static($db, self::makeQuery($db, ['item.is_read = 0']), 'Unread');
|
||||
$list->linkFeed = true;
|
||||
return $list;
|
||||
@@ -102,7 +111,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list with all items for the given feed
|
||||
*/
|
||||
public static function allForFeed(int $feedId, SQLite3 $db): static {
|
||||
public static function allForFeed(int $feedId, SQLite3 $db): static
|
||||
{
|
||||
$list = new static($db, self::makeQuery($db, ['feed.id = :feed'], [[':feed', $feedId]]), '',
|
||||
"/feed/items?id=$feedId");
|
||||
$list->showIndicators = true;
|
||||
@@ -116,7 +126,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list with unread items for the given feed
|
||||
*/
|
||||
public static function unreadForFeed(int $feedId, SQLite3 $db): static {
|
||||
public static function unreadForFeed(int $feedId, SQLite3 $db): static
|
||||
{
|
||||
return new static($db, self::makeQuery($db, ['feed.id = :feed', 'item.is_read = 0'], [[':feed', $feedId]]),
|
||||
'Unread', "/feed/items?id=$feedId&unread");
|
||||
}
|
||||
@@ -128,7 +139,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list with bookmarked items for the given feed
|
||||
*/
|
||||
public static function bookmarkedForFeed(int $feedId, SQLite3 $db): static {
|
||||
public static function bookmarkedForFeed(int $feedId, SQLite3 $db): static
|
||||
{
|
||||
return new static($db,
|
||||
self::makeQuery($db, ['feed.id = :feed', 'item.is_bookmarked = 1'], [[':feed', $feedId]]), 'Bookmarked',
|
||||
"/feed/items?id=$feedId&bookmarked");
|
||||
@@ -142,7 +154,8 @@ class ItemList {
|
||||
* @param SQLite3 $db The database connection to use to obtain items
|
||||
* @return static An item list match the given search terms
|
||||
*/
|
||||
public static function matchingSearch(string $search, bool $isBookmarked, SQLite3 $db): static {
|
||||
public static function matchingSearch(string $search, bool $isBookmarked, SQLite3 $db): static
|
||||
{
|
||||
$where = $isBookmarked ? ['item.is_bookmarked = 1'] : [];
|
||||
$where[] = 'item.id IN (SELECT ROWID FROM item_search WHERE content MATCH :search)';
|
||||
$list = new static($db, self::makeQuery($db, $where, [[':search', $search]]),
|
||||
@@ -156,7 +169,8 @@ class ItemList {
|
||||
/**
|
||||
* Render this item list
|
||||
*/
|
||||
public function render(): void {
|
||||
public function render(): void
|
||||
{
|
||||
if ($this->isError()) { ?>
|
||||
<p>Error retrieving list:<br><?=$this->error?><?php
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user