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.

62 line
2.1KB

  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 function __construct($pid, $pname) {
  16. $this->id = $pid;
  17. $this->name = $pname;
  18. }
  19. public function getUri () {
  20. return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
  21. }
  22. public function getEntryId () {
  23. return self::ALL_RATING_ID.":".$this->id;
  24. }
  25. public static function getCount() {
  26. // str_format (localize("ratings", count(array))
  27. return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
  28. }
  29. public static function getAllRatings() {
  30. return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
  31. }
  32. public static function getEntryArray ($query, $params) {
  33. list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
  34. $entryArray = array();
  35. while ($post = $result->fetchObject ())
  36. {
  37. $ratingObj = new Rating ($post->id, $post->rating);
  38. $rating=$post->rating/2;
  39. $rating = str_format (localize("ratingword", $rating), $rating);
  40. array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
  41. str_format (localize("bookword", $post->count), $post->count), "text",
  42. array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
  43. }
  44. return $entryArray;
  45. }
  46. public static function getRatingById ($ratingId) {
  47. $result = parent::getDb ()->prepare('select rating from ratings where id = ?');
  48. $result->execute (array ($ratingId));
  49. return new Rating ($ratingId, $result->fetchColumn ());
  50. }
  51. }