Add ratings everywhere
This commit is contained in:
parent
8838f15034
commit
edb11854af
46
book.php
46
book.php
|
@ -16,13 +16,33 @@ class Book extends Base {
|
||||||
const ALL_BOOKS_UUID = "urn:uuid";
|
const ALL_BOOKS_UUID = "urn:uuid";
|
||||||
const ALL_BOOKS_ID = "calibre:books";
|
const ALL_BOOKS_ID = "calibre:books";
|
||||||
const ALL_RECENT_BOOKS_ID = "calibre:recentbooks";
|
const ALL_RECENT_BOOKS_ID = "calibre:recentbooks";
|
||||||
const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover";
|
const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating";
|
||||||
|
|
||||||
const SQL_BOOKS_BY_FIRST_LETTER = "select {0} from books left outer join comments on book = books.id where upper (books.sort) like ?";
|
const SQL_BOOKS_BY_FIRST_LETTER = "select {0} from books
|
||||||
const SQL_BOOKS_BY_AUTHOR = "select {0} from books_authors_link, books left outer join comments on comments.book = books.id where books_authors_link.book = books.id and author = ? order by pubdate";
|
left outer join comments on comments.book = books.id
|
||||||
const SQL_BOOKS_BY_SERIE = "select {0} from books_series_link, books left outer join comments on comments.book = books.id where books_series_link.book = books.id and series = ? order by series_index";
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
const SQL_BOOKS_BY_TAG = "select {0} from books_tags_link, books left outer join comments on comments.book = books.id where books_tags_link.book = books.id and tag = ? order by sort";
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
const SQL_BOOKS_QUERY = "select {0} from books left outer join comments on book = books.id where exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?";
|
where upper (books.sort) like ?";
|
||||||
|
const SQL_BOOKS_BY_AUTHOR = "select {0} from books_authors_link, books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
|
where books_authors_link.book = books.id and author = ? order by pubdate";
|
||||||
|
const SQL_BOOKS_BY_SERIE = "select {0} from books_series_link, books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
|
where books_series_link.book = books.id and series = ? order by series_index";
|
||||||
|
const SQL_BOOKS_BY_TAG = "select {0} from books_tags_link, books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
|
where books_tags_link.book = books.id and tag = ? order by sort";
|
||||||
|
const SQL_BOOKS_QUERY = "select {0} from books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
|
where exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?";
|
||||||
|
|
||||||
public $id;
|
public $id;
|
||||||
public $title;
|
public $title;
|
||||||
|
@ -54,6 +74,7 @@ class Book extends Base {
|
||||||
$this->comment = $line->comment;
|
$this->comment = $line->comment;
|
||||||
$this->uuid = $line->uuid;
|
$this->uuid = $line->uuid;
|
||||||
$this->hasCover = $line->has_cover;
|
$this->hasCover = $line->has_cover;
|
||||||
|
$this->rating = $line->rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEntryId () {
|
public function getEntryId () {
|
||||||
|
@ -308,7 +329,10 @@ class Book extends Base {
|
||||||
|
|
||||||
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 left outer join comments on book = books.id
|
from books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
where books.id = ?');
|
where books.id = ?');
|
||||||
$result->execute (array ($bookId));
|
$result->execute (array ($bookId));
|
||||||
while ($post = $result->fetchObject ())
|
while ($post = $result->fetchObject ())
|
||||||
|
@ -321,7 +345,10 @@ where books.id = ?');
|
||||||
|
|
||||||
public static function getBookByDataId($dataId) {
|
public static function getBookByDataId($dataId) {
|
||||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||||
from data, books left outer join comments on comments.book = books.id
|
from data, books
|
||||||
|
left outer join comments on comments.book = books.id
|
||||||
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
left outer join ratings on books_ratings_link.rating = ratings.id
|
||||||
where data.book = books.id and data.id = ?');
|
where data.book = books.id and data.id = ?');
|
||||||
$result->execute (array ($dataId));
|
$result->execute (array ($dataId));
|
||||||
while ($post = $result->fetchObject ())
|
while ($post = $result->fetchObject ())
|
||||||
|
@ -369,7 +396,7 @@ order by substr (upper (sort), 1, 1)");
|
||||||
|
|
||||||
public static function getAllRecentBooks() {
|
public static function getAllRecentBooks() {
|
||||||
global $config;
|
global $config;
|
||||||
$result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . ", ratings.rating
|
$result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . "
|
||||||
from books
|
from books
|
||||||
left outer join comments on comments.book = books.id
|
left outer join comments on comments.book = books.id
|
||||||
left outer join books_ratings_link on books_ratings_link.book = books.id
|
left outer join books_ratings_link on books_ratings_link.book = books.id
|
||||||
|
@ -379,7 +406,6 @@ order by timestamp desc limit " . $config['cops_recentbooks_limit']);
|
||||||
while ($post = $result->fetchObject ())
|
while ($post = $result->fetchObject ())
|
||||||
{
|
{
|
||||||
$book = new Book ($post);
|
$book = new Book ($post);
|
||||||
$book->rating = $post->rating;
|
|
||||||
array_push ($entryArray, $book->getEntry ());
|
array_push ($entryArray, $book->getEntry ());
|
||||||
}
|
}
|
||||||
return $entryArray;
|
return $entryArray;
|
||||||
|
|
Loading…
Reference in a new issue