From 8838f150342d99c55b8407ce0daf8ce28fc8f205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 4 Dec 2012 10:58:39 +0100 Subject: [PATCH] Add ratings only in recent addition for now. --- book.php | 23 +++++++++++++++++++++-- index.php | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/book.php b/book.php index 221343c..1090352 100644 --- a/book.php +++ b/book.php @@ -34,6 +34,7 @@ class Book extends Base { public $relativePath; public $seriesIndex; public $comment; + public $rating; public $datas = NULL; public $authors = NULL; public $serie = NULL; @@ -159,6 +160,20 @@ class Book extends Base { return $tagList; } + public function getRating () { + if (is_null ($this->rating) || $this->rating == 0) { + return ""; + } + $retour = ""; + for ($i = 0; $i < $this->rating / 2; $i++) { + $retour .= "★"; + } + for ($i = 0; $i < 5 - $this->rating / 2; $i++) { + $retour .= "☆"; + } + return $retour; + } + public function getComment ($withSerie = true) { $addition = ""; $se = $this->getSerie (); @@ -354,13 +369,17 @@ order by substr (upper (sort), 1, 1)"); public static function getAllRecentBooks() { global $config; - $result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . " -from books left outer join comments on book = books.id + $result = parent::getDb ()->query("select " . self::BOOK_COLUMNS . ", ratings.rating +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 order by timestamp desc limit " . $config['cops_recentbooks_limit']); $entryArray = array(); while ($post = $result->fetchObject ()) { $book = new Book ($post); + $book->rating = $post->rating; array_push ($entryArray, $book->getEntry ()); } return $entryArray; diff --git a/index.php b/index.php index 3789825..44c00a6 100644 --- a/index.php +++ b/index.php @@ -225,7 +225,7 @@
-
title) ?> (book->pubdate) ?>)
+
title) ?> (book->pubdate) ?>) book->getRating () ?>
book->getAuthorsName ()) ?>
book->getTagsName ()) ?>