From 14199cf9b38cccec17c372d5f55ec3fd81326e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sun, 30 Sep 2012 14:39:53 +0200 Subject: [PATCH] Author split is finished with this little refactoring. fix #13 --- author.php | 30 ++++++++++-------------------- base.php | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/author.php b/author.php index 2452284..a3310a7 100644 --- a/author.php +++ b/author.php @@ -11,6 +11,10 @@ require_once('base.php'); class Author extends Base { const ALL_AUTHORS_ID = "calibre:authors"; + const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count"; + 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"; + 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"; + public $id; public $name; public $sort; @@ -56,29 +60,15 @@ order by substr (upper (sort), 1, 1)'); } public static function getAuthorsByStartingLetter($letter) { - $result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count -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'); - $entryArray = array(); - $result->execute (array ($letter . "%")); - while ($post = $result->fetchObject ()) - { - $author = new Author ($post->id, $post->sort); - array_push ($entryArray, new Entry ($post->sort, $author->getEntryId (), - str_format (localize("bookword.many"), $post->count), "text", - array ( new LinkNavigation ($author->getUri ())))); - } - return $entryArray; + return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); } public static function getAllAuthors() { - $result = parent::getDb ()->query('select authors.id as id, authors.name as name, authors.sort as sort, count(*) as count -from authors, books_authors_link -where author = authors.id -group by authors.id, authors.name, authors.sort -order by sort'); + return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); + } + + public static function getEntryArray ($query, $params) { + list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, $params, -1); $entryArray = array(); while ($post = $result->fetchObject ()) { diff --git a/base.php b/base.php index 97e34e7..abc4819 100644 --- a/base.php +++ b/base.php @@ -431,7 +431,7 @@ abstract class Base global $config; $totalResult = -1; - if ($config['cops_max_item_per_page'] != -1) + if ($config['cops_max_item_per_page'] != -1 && $n != -1) { // First check total number of results $result = self::getDb ()->prepare (str_format ($query, "count(*)"));