Browse Source

add channel sort order

main
yggverse 7 months ago
parent
commit
63ec2df6b0
  1. 2
      config/example.json
  2. 27
      src/Model/Database.php

2
config/example.json

@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
{
"source":"https://www.omglinux.com/feed",
"alias":"omglinux.gmi",
"order":1,
"enabled":true,
"item":
{
@ -95,6 +96,7 @@ @@ -95,6 +96,7 @@
{
"source":"https://omgubuntu.co.uk/feed",
"alias":"omgubuntu.gmi",
"order":2,
"enabled":false,
"item":
{

27
src/Model/Database.php

@ -13,6 +13,7 @@ class Database @@ -13,6 +13,7 @@ class Database
?string $username = null,
?string $password = null
) {
// Init connection
$this->_database = new \PDO(
sprintf(
'sqlite:%s',
@ -40,11 +41,13 @@ class Database @@ -40,11 +41,13 @@ class Database
\PDO::FETCH_OBJ
);
// Init structure
$this->_database->query('
CREATE TABLE IF NOT EXISTS "channel"
(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"time" INTEGER NOT NULL,
"order" INTEGER NOT NULL,
"alias" VARCHAR NOT NULL,
"source" TEXT NOT NULL,
"link" TEXT,
@ -90,7 +93,7 @@ class Database @@ -90,7 +93,7 @@ class Database
public function getChannels(): ?array
{
$query = $this->_database->query(
'SELECT * FROM `channel`'
'SELECT * FROM `channel` ORDER BY `order` ASC, `title` ASC, `id` ASC'
);
if ($result = $query->fetchAll())
@ -142,17 +145,18 @@ class Database @@ -142,17 +145,18 @@ class Database
}
public function addChannel(
string $alias,
string $source,
?string $link,
?string $title,
?string $description,
?int $time = null
string $alias,
string $source,
?string $link = null,
?string $title = null,
?string $description = null,
?int $time = null,
?int $order = null
): ?int
{
$query = $this->_database->prepare(
'INSERT INTO `channel` (`alias`, `source`, `link`, `title`, `description`, `time`)
VALUES (:alias, :source, :link, :title, :description, :time)'
'INSERT INTO `channel` (`alias`, `source`, `link`, `title`, `description`, `time`, `order`)
VALUES (:alias, :source, :link, :title, :description, :time, :order)'
);
$query->execute(
@ -162,7 +166,8 @@ class Database @@ -162,7 +166,8 @@ class Database
':link' => $link,
':title' => $title,
':description' => $description,
':time' => $time ? $time : time()
':time' => $time ? $time : time(),
':order' => $order ? $order : 0
]
);
@ -199,7 +204,7 @@ class Database @@ -199,7 +204,7 @@ class Database
{
$query = $this->_database->query(
sprintf(
'SELECT * FROM `channelItem` ORDER BY `time` DESC LIMIT %d,%d',
'SELECT * FROM `channelItem` ORDER BY `pubTime` DESC, `time` DESC, `id` DESC LIMIT %d,%d',
$start,
$limit
)

Loading…
Cancel
Save