diff --git a/base.php b/base.php index 8ff4804..1f942e0 100644 --- a/base.php +++ b/base.php @@ -137,12 +137,13 @@ class Entry private static $updated = NULL; public static $icons = array( - Author::ALL_AUTHORS_ID => 'images/author.png', - Serie::ALL_SERIES_ID => 'images/serie.png', - Book::ALL_RECENT_BOOKS_ID => 'images/recent.png', - Tag::ALL_TAGS_ID => 'images/tag.png', - "calibre:books$" => 'images/allbook.png', - "calibre:books:letter" => 'images/allbook.png' + Author::ALL_AUTHORS_ID => 'images/author.png', + Serie::ALL_SERIES_ID => 'images/serie.png', + Book::ALL_RECENT_BOOKS_ID => 'images/recent.png', + Tag::ALL_TAGS_ID => 'images/tag.png', + CustomColumn::ALL_CUSTOMS_ID => 'images/tag.png', + "calibre:books$" => 'images/allbook.png', + "calibre:books:letter" => 'images/allbook.png' ); public function getUpdatedTime () { @@ -228,6 +229,10 @@ class Page return new PageAllTags ($id, $query, $n); case Base::PAGE_TAG_DETAIL : 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 : return new PageAllSeries ($id, $query, $n); case Base::PAGE_ALL_BOOKS : @@ -266,6 +271,12 @@ class Page array_push ($this->entryArray, Author::getCount()); array_push ($this->entryArray, Serie::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()); } @@ -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 { public function InitializeContent () @@ -465,6 +499,8 @@ abstract class Base const PAGE_ALL_TAGS = "11"; const PAGE_TAG_DETAIL = "12"; const PAGE_BOOK_DETAIL = "13"; + const PAGE_ALL_CUSTOMS = "14"; + const PAGE_CUSTOM_DETAIL = "15"; const COMPATIBILITY_XML_ALDIKO = "aldiko"; diff --git a/book.php b/book.php index 7cb2478..fd62e12 100644 --- a/book.php +++ b/book.php @@ -10,6 +10,7 @@ require_once('base.php'); require_once('serie.php'); require_once('author.php'); require_once('tag.php'); +require_once ("customcolumn.php"); require_once('data.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"); 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"); +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 . " 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 . " @@ -41,6 +44,7 @@ class Book extends Base { const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR; const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE; 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_RECENT = SQL_BOOKS_RECENT; @@ -398,6 +402,11 @@ class Book extends Base { 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) { $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' from books ' . self::SQL_BOOKS_LEFT_JOIN . ' diff --git a/config_default.php b/config_default.php index 409b68b..247fed9 100644 --- a/config_default.php +++ b/config_default.php @@ -140,4 +140,14 @@ * Filter on tags to book list */ $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"); ?> \ No newline at end of file diff --git a/customcolumn.php b/customcolumn.php index 6d59768..4218040 100644 --- a/customcolumn.php +++ b/customcolumn.php @@ -55,6 +55,15 @@ class CustomColumn extends Base { $post = $result->fetchObject (); 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) { $nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn(); diff --git a/index.php b/index.php index 86217f5..01cb8cd 100644 --- a/index.php +++ b/index.php @@ -12,6 +12,7 @@ require_once ("author.php"); require_once ("serie.php"); require_once ("tag.php"); + require_once ("customcolumn.php"); require_once ("book.php"); header ("Content-Type:application/xhtml+xml");