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.

76 lines
2.5KB

  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 Sébastien Lucas <sebastien@slucas.fr>
  7. */
  8. require_once('base.php');
  9. class Serie extends Base {
  10. const ALL_SERIES_ID = "calibre:series";
  11. public $id;
  12. public $name;
  13. public function __construct($pid, $pname) {
  14. $this->id = $pid;
  15. $this->name = $pname;
  16. }
  17. public function getUri () {
  18. return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
  19. }
  20. public function getEntryId () {
  21. return self::ALL_SERIES_ID.":".$this->id;
  22. }
  23. public static function getCount() {
  24. $nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn();
  25. if ($nSeries == 0) return NULL;
  26. $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
  27. str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",
  28. array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
  29. return $entry;
  30. }
  31. public static function getSerieByBookId ($bookId) {
  32. $result = parent::getDb ()->prepare('select series.id as id, name
  33. from books_series_link, series
  34. where series.id = series and book = ?');
  35. $result->execute (array ($bookId));
  36. if ($post = $result->fetchObject ()) {
  37. return new Serie ($post->id, $post->name);
  38. }
  39. return NULL;
  40. }
  41. public static function getSerieById ($serieId) {
  42. $result = parent::getDb ()->prepare('select id, name from series where id = ?');
  43. $result->execute (array ($serieId));
  44. if ($post = $result->fetchObject ()) {
  45. return new Serie ($post->id, $post->name);
  46. }
  47. return NULL;
  48. }
  49. public static function getAllSeries() {
  50. $result = parent::getDb ()->query('select series.id as id, series.name as name, series.sort as sort, count(*) as count
  51. from series, books_series_link
  52. where series.id = series
  53. group by series.id, series.name, series.sort
  54. order by series.sort');
  55. $entryArray = array();
  56. while ($post = $result->fetchObject ())
  57. {
  58. $serie = new Serie ($post->id, $post->sort);
  59. array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
  60. str_format (localize("bookword", $post->count), $post->count), "text",
  61. array ( new LinkNavigation ($serie->getUri ()))));
  62. }
  63. return $entryArray;
  64. }
  65. }