--- /dev/null
+<?php
+/**
+ * COPS (Calibre OPDS PHP Server) class file
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Sébastien Lucas <sebastien@slucas.fr>
+ */
+
+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;
+ }
+}