Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3KB

  1. <?php
  2. /**
  3. * COPS (Calibre OPDS PHP Server) class file
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Michael Pfitzner
  7. */
  8. require_once('base.php');
  9. class Rating extends Base {
  10. const ALL_RATING_ID = "cops:rating";
  11. const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
  12. const SQL_ALL_RATINGS ="select {0} from ratings, books_ratings_link where books_ratings_link.rating = ratings.id group by ratings.id order by ratings.rating";
  13. public $id;
  14. public $name;
  15. public $sort;
  16. public function __construct($pid, $pname) {
  17. $this->id = $pid;
  18. $this->name = $pname;
  19. }
  20. public function getUri () {
  21. return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
  22. }
  23. public function getEntryId () {
  24. return self::ALL_RATING_ID.":".$this->id;
  25. }
  26. public static function getCount() {
  27. $nRatings = parent::getDb ()->query('select count(*) from ratings')->fetchColumn();
  28. $entry = new Entry (localize("ratings.title"), self::ALL_RATING_ID,
  29. str_format (localize("ratings", $nRatings), $nRatings), "text",
  30. array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS)));
  31. return $entry;
  32. }
  33. public static function getAllRatings() {
  34. return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
  35. }
  36. public static function getEntryArray ($query, $params) {
  37. list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
  38. $entryArray = array();
  39. while ($post = $result->fetchObject ())
  40. {
  41. $ratingObj = new Rating ($post->id, $post->rating);
  42. $rating=$post->rating/2;
  43. $rating = str_format (localize("ratingword", $rating), $rating);
  44. array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
  45. str_format (localize("bookword", $post->count), $post->count), "text",
  46. array ( new LinkNavigation ($ratingObj->getUri ()))));
  47. }
  48. return $entryArray;
  49. }
  50. public static function getRatingById ($ratingId) {
  51. $result = parent::getDb ()->prepare('select rating from ratings where id = ?');
  52. $result->execute (array ($ratingId));
  53. return new Author ($ratingId, $result->fetchColumn ());
  54. }
  55. }