Add Custom columns through config. Only tested in HTML catalog for now
re #32
This commit is contained in:
parent
a96888c76a
commit
f4675dec52
48
base.php
48
base.php
|
@ -137,12 +137,13 @@ class Entry
|
||||||
private static $updated = NULL;
|
private static $updated = NULL;
|
||||||
|
|
||||||
public static $icons = array(
|
public static $icons = array(
|
||||||
Author::ALL_AUTHORS_ID => 'images/author.png',
|
Author::ALL_AUTHORS_ID => 'images/author.png',
|
||||||
Serie::ALL_SERIES_ID => 'images/serie.png',
|
Serie::ALL_SERIES_ID => 'images/serie.png',
|
||||||
Book::ALL_RECENT_BOOKS_ID => 'images/recent.png',
|
Book::ALL_RECENT_BOOKS_ID => 'images/recent.png',
|
||||||
Tag::ALL_TAGS_ID => 'images/tag.png',
|
Tag::ALL_TAGS_ID => 'images/tag.png',
|
||||||
"calibre:books$" => 'images/allbook.png',
|
CustomColumn::ALL_CUSTOMS_ID => 'images/tag.png',
|
||||||
"calibre:books:letter" => 'images/allbook.png'
|
"calibre:books$" => 'images/allbook.png',
|
||||||
|
"calibre:books:letter" => 'images/allbook.png'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function getUpdatedTime () {
|
public function getUpdatedTime () {
|
||||||
|
@ -228,6 +229,10 @@ class Page
|
||||||
return new PageAllTags ($id, $query, $n);
|
return new PageAllTags ($id, $query, $n);
|
||||||
case Base::PAGE_TAG_DETAIL :
|
case Base::PAGE_TAG_DETAIL :
|
||||||
return new PageTagDetail ($id, $query, $n);
|
return new PageTagDetail ($id, $query, $n);
|
||||||
|
case Base::PAGE_ALL_CUSTOMS :
|
||||||
|
return new PageAllCustoms ($id, $query, $n);
|
||||||
|
case Base::PAGE_CUSTOM_DETAIL :
|
||||||
|
return new PageCustomDetail ($id, $query, $n);
|
||||||
case Base::PAGE_ALL_SERIES :
|
case Base::PAGE_ALL_SERIES :
|
||||||
return new PageAllSeries ($id, $query, $n);
|
return new PageAllSeries ($id, $query, $n);
|
||||||
case Base::PAGE_ALL_BOOKS :
|
case Base::PAGE_ALL_BOOKS :
|
||||||
|
@ -266,6 +271,12 @@ class Page
|
||||||
array_push ($this->entryArray, Author::getCount());
|
array_push ($this->entryArray, Author::getCount());
|
||||||
array_push ($this->entryArray, Serie::getCount());
|
array_push ($this->entryArray, Serie::getCount());
|
||||||
array_push ($this->entryArray, Tag::getCount());
|
array_push ($this->entryArray, Tag::getCount());
|
||||||
|
foreach ($config['cops_calibre_custom_column'] as $lookup) {
|
||||||
|
$customId = CustomColumn::getCustomId ($lookup);
|
||||||
|
if (!is_null ($customId)) {
|
||||||
|
array_push ($this->entryArray, CustomColumn::getCount($customId));
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +375,29 @@ class PageAllTags extends Page
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PageCustomDetail extends Page
|
||||||
|
{
|
||||||
|
public function InitializeContent ()
|
||||||
|
{
|
||||||
|
$customId = getURLParam ("custom", NULL);
|
||||||
|
$custom = CustomColumn::getCustomById ($customId, $this->idGet);
|
||||||
|
$this->idPage = $custom->getEntryId ();
|
||||||
|
$this->title = $custom->name;
|
||||||
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByCustom ($customId, $this->idGet, $this->n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PageAllCustoms extends Page
|
||||||
|
{
|
||||||
|
public function InitializeContent ()
|
||||||
|
{
|
||||||
|
$customId = getURLParam ("custom", NULL);
|
||||||
|
$this->title = CustomColumn::getAllTitle ($customId);
|
||||||
|
$this->entryArray = CustomColumn::getAllCustoms($customId);
|
||||||
|
$this->idPage = CustomColumn::getAllCustomsId ($customId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PageTagDetail extends Page
|
class PageTagDetail extends Page
|
||||||
{
|
{
|
||||||
public function InitializeContent ()
|
public function InitializeContent ()
|
||||||
|
@ -465,6 +499,8 @@ abstract class Base
|
||||||
const PAGE_ALL_TAGS = "11";
|
const PAGE_ALL_TAGS = "11";
|
||||||
const PAGE_TAG_DETAIL = "12";
|
const PAGE_TAG_DETAIL = "12";
|
||||||
const PAGE_BOOK_DETAIL = "13";
|
const PAGE_BOOK_DETAIL = "13";
|
||||||
|
const PAGE_ALL_CUSTOMS = "14";
|
||||||
|
const PAGE_CUSTOM_DETAIL = "15";
|
||||||
|
|
||||||
const COMPATIBILITY_XML_ALDIKO = "aldiko";
|
const COMPATIBILITY_XML_ALDIKO = "aldiko";
|
||||||
|
|
||||||
|
|
9
book.php
9
book.php
|
@ -10,6 +10,7 @@ require_once('base.php');
|
||||||
require_once('serie.php');
|
require_once('serie.php');
|
||||||
require_once('author.php');
|
require_once('author.php');
|
||||||
require_once('tag.php');
|
require_once('tag.php');
|
||||||
|
require_once ("customcolumn.php");
|
||||||
require_once('data.php');
|
require_once('data.php');
|
||||||
require_once('php-epub-meta/epub.php');
|
require_once('php-epub-meta/epub.php');
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ define ('SQL_BOOKS_BY_SERIE', "select {0} from books_series_link, books " . SQL_
|
||||||
where books_series_link.book = books.id and series = ? {1} order by series_index");
|
where books_series_link.book = books.id and series = ? {1} order by series_index");
|
||||||
define ('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . "
|
define ('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . "
|
||||||
where books_tags_link.book = books.id and tag = ? {1} order by sort");
|
where books_tags_link.book = books.id and tag = ? {1} order by sort");
|
||||||
|
define ('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . "
|
||||||
|
where {2}.book = books.id and {2}.{3} = ? {1} order by sort");
|
||||||
define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . "
|
define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . "
|
||||||
where (exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?) {1}");
|
where (exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?) {1}");
|
||||||
define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . "
|
define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . "
|
||||||
|
@ -41,6 +44,7 @@ class Book extends Base {
|
||||||
const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR;
|
const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR;
|
||||||
const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE;
|
const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE;
|
||||||
const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG;
|
const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG;
|
||||||
|
const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM;
|
||||||
const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY;
|
const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY;
|
||||||
const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT;
|
const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT;
|
||||||
|
|
||||||
|
@ -398,6 +402,11 @@ class Book extends Base {
|
||||||
return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
|
return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getBooksByCustom($customId, $id, $n) {
|
||||||
|
$query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
|
||||||
|
return self::getEntryArray ($query, array ($id), $n);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getBookById($bookId) {
|
public static function getBookById($bookId) {
|
||||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||||
from books ' . self::SQL_BOOKS_LEFT_JOIN . '
|
from books ' . self::SQL_BOOKS_LEFT_JOIN . '
|
||||||
|
|
|
@ -140,4 +140,14 @@
|
||||||
* Filter on tags to book list
|
* Filter on tags to book list
|
||||||
*/
|
*/
|
||||||
$config['cops_books_filter'] = array ("Non lus" => "!Read", "lus" => "Read");
|
$config['cops_books_filter'] = array ("Non lus" => "!Read", "lus" => "Read");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Custom Columns to add as an array containing the lookup names
|
||||||
|
* configured in Calibre
|
||||||
|
*
|
||||||
|
* For example : array ("genre", "mycolumn");
|
||||||
|
*
|
||||||
|
* Note that for now only the first, second and forth type of custom columns are supported
|
||||||
|
*/
|
||||||
|
$config['cops_calibre_custom_column'] = array ("genre", "type2");
|
||||||
?>
|
?>
|
|
@ -55,6 +55,15 @@ class CustomColumn extends Base {
|
||||||
$post = $result->fetchObject ();
|
$post = $result->fetchObject ();
|
||||||
return $post->name;
|
return $post->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getCustomId ($lookup) {
|
||||||
|
$result = parent::getDb ()->prepare('select id from custom_columns where label = ?');
|
||||||
|
$result->execute (array ($lookup));
|
||||||
|
if ($post = $result->fetchObject ()) {
|
||||||
|
return $post->id;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getCount($customId) {
|
public static function getCount($customId) {
|
||||||
$nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn();
|
$nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
require_once ("author.php");
|
require_once ("author.php");
|
||||||
require_once ("serie.php");
|
require_once ("serie.php");
|
||||||
require_once ("tag.php");
|
require_once ("tag.php");
|
||||||
|
require_once ("customcolumn.php");
|
||||||
require_once ("book.php");
|
require_once ("book.php");
|
||||||
|
|
||||||
header ("Content-Type:application/xhtml+xml");
|
header ("Content-Type:application/xhtml+xml");
|
||||||
|
|
Loading…
Reference in a new issue