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
|
|
|
public $id; |
15
|
|
|
public $lang_code; |
16
|
|
|
|
17
|
3 |
|
public function __construct($pid, $plang_code) { |
18
|
3 |
|
$this->id = $pid; |
19
|
3 |
|
$this->lang_code = $plang_code; |
20
|
3 |
|
} |
21
|
|
|
|
22
|
2 |
|
public function getUri () { |
23
|
2 |
|
return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
24
|
|
|
} |
25
|
|
|
|
26
|
3 |
|
public function getEntryId () { |
27
|
3 |
|
return self::ALL_LANGUAGES_ID.":".$this->id; |
28
|
|
|
} |
29
|
|
|
|
30
|
13 |
|
public static function getLanguageString ($code) { |
31
|
13 |
|
$string = localize("languages.".$code); |
32
|
13 |
|
if (preg_match ("/^languages/", $string)) { |
33
|
|
|
return $code; |
34
|
|
|
} |
35
|
13 |
|
return $string; |
36
|
|
|
} |
37
|
|
|
|
38
|
18 |
|
public static function getCount() { |
39
|
|
|
// str_format (localize("languages.alphabetical", count(array)) |
40
|
18 |
|
return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public static function getLanguageById ($languageId) { |
44
|
1 |
|
$result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
|
|
|
|
45
|
1 |
|
$result->execute (array ($languageId)); |
46
|
1 |
|
if ($post = $result->fetchObject ()) { |
47
|
1 |
|
return new Language ($post->id, Language::getLanguageString ($post->lang_code)); |
48
|
|
|
} |
49
|
|
|
return NULL; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
2 |
|
public static function getAllLanguages() { |
55
|
2 |
|
$result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count |
|
|
|
|
56
|
|
|
from languages, books_languages_link |
57
|
|
|
where languages.id = books_languages_link.lang_code |
58
|
|
|
group by languages.id, books_languages_link.lang_code |
59
|
2 |
|
order by languages.lang_code'); |
60
|
2 |
|
$entryArray = array(); |
61
|
2 |
|
while ($post = $result->fetchObject ()) |
62
|
|
|
{ |
63
|
2 |
|
$language = new Language ($post->id, $post->lang_code); |
64
|
2 |
|
array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
65
|
2 |
|
str_format (localize("bookword", $post->count), $post->count), "text", |
66
|
2 |
|
array ( new LinkNavigation ($language->getUri ())), "", $post->count)); |
67
|
2 |
|
} |
68
|
2 |
|
return $entryArray; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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 theSon
calls the wrong method in the parent class.