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.

68 lines
2.4KB

  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 At Libitum <eljarec@yahoo.com>
  7. */
  8. require_once('base.php');
  9. class Publisher extends Base {
  10. const ALL_PUBLISHERS_ID = "cops:publishers";
  11. const PUBLISHERS_COLUMNS = "publishers.id as id, publishers.name as name, count(*) as count";
  12. const SQL_ALL_PUBLISHERS = "select {0} from publishers, books_publishers_link where publishers.id = publisher group by publishers.id, publishers.name order by publishers.name";
  13. const SQL_PUBLISHERS_FOR_SEARCH = "select {0} from publishers, books_publishers_link where publishers.id = publisher and upper (publishers.name) like ? group by publishers.id, publishers.name order by publishers.name";
  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_PUBLISHER_DETAIL."&id=$this->id";
  22. }
  23. public function getEntryId () {
  24. return self::ALL_PUBLISHERS_ID.":".$this->id;
  25. }
  26. public static function getCount() {
  27. // str_format (localize("publishers.alphabetical", count(array))
  28. return parent::getCountGeneric ("publishers", self::ALL_PUBLISHERS_ID, parent::PAGE_ALL_PUBLISHERS);
  29. }
  30. public static function getPublisherByBookId ($bookId) {
  31. $result = parent::getDb ()->prepare('select publishers.id as id, name
  32. from books_publishers_link, publishers
  33. where publishers.id = publisher and book = ?');
  34. $result->execute (array ($bookId));
  35. if ($post = $result->fetchObject ()) {
  36. return new Publisher ($post);
  37. }
  38. return NULL;
  39. }
  40. public static function getPublisherById ($publisherId) {
  41. $result = parent::getDb ()->prepare('select id, name
  42. from publishers where id = ?');
  43. $result->execute (array ($publisherId));
  44. if ($post = $result->fetchObject ()) {
  45. return new Publisher ($post);
  46. }
  47. return NULL;
  48. }
  49. public static function getAllPublishers() {
  50. return Base::getEntryArrayWithBookNumber (self::SQL_ALL_PUBLISHERS, self::PUBLISHERS_COLUMNS, array (), "Publisher");
  51. }
  52. public static function getAllPublishersByQuery($query) {
  53. return Base::getEntryArrayWithBookNumber (self::SQL_PUBLISHERS_FOR_SEARCH, self::PUBLISHERS_COLUMNS, array ('%' . $query . '%'), "Publisher");
  54. }
  55. }