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 language extends Base {
12 const ALL_LANGUAGES_ID = "calibre:languages";
17 public function __construct($pid, $plang_code) {
19 $this->lang_code = $plang_code;
22 public function getUri () {
23 return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id";
26 public function getEntryId () {
27 return self::ALL_LANGUAGES_ID.":".$this->id;
30 public static function getLanguageString ($code) {
31 $string = localize("languages.".$code);
32 if (preg_match ("/^languages/", $string)) {
38 public static function getCount() {
39 $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(0);
40 if ($nLanguages == 0) return NULL;
41 $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
42 str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text",
43 array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES)));
47 public static function getLanguageById ($languageId) {
48 $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
49 $result->execute (array ($languageId));
50 if ($post = $result->fetchObject ()) {
51 return new Language ($post->id, Language::getLanguageString ($post->lang_code));
58 public static function getAllLanguages() {
59 $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, link.count as count
61 (select lang_code,count(*) as count from books_languages_link group by lang_code) link
62 where languages.id = link.lang_code
63 group by languages.id, link.lang_code
64 order by languages.lang_code');
65 $entryArray = array();
66 while ($post = $result->fetchObject ())
68 $language = new Language ($post->id, $post->lang_code);
69 array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
70 str_format (localize("bookword", $post->count), $post->count), "text",
71 array ( new LinkNavigation ($language->getUri ()))));