-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublisher.php
67 lines (55 loc) · 2.43 KB
/
publisher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author At Libitum <[email protected]>
*/
require_once('base.php');
class Publisher extends Base {
const ALL_PUBLISHERS_ID = "cops:publishers";
const PUBLISHERS_COLUMNS = "publishers.id as id, publishers.name as name, count(*) as count";
const SQL_ALL_PUBLISHERS = "select {0} from publishers, books_publishers_link where publishers.id = publisher group by publishers.id, publishers.name order by publishers.name";
const SQL_PUBLISHERS_FOR_SEARCH = "select {0} from publishers, books_publishers_link where publishers.id = publisher and upper (publishers.name) like ? group by publishers.id, publishers.name order by publishers.name";
public $id;
public $name;
public function __construct($post) {
$this->id = $post->id;
$this->name = $post->name;
}
public function getUri () {
return "?page=".parent::PAGE_PUBLISHER_DETAIL."&id=$this->id";
}
public function getEntryId () {
return self::ALL_PUBLISHERS_ID.":".$this->id;
}
public static function getCount() {
// str_format (localize("publishers.alphabetical", count(array))
return parent::getCountGeneric ("publishers", self::ALL_PUBLISHERS_ID, parent::PAGE_ALL_PUBLISHERS);
}
public static function getPublisherByBookId ($bookId) {
$result = parent::getDb ()->prepare('select publishers.id as id, name
from books_publishers_link, publishers
where publishers.id = publisher and book = ?');
$result->execute (array ($bookId));
if ($post = $result->fetchObject ()) {
return new Publisher ($post);
}
return NULL;
}
public static function getPublisherById ($publisherId) {
$result = parent::getDb ()->prepare('select id, name
from publishers where id = ?');
$result->execute (array ($publisherId));
if ($post = $result->fetchObject ()) {
return new Publisher ($post);
}
return NULL;
}
public static function getAllPublishers() {
return Base::getEntryArrayWithBookNumber (self::SQL_ALL_PUBLISHERS, self::PUBLISHERS_COLUMNS, array (), "Publisher");
}
public static function getAllPublishersByQuery($query) {
return Base::getEntryArrayWithBookNumber (self::SQL_PUBLISHERS_FOR_SEARCH, self::PUBLISHERS_COLUMNS, array ('%' . $query . '%'), "Publisher");
}
}