cops/language.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2013-05-21 20:49:21 +03:00
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Senioru <bla>
*/
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 getCount() {
$nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn();
$entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text non",
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 ()) {
2013-05-21 21:39:25 +03:00
return new Language ($post->id, localize("languages.".$post->lang_code));
2013-05-21 20:49:21 +03:00
}
return NULL;
}
public static function getAllLanguages() {
2013-05-21 21:39:25 +03:00
$result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
2013-05-21 20:49:21 +03:00
from languages, books_languages_link
where languages.id = books_languages_link.lang_code
group by languages.id, books_languages_link.lang_code
order by languages.lang_code');
$entryArray = array();
while ($post = $result->fetchObject ())
{
$language = new Language ($post->id, $post->lang_code);
2013-05-21 21:39:25 +03:00
array_push ($entryArray, new Entry (localize("languages.".$language->lang_code), $language->getEntryId (),
2013-05-21 20:49:21 +03:00
str_format (localize("bookword", $post->count), $post->count), "text non",
array ( new LinkNavigation ($language->getUri ()))));
}
return $entryArray;
}
}
2013-05-21 21:39:25 +03:00
?>