|
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
|
|
|
class Author |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
const ALL_AUTHORS_ID = "cops:authors"; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count"; |
|
|
|
|
|
|
14
|
|
|
const SQL_AUTHORS_BY_FIRST_LETTER = "select {0} from authors, books_authors_link where author = authors.id and upper (authors.sort) like ? group by authors.id, authors.name, authors.sort order by sort"; |
|
|
|
|
|
|
15
|
|
|
const SQL_AUTHORS_FOR_SEARCH = "select {0} from authors, books_authors_link where author = authors.id and (upper (authors.sort) like ? or upper (authors.name) like ?) group by authors.id, authors.name, authors.sort order by sort"; |
|
|
|
|
|
|
16
|
|
|
const SQL_ALL_AUTHORS = "select {0} from authors, books_authors_link where author = authors.id group by authors.id, authors.name, authors.sort order by sort"; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public $id; |
|
19
|
|
|
public $name; |
|
20
|
|
|
public $sort; |
|
21
|
|
|
|
|
22
|
59 |
|
public function __construct($post) { |
|
23
|
59 |
|
$this->id = $post->id; |
|
24
|
59 |
|
$this->name = str_replace("|", ",", $post->name); |
|
|
|
|
|
|
25
|
59 |
|
$this->sort = $post->sort; |
|
26
|
59 |
|
} |
|
27
|
|
|
|
|
28
|
55 |
|
public function getUri () { |
|
29
|
55 |
|
return "?page=".Base::PAGE_AUTHOR_DETAIL."&id=$this->id"; |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
20 |
|
public function getEntryId () { |
|
33
|
20 |
|
return self::ALL_AUTHORS_ID.":".$this->id; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
3 |
|
public static function getEntryIdByLetter ($startingLetter) { |
|
37
|
3 |
|
return self::ALL_AUTHORS_ID.":letter:".$startingLetter; |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
18 |
|
public static function getCount() { |
|
41
|
|
|
// str_format (localize("authors.alphabetical", count(array)) |
|
|
|
|
|
|
42
|
18 |
|
return Base::getCountGeneric ("authors", self::ALL_AUTHORS_ID, Base::PAGE_ALL_AUTHORS); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
View Code Duplication |
public static function getAllAuthorsByFirstLetter() { |
|
|
|
|
|
|
46
|
2 |
|
list (, $result) = Base::executeQuery ("select {0} |
|
|
|
|
|
|
47
|
|
|
from authors |
|
48
|
|
|
group by substr (upper (sort), 1, 1) |
|
49
|
2 |
|
order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array (), -1); |
|
|
|
|
|
|
50
|
2 |
|
$entryArray = array(); |
|
51
|
2 |
|
while ($post = $result->fetchObject ()) |
|
52
|
|
|
{ |
|
53
|
2 |
|
array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), |
|
54
|
2 |
|
str_format (localize("authorword", $post->count), $post->count), "text", |
|
|
|
|
|
|
55
|
2 |
|
array ( new LinkNavigation ("?page=".Base::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
|
|
|
|
|
56
|
2 |
|
} |
|
57
|
2 |
|
return $entryArray; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public static function getAuthorsByStartingLetter($letter) { |
|
61
|
1 |
|
return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
23 |
|
public static function getAuthorsForSearch($query) { |
|
65
|
23 |
|
return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
public static function getAllAuthors() { |
|
69
|
1 |
|
return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
25 |
|
public static function getEntryArray ($query, $params) { |
|
73
|
25 |
|
return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
7 |
|
public static function getAuthorById ($authorId) { |
|
77
|
7 |
|
$result = Base::getDb ()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
|
78
|
7 |
|
$result->execute (array ($authorId)); |
|
79
|
7 |
|
$post = $result->fetchObject (); |
|
80
|
7 |
|
return new Author ($post); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
49 |
View Code Duplication |
public static function getAuthorByBookId ($bookId) { |
|
|
|
|
|
|
84
|
49 |
|
$result = Base::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
85
|
|
|
where author = authors.id |
|
86
|
49 |
|
and book = ?'); |
|
87
|
49 |
|
$result->execute (array ($bookId)); |
|
88
|
49 |
|
$authorArray = array (); |
|
89
|
49 |
|
while ($post = $result->fetchObject ()) { |
|
90
|
49 |
|
array_push ($authorArray, new Author ($post)); |
|
91
|
49 |
|
} |
|
92
|
49 |
|
return $authorArray; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.