Add ratings everywhere

This commit is contained in:
Sébastien Lucas 2012-12-04 13:13:58 +01:00
parent 8838f15034
commit edb11854af
1 changed files with 36 additions and 10 deletions

View File

@ -16,13 +16,33 @@ class Book extends Base {
const ALL_BOOKS_UUID = "urn:uuid";
const ALL_BOOKS_ID = "calibre:books";
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_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";
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";
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";
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 ?";
const SQL_BOOKS_BY_FIRST_LETTER = "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 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 $title;
@ -54,6 +74,7 @@ class Book extends Base {
$this->comment = $line->comment;
$this->uuid = $line->uuid;
$this->hasCover = $line->has_cover;
$this->rating = $line->rating;
}
public function getEntryId () {
@ -308,7 +329,10 @@ class Book extends Base {
public static function getBookById($bookId) {
$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 = ?');
$result->execute (array ($bookId));
while ($post = $result->fetchObject ())
@ -321,7 +345,10 @@ where books.id = ?');
public static function getBookByDataId($dataId) {
$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 = ?');
$result->execute (array ($dataId));
while ($post = $result->fetchObject ())
@ -369,7 +396,7 @@ order by substr (upper (sort), 1, 1)");
public static function getAllRecentBooks() {
global $config;
$result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . ", ratings.rating
$result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . "
from books
left outer join comments on comments.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 ())
{
$book = new Book ($post);
$book->rating = $post->rating;
array_push ($entryArray, $book->getEntry ());
}
return $entryArray;