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 Author extends Base { |
12
|
|
|
const ALL_AUTHORS_ID = "cops:authors"; |
13
|
|
|
|
14
|
|
|
const SQL_AUTHORS_BY_FIRST_LETTER = |
15
|
|
|
"select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count |
16
|
|
|
from authors |
17
|
|
|
inner join books_authors_link as link on link.author = authors.id |
18
|
|
|
inner join ({0}) as filter on filter.id = link.book |
19
|
|
|
where upper (authors.sort) like ? |
20
|
|
|
group by authors.id, authors.name, authors.sort |
21
|
|
|
order by sort"; |
22
|
|
|
const SQL_AUTHORS_FOR_SEARCH = |
23
|
56 |
|
"select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count |
24
|
56 |
|
from authors |
25
|
56 |
|
inner join books_authors_link as link on link.author = authors.id |
26
|
56 |
|
inner join ({0}) as filter on filter.id = link.book |
27
|
56 |
|
where (upper (authors.sort) like ? or upper (authors.name) like ?) |
28
|
|
|
group by authors.id, authors.name, authors.sort |
29
|
53 |
|
order by sort"; |
30
|
53 |
|
const SQL_ALL_AUTHORS = |
31
|
|
|
"select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count |
32
|
|
|
from authors |
33
|
20 |
|
inner join books_authors_link as link on author = authors.id |
34
|
20 |
|
inner join ({0}) as filter on filter.id = link.book |
35
|
|
|
group by authors.id, authors.name, authors.sort |
36
|
|
|
order by sort"; |
37
|
3 |
|
const SQL_ALL_AUTHORS_FIRST_LETTERS = |
38
|
3 |
|
"select substr (upper (sort), 1, 1) as title, count(*) as count |
39
|
|
|
from authors |
40
|
|
|
inner join books_authors_link as link on link.author = authors.id |
41
|
7 |
|
inner join ({0}) as filter on filter.id = link.book |
42
|
|
|
group by substr (upper (sort), 1, 1) |
43
|
7 |
|
order by substr (upper (sort), 1, 1)"; |
44
|
|
|
|
45
|
|
|
public $id; |
46
|
2 |
|
public $name; |
47
|
2 |
|
public $sort; |
48
|
|
|
|
49
|
|
|
public function __construct($post) { |
50
|
2 |
|
$this->id = $post->id; |
51
|
2 |
|
$this->name = str_replace("|", ",", $post->name); |
52
|
2 |
|
$this->sort = $post->sort; |
53
|
|
|
} |
54
|
2 |
|
|
55
|
2 |
|
public function getUri () { |
56
|
2 |
|
return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; |
57
|
2 |
|
} |
58
|
2 |
|
|
59
|
|
|
public function getEntryId () { |
60
|
|
|
return self::ALL_AUTHORS_ID.":".$this->id; |
61
|
1 |
|
} |
62
|
1 |
|
|
63
|
|
|
public static function getEntryIdByLetter ($startingLetter) { |
64
|
|
|
return self::ALL_AUTHORS_ID.":letter:".$startingLetter; |
65
|
23 |
|
} |
66
|
23 |
|
|
67
|
|
|
public static function getCount() { |
68
|
|
|
// str_format (localize("authors.alphabetical", count(array)) |
69
|
1 |
|
return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
|
|
|
|
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
public static function getAllAuthorsFirstLetters() { |
73
|
25 |
|
list (, $result) = parent::executeFilteredQuery(self::SQL_ALL_AUTHORS_FIRST_LETTERS, array(), -1); |
|
|
|
|
74
|
25 |
|
$entryArray = array(); |
75
|
|
|
while ($post = $result->fetchObject ()) |
76
|
|
|
{ |
77
|
7 |
|
array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), |
78
|
7 |
|
str_format (localize("authorword", $post->count), $post->count), "text", |
79
|
7 |
|
array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
80
|
7 |
|
} |
81
|
7 |
|
return $entryArray; |
82
|
|
|
} |
83
|
|
|
|
84
|
46 |
|
public static function getAuthorsByStartingLetter($letter) { |
85
|
46 |
|
return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
86
|
|
|
} |
87
|
46 |
|
|
88
|
46 |
|
public static function getAuthorsForSearch($query) { |
89
|
46 |
|
return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
90
|
46 |
|
} |
91
|
46 |
|
|
92
|
46 |
|
public static function getAllAuthors() { |
93
|
46 |
|
return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public static function getEntryArray ($query, $params) { |
97
|
|
|
return Base::getEntryArrayWithBookNumber ($query, $params, "Author"); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function getAuthorById ($authorId) { |
101
|
|
|
$result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count from authors where id = ?'); |
|
|
|
|
102
|
|
|
$result->execute (array ($authorId)); |
103
|
|
|
$post = $result->fetchObject (); |
104
|
|
|
return new Author ($post); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function getAuthorByBookId ($bookId) { |
108
|
|
|
$result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
|
|
|
109
|
|
|
where author = authors.id |
110
|
|
|
and book = ?'); |
111
|
|
|
$result->execute (array ($bookId)); |
112
|
|
|
$authorArray = array (); |
113
|
|
|
while ($post = $result->fetchObject ()) { |
114
|
|
|
array_push ($authorArray, new Author ($post)); |
115
|
|
|
} |
116
|
|
|
return $authorArray; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.