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.

73 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 Author extends Base {
  10. const ALL_AUTHORS_ID = "calibre:authors";
  11. public $id;
  12. public $name;
  13. public $sort;
  14. public function __construct($pid, $pname) {
  15. $this->id = $pid;
  16. $this->name = $pname;
  17. }
  18. public function getUri () {
  19. return "feed.php?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id";
  20. }
  21. public function getEntryId () {
  22. return self::ALL_AUTHORS_ID.":".$this->id;
  23. }
  24. public static function getCount() {
  25. $nAuthors = parent::getDb ()->query('select count(*) from authors')->fetchColumn();
  26. parent::addEntryClass ( new Entry ("Authors", self::ALL_AUTHORS_ID,
  27. "Alphabetical index of the $nAuthors authors", "text",
  28. array ( new LinkNavigation ("feed.php?page=".parent::PAGE_ALL_AUTHORS))));
  29. }
  30. public static function getAllAuthors() {
  31. $result = parent::getDb ()->query('select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count
  32. from authors, books_authors_link
  33. where author = authors.id
  34. group by authors.id, authors.name, authors.sort
  35. order by sort');
  36. while ($post = $result->fetchObject ())
  37. {
  38. $author = new Author ($post->id, $post->sort);
  39. parent::addEntryClass ( new Entry ($post->sort, $author->getEntryId (),
  40. "$post->count books", "text",
  41. array ( new LinkNavigation ($author->getUri ()))));
  42. }
  43. }
  44. public static function getAuthorName ($authorId) {
  45. $result = parent::getDb ()->prepare('select sort from authors where id = ?');
  46. $result->execute (array ($authorId));
  47. return $result->fetchColumn ();
  48. }
  49. public static function getAuthorByBookId ($bookId) {
  50. $result = parent::getDb ()->prepare('select authors.id as id, authors.sort as sort
  51. from authors, books_authors_link
  52. where author = authors.id
  53. and book = ?');
  54. $result->execute (array ($bookId));
  55. $authorArray = array ();
  56. while ($post = $result->fetchObject ()) {
  57. array_push ($authorArray, new Author ($post->id, $post->sort));
  58. }
  59. return $authorArray;
  60. }
  61. }
  62. ?>