X-Git-Url: https://git.rvb.name/openlib.git/blobdiff_plain/a47401f5fac121db5eb44214530121ab14cba2f3..6b3a07a008979ee27733a2deae2ff4fc42f4a535:/www/language.php diff --git a/www/language.php b/www/language.php new file mode 100644 index 0000000..646c658 --- /dev/null +++ b/www/language.php @@ -0,0 +1,75 @@ + + */ + +require_once('base.php'); + +class language extends Base { + const ALL_LANGUAGES_ID = "calibre:languages"; + + public $id; + public $lang_code; + + public function __construct($pid, $plang_code) { + $this->id = $pid; + $this->lang_code = $plang_code; + } + + public function getUri () { + return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; + } + + public function getEntryId () { + return self::ALL_LANGUAGES_ID.":".$this->id; + } + + public static function getLanguageString ($code) { + $string = localize("languages.".$code); + if (preg_match ("/^languages/", $string)) { + return $code; + } + return $string; + } + + public static function getCount() { + $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(0); + if ($nLanguages == 0) return NULL; + $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, + str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", + array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES))); + return $entry; + } + + public static function getLanguageById ($languageId) { + $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); + $result->execute (array ($languageId)); + if ($post = $result->fetchObject ()) { + return new Language ($post->id, Language::getLanguageString ($post->lang_code)); + } + return NULL; + } + + + + public static function getAllLanguages() { + $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, link.count as count +from languages, +(select lang_code,count(*) as count from books_languages_link group by lang_code) link +where languages.id = link.lang_code +group by languages.id, link.lang_code +order by languages.lang_code'); + $entryArray = array(); + while ($post = $result->fetchObject ()) + { + $language = new Language ($post->id, $post->lang_code); + array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", + array ( new LinkNavigation ($language->getUri ())))); + } + return $entryArray; + } +}