X-Git-Url: https://git.rvb.name/openlib.git/blobdiff_plain/a47401f5fac121db5eb44214530121ab14cba2f3..6b3a07a008979ee27733a2deae2ff4fc42f4a535:/www/tag.php diff --git a/www/tag.php b/www/tag.php new file mode 100644 index 0000000..e73b9c0 --- /dev/null +++ b/www/tag.php @@ -0,0 +1,73 @@ + + */ + +require_once('base.php'); + +class tag extends Base { + const ALL_TAGS_ID = "calibre:tags"; + + public $id; + public $name; + + public function __construct($pid, $pname) { + $this->id = $pid; + $this->name = $pname; + } + + public static function getTagString ($code) { + $string = localize("tags.".$code); + if (preg_match ("/^tag/", $string)) { + return $code; + } + return $string; + } + + + public function getUri () { + return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id"; + } + + public function getEntryId () { + return self::ALL_TAGS_ID.":".$this->id; + } + + public static function getCount() { + $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn(0); + if ($nTags == 0) return NULL; + $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, + str_format (localize("tags.alphabetical", $nTags), $nTags), "text", + array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS))); + return $entry; + } + + public static function getTagById ($tagId) { + $result = parent::getDb ()->prepare('select id, name from tags where id = ?'); + $result->execute (array ($tagId)); + if ($post = $result->fetchObject ()) { + return new Tag ($post->id, Tag::getTagString ($post->name)); + } + return NULL; + } + + public static function getAllTags() { + $result = parent::getDb ()->query('select tags.id as id, tags.name as name, link.count +from tags, +(select tag,count(*) as count from books_tags_link group by tag) link +where tags.id = link.tag +order by tags.name'); + $entryArray = array(); + while ($post = $result->fetchObject ()) + { + $tag = new Tag ($post->id, Tag::getTagString ($post->name)); + array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", + array ( new LinkNavigation ($tag->getUri ())))); + } + return $entryArray; + } +}