From f095e9426e4da4761a49a0140a259818a5e773d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 2 Jun 2014 22:04:41 +0200 Subject: [PATCH] Add the number of elements with the publishers. re #79 --- base.php | 7 ++++++- publisher.php | 47 +++++++++++------------------------------------ 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/base.php b/base.php index 9195340..6bf1dde 100644 --- a/base.php +++ b/base.php @@ -1272,7 +1272,12 @@ abstract class Base while ($post = $result->fetchObject ()) { $instance = new $category ($post); - array_push ($entryArray, new Entry ($post->sort, $instance->getEntryId (), + if (property_exists($post, "sort")) { + $title = $post->sort; + } else { + $title = $post->name; + } + array_push ($entryArray, new Entry ($title, $instance->getEntryId (), str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($instance->getUri ())), "", $post->count)); } diff --git a/publisher.php b/publisher.php index 6ab09de..c8ca878 100644 --- a/publisher.php +++ b/publisher.php @@ -10,13 +10,17 @@ 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($pid, $pname) { - $this->id = $pid; - $this->name = $pname; + public function __construct($post) { + $this->id = $post->id; + $this->name = $post->name; } public function getUri () { @@ -38,7 +42,7 @@ 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 new Publisher ($post); } return NULL; } @@ -48,45 +52,16 @@ where publishers.id = publisher and book = ?'); from publishers where id = ?'); $result->execute (array ($publisherId)); if ($post = $result->fetchObject ()) { - return new Publisher ($post->id, $post->name); + return new Publisher ($post); } 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; + return Base::getEntryArrayWithBookNumber (self::SQL_ALL_PUBLISHERS, self::PUBLISHERS_COLUMNS, array (), "Publisher"); } 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; + return Base::getEntryArrayWithBookNumber (self::SQL_PUBLISHERS_FOR_SEARCH, self::PUBLISHERS_COLUMNS, array ('%' . $query . '%'), "Publisher"); } }