cops/publisher.php
2014-05-30 06:47:38 +02:00

93 lines
3.2 KiB
PHP

<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author At Libitum <eljarec@yahoo.com>
*/
require_once('base.php');
class Publisher extends Base {
const ALL_PUBLISHERS_ID = "cops:publishers";
public $id;
public $name;
public function __construct($pid, $pname) {
$this->id = $pid;
$this->name = $pname;
}
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->id, $post->name);
}
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->id, $post->name);
}
return NULL;
}
public static function getAllPublishers() {
$result = parent::getDb ()->query('select publishers.id as id, publishers.name as name, count(*) as count
from publishers, books_publishers_link
where publishers.id = publisher
group by publishers.id, publishers.name
order by publishers.name');
$entryArray = array();
while ($post = $result->fetchObject ())
{
$publisher = new Publisher ($post->id, $post->name);
array_push ($entryArray, new Entry ($publisher->name, $publisher->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($publisher->getUri ()))));
}
return $entryArray;
}
public static function getAllPublishersByQuery($query) {
$columns = "publishers.id as id, publishers.name as name, count(*) as count";
$sql = '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';
list (, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), -1);
$entryArray = array();
while ($post = $result->fetchObject ())
{
$publisher = new Publisher ($post->id, $post->name);
array_push ($entryArray, new Entry ($publisher->name, $publisher->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($publisher->getUri ()))));
}
return $entryArray;
}
}