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 Sébastien Lucas <sebastien@slucas.fr>
  7. */
  8. require_once('base.php');
  9. class Serie extends Base {
  10. const ALL_SERIES_ID = "cops:series";
  11. const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count";
  12. const SQL_ALL_SERIES = "select {0} from series, books_series_link where series.id = series group by series.id, series.name, series.sort order by series.sort";
  13. const SQL_SERIES_FOR_SEARCH = "select {0} from series, books_series_link where series.id = series and upper (series.name) like ? group by series.id, series.name, series.sort order by series.sort";
  14. public $id;
  15. public $name;
  16. public function __construct($post) {
  17. $this->id = $post->id;
  18. $this->name = $post->name;
  19. }
  20. public function getUri () {
  21. return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
  22. }
  23. public function getEntryId () {
  24. return self::ALL_SERIES_ID.":".$this->id;
  25. }
  26. public static function getCount() {
  27. // str_format (localize("series.alphabetical", count(array))
  28. return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
  29. }
  30. public static function getSerieByBookId ($bookId) {
  31. $result = parent::getDb ()->prepare('select series.id as id, name
  32. from books_series_link, series
  33. where series.id = series and book = ?');
  34. $result->execute (array ($bookId));
  35. if ($post = $result->fetchObject ()) {
  36. return new Serie ($post);
  37. }
  38. return NULL;
  39. }
  40. public static function getSerieById ($serieId) {
  41. $result = parent::getDb ()->prepare('select id, name from series where id = ?');
  42. $result->execute (array ($serieId));
  43. if ($post = $result->fetchObject ()) {
  44. return new Serie ($post);
  45. }
  46. return NULL;
  47. }
  48. public static function getAllSeries() {
  49. return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array (), "Serie");
  50. }
  51. public static function getAllSeriesByQuery($query) {
  52. return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array ('%' . $query . '%'), "Serie");
  53. }
  54. }