|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Sébastien Lucas <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
require_once('base.php'); |
|
10
|
|
|
|
|
11
|
|
|
class language extends Base { |
|
12
|
|
|
const ALL_LANGUAGES_ID = "cops:languages"; |
|
13
|
|
|
|
|
14
|
|
|
const SQL_ALL_LANGUAGES = |
|
15
|
|
|
"select languages.id as id, languages.lang_code as lang_code, count(*) as count |
|
16
|
|
|
from languages |
|
17
|
3 |
|
inner join books_languages_link as link on languages.id = link.lang_code |
|
18
|
3 |
|
inner join ({0}) as filter on link.book = filter.id |
|
19
|
3 |
|
group by languages.id, link.lang_code |
|
20
|
3 |
|
order by languages.lang_code"; |
|
21
|
|
|
|
|
22
|
2 |
|
public $id; |
|
23
|
2 |
|
public $lang_code; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct($pid, $plang_code) { |
|
26
|
3 |
|
$this->id = $pid; |
|
27
|
3 |
|
$this->lang_code = $plang_code; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
12 |
|
public function getUri () { |
|
31
|
12 |
|
return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
|
32
|
12 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getEntryId () { |
|
35
|
12 |
|
return self::ALL_LANGUAGES_ID.":".$this->id; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
7 |
|
public static function getLanguageString ($code) { |
|
39
|
|
|
$string = localize("languages.".$code); |
|
40
|
7 |
|
if (preg_match ("/^languages/", $string)) { |
|
41
|
|
|
return $code; |
|
42
|
|
|
} |
|
43
|
1 |
|
return $string; |
|
44
|
1 |
|
} |
|
45
|
1 |
|
|
|
46
|
1 |
|
public static function getCount() { |
|
47
|
1 |
|
// str_format (localize("languages.alphabetical", count(array)) |
|
48
|
|
|
return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function getLanguageById ($languageId) { |
|
52
|
|
|
$result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
|
|
|
|
|
|
53
|
|
|
$result->execute (array ($languageId)); |
|
54
|
2 |
|
if ($post = $result->fetchObject ()) { |
|
55
|
2 |
|
return new Language ($post->id, Language::getLanguageString ($post->lang_code)); |
|
56
|
|
|
} |
|
57
|
|
|
return NULL; |
|
58
|
|
|
} |
|
59
|
2 |
|
|
|
60
|
2 |
|
|
|
61
|
2 |
|
|
|
62
|
|
|
public static function getAllLanguages() { |
|
63
|
2 |
|
list (, $result) = self::executeFilteredQuery(self::SQL_ALL_LANGUAGES, array(), -1); |
|
64
|
2 |
|
$entryArray = array(); |
|
65
|
2 |
|
while ($post = $result->fetchObject ()) |
|
66
|
2 |
|
{ |
|
67
|
2 |
|
$language = new Language ($post->id, $post->lang_code); |
|
68
|
2 |
|
array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
|
69
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text", |
|
70
|
|
|
array ( new LinkNavigation ($language->getUri ())), "", $post->count)); |
|
71
|
|
|
} |
|
72
|
|
|
return $entryArray; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Takes a language name and tries to find the language code |
|
77
|
|
|
* @param string $language A language name |
|
78
|
|
|
* @return string the code for this name |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function getLanguageCode($language) { |
|
81
|
|
|
// Filtering this call will lead to endless recursion |
|
82
|
|
|
list (, $result) = self::executeQuery("select {0} from languages", "id, lang_code", "", array(), -1); |
|
83
|
|
|
$entryArray = array(); |
|
|
|
|
|
|
84
|
|
|
while ($post = $result->fetchObject ()) |
|
85
|
|
|
{ |
|
86
|
|
|
$code = $post->lang_code; |
|
87
|
|
|
$lang = Language::getLanguageString ($code); |
|
88
|
|
|
if (strcasecmp($lang, $language) == 0) |
|
89
|
|
|
return $code; |
|
90
|
|
|
} |
|
91
|
|
|
return $language; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.