3 * COPS (Calibre OPDS PHP Server) class file
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Sébastien Lucas <sebastien@slucas.fr>
9 require_once('base.php');
11 class tag extends Base {
12 const ALL_TAGS_ID = "calibre:tags";
17 public function __construct($pid, $pname) {
22 public static function getTagString ($code) {
23 $string = localize("tags.".$code);
24 if (preg_match ("/^tag/", $string)) {
31 public function getUri () {
32 return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
35 public function getEntryId () {
36 return self::ALL_TAGS_ID.":".$this->id;
39 public static function getCount() {
40 $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn(0);
41 if ($nTags == 0) return NULL;
42 $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID,
43 str_format (localize("tags.alphabetical", $nTags), $nTags), "text",
44 array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS)));
48 public static function getTagById ($tagId) {
49 $result = parent::getDb ()->prepare('select id, name from tags where id = ?');
50 $result->execute (array ($tagId));
51 if ($post = $result->fetchObject ()) {
52 return new Tag ($post->id, Tag::getTagString ($post->name));
57 public static function getAllTags() {
58 $result = parent::getDb ()->query('select tags.id as id, tags.name as name, link.count
60 (select tag,count(*) as count from books_tags_link group by tag) link
61 where tags.id = link.tag
63 $entryArray = array();
64 while ($post = $result->fetchObject ())
66 $tag = new Tag ($post->id, Tag::getTagString ($post->name));
67 array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
68 str_format (localize("bookword", $post->count), $post->count), "text",
69 array ( new LinkNavigation ($tag->getUri ()))));