From 4b7743397b0d892e39a81cdc0d9f83da6b00759d Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 27 Feb 2014 00:33:40 +0100 Subject: [PATCH] raw sketch of ratings category --- base.php | 32 +++++++++++++++++++++++++++ book.php | 8 +++++++ index.php | 1 + rating.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 rating.php diff --git a/base.php b/base.php index 61f877d..d814b97 100644 --- a/base.php +++ b/base.php @@ -438,6 +438,10 @@ class Page return new PageAllCustoms ($id, $query, $n); case Base::PAGE_CUSTOM_DETAIL : return new PageCustomDetail ($id, $query, $n); + case Base::PAGE_ALL_RATINGS : + return new PageAllRating ($id, $query, $n); + case Base::PAGE_RATING_DETAIL : + return new PageRatingDetail ($id, $query, $n); case Base::PAGE_ALL_SERIES : return new PageAllSeries ($id, $query, $n); case Base::PAGE_ALL_BOOKS : @@ -510,6 +514,10 @@ class Page $tags = Tag::getCount(); if (!is_null ($tags)) array_push ($this->entryArray, $tags); } + if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) { + $rating = Rating::getCount(); + if (!is_null ($rating)) array_push ($this->entryArray, $rating); + } if (!in_array ("language", getCurrentOption ('ignored_categories'))) { $languages = Language::getCount(); if (!is_null ($languages)) array_push ($this->entryArray, $languages); @@ -707,6 +715,27 @@ class PageSerieDetail extends Page } } +class PageAllRating extends Page +{ + public function InitializeContent () + { + $this->title = localize("rating.title"); + $this->entryArray = Rating::getAllRatings(); + $this->idPage = Rating::ALL_RATING_ID; + } +} + +class PageRatingDetail extends Page +{ + public function InitializeContent () + { + $rating = Rating::getRatingById ($this->idGet); + $this->idPage = $rating->getEntryId (); + $this->title = $rating->name; + list ($this->entryArray, $this->totalNumber) = Book::getBooksByRating ($this->idGet, $this->n); + } +} + class PageAllBooks extends Page { public function InitializeContent () @@ -750,6 +779,7 @@ class PageRecentBooks extends Page class PageQueryResult extends Page { const SCOPE_TAG = "tag"; + const SCOPE_RATING = "rating"; const SCOPE_SERIES = "series"; const SCOPE_AUTHOR = "author"; const SCOPE_BOOK = "book"; @@ -1029,6 +1059,8 @@ abstract class Base const PAGE_CUSTOMIZE = "19"; const PAGE_ALL_PUBLISHERS = "20"; const PAGE_PUBLISHER_DETAIL = "21"; + const PAGE_ALL_RATINGS = "22"; + const PAGE_RATING_DETAIL = "23"; const COMPATIBILITY_XML_ALDIKO = "aldiko"; diff --git a/book.php b/book.php index 46cad12..bde90c1 100644 --- a/book.php +++ b/book.php @@ -9,6 +9,7 @@ require_once('base.php'); require_once('serie.php'); require_once('author.php'); +require_once('rating.php'); require_once('publisher.php'); require_once('tag.php'); require_once('language.php'); @@ -44,6 +45,8 @@ define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " title like ?) {1} order by books.sort"); define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " where 1=1 {1} order by timestamp desc limit "); +define ('SQL_BOOKS_BY_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " + where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort"); class Book extends Base { const ALL_BOOKS_UUID = "urn:uuid"; @@ -62,6 +65,7 @@ class Book extends Base { const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM; const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY; const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; + const SQL_BOOKS_BY_RATING = SQL_BOOKS_BY_RATING; const BAD_SEARCH = "QQQQQ"; @@ -447,6 +451,10 @@ class Book extends Base { return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); } + public static function getBooksByRating($ratingId, $n) { + return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); + } + public static function getBooksByPublisher($publisherId, $n) { return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); } diff --git a/index.php b/index.php index b44f385..0dbeb4f 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,7 @@ require_once ("config.php"); require_once ("base.php"); require_once ("author.php"); + require_once ("rating.php"); require_once ("publisher.php"); require_once ("serie.php"); require_once ("tag.php"); diff --git a/rating.php b/rating.php new file mode 100644 index 0000000..074a1d9 --- /dev/null +++ b/rating.php @@ -0,0 +1,65 @@ +id = $pid; + $this->name = $pname; + } + + public function getUri () { + return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; + } + + public function getEntryId () { + return self::ALL_RATING_ID.":".$this->id; + } + + public static function getCount() { + $nAuthors = parent::getDb ()->query('select count(*) from ratings')->fetchColumn(); + $entry = new Entry (localize("rating.title"), self::ALL_RATING_ID, + str_format (localize("ratings", $nAuthors), $nAuthors), "text", + array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS))); + return $entry; + } + + public static function getAllRatings() { + return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); + } + + public static function getEntryArray ($query, $params) { + list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, "", $params, -1); + $entryArray = array(); + while ($post = $result->fetchObject ()) + { + $rating = new Rating ($post->id, $post->rating); + $bewertung=$post->rating/2; + $bewertung.=" Sterne"; + array_push ($entryArray, new Entry ($bewertung, $rating->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", + array ( new LinkNavigation ($rating->getUri ())))); + } + return $entryArray; + } + + public static function getRatingById ($ratingId) { + $result = parent::getDb ()->prepare('select rating from ratings where id = ?'); + $result->execute (array ($ratingId)); + return new Author ($ratingId, $result->fetchColumn ()); + } +}