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.

65 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 tag extends Base {
  10. const ALL_TAGS_ID = "cops:tags";
  11. const TAG_COLUMNS = "tags.id as id, tags.name as name, count(*) as count";
  12. const SQL_ALL_TAGS = "select {0} from tags, books_tags_link where tags.id = tag group by tags.id, tags.name order by tags.name";
  13. public $id;
  14. public $name;
  15. public function __construct($post) {
  16. $this->id = $post->id;
  17. $this->name = $post->name;
  18. }
  19. public function getUri () {
  20. return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
  21. }
  22. public function getEntryId () {
  23. return self::ALL_TAGS_ID.":".$this->id;
  24. }
  25. public static function getCount() {
  26. // str_format (localize("tags.alphabetical", count(array))
  27. return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
  28. }
  29. public static function getTagById ($tagId) {
  30. $result = parent::getDb ()->prepare('select id, name from tags where id = ?');
  31. $result->execute (array ($tagId));
  32. if ($post = $result->fetchObject ()) {
  33. return new Tag ($post);
  34. }
  35. return NULL;
  36. }
  37. public static function getAllTags() {
  38. return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
  39. }
  40. public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
  41. $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
  42. $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name';
  43. list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage);
  44. $entryArray = array();
  45. while ($post = $result->fetchObject ())
  46. {
  47. $tag = new Tag ($post);
  48. array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
  49. str_format (localize("bookword", $post->count), $post->count), "text",
  50. array ( new LinkNavigation ($tag->getUri ()))));
  51. }
  52. return array ($entryArray, $totalNumber);
  53. }
  54. }