From 9aee96d7e20dd2778029700eed9a2e5a88fc5852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Wed, 28 May 2014 16:13:57 +0200 Subject: [PATCH] Centralize some of the database function (linked to the normalized search). re #48, #49 --- author.php | 2 +- base.php | 4 ++++ book.php | 5 ++--- language.php | 2 +- publisher.php | 2 +- rating.php | 2 +- serie.php | 2 +- tag.php | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/author.php b/author.php index ba871ce..cf7d9ae 100644 --- a/author.php +++ b/author.php @@ -39,7 +39,7 @@ class Author extends Base { } public static function getCount() { - $nAuthors = parent::getDb ()->query('select count(*) from authors')->fetchColumn(); + $nAuthors = parent::executeQuerySingle ('select count(*) from authors'); $entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID, str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS))); diff --git a/base.php b/base.php index f91c0c5..1668fd9 100644 --- a/base.php +++ b/base.php @@ -1248,6 +1248,10 @@ abstract class Base self::$db = NULL; } + public static function executeQuerySingle ($query, $database = NULL) { + return self::getDb ($database)->query($query)->fetchColumn(); + } + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { $totalResult = -1; diff --git a/book.php b/book.php index 60f4189..f150155 100644 --- a/book.php +++ b/book.php @@ -428,13 +428,12 @@ class Book extends Base { } public static function getBookCount($database = NULL) { - $nBooks = parent::getDb ($database)->query('select count(*) from books')->fetchColumn(); - return $nBooks; + return parent::executeQuerySingle ('select count(*) from books', $database); } public static function getCount() { global $config; - $nBooks = parent::getDb ()->query('select count(*) from books')->fetchColumn(); + $nBooks = parent::executeQuerySingle ('select count(*) from books'); $result = array(); $entry = new Entry (localize ("allbooks.title"), self::ALL_BOOKS_ID, diff --git a/language.php b/language.php index 8acb627..4d54ec1 100644 --- a/language.php +++ b/language.php @@ -36,7 +36,7 @@ class language extends Base { } public static function getCount() { - $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(); + $nLanguages = parent::executeQuerySingle ('select count(*) from languages'); if ($nLanguages == 0) return NULL; $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", diff --git a/publisher.php b/publisher.php index 7e6abb4..2a6a34b 100644 --- a/publisher.php +++ b/publisher.php @@ -28,7 +28,7 @@ class Publisher extends Base { } public static function getCount() { - $nPublishers = parent::getDb ()->query('select count(*) from publishers')->fetchColumn(); + $nPublishers = parent::executeQuerySingle ('select count(*) from publishers'); if ($nPublishers == 0) return NULL; $entry = new Entry (localize("publishers.title"), self::ALL_PUBLISHERS_ID, str_format (localize("publishers.alphabetical", $nPublishers), $nPublishers), "text", diff --git a/rating.php b/rating.php index df7a111..10389e9 100644 --- a/rating.php +++ b/rating.php @@ -30,7 +30,7 @@ class Rating extends Base { } public static function getCount() { - $nRatings = parent::getDb ()->query('select count(*) from ratings')->fetchColumn(); + $nRatings = parent::executeQuerySingle ('select count(*) from ratings'); $entry = new Entry (localize("ratings.title"), self::ALL_RATING_ID, str_format (localize("ratings", $nRatings), $nRatings), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS))); diff --git a/serie.php b/serie.php index cb5ea5a..63f40d0 100644 --- a/serie.php +++ b/serie.php @@ -28,7 +28,7 @@ class Serie extends Base { } public static function getCount() { - $nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn(); + $nSeries = parent::executeQuerySingle ('select count(*) from series'); if ($nSeries == 0) return NULL; $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID, str_format (localize("series.alphabetical", $nSeries), $nSeries), "text", diff --git a/tag.php b/tag.php index feb14f1..cd8fb1c 100644 --- a/tag.php +++ b/tag.php @@ -28,7 +28,7 @@ class tag extends Base { } public static function getCount() { - $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn(); + $nTags = parent::executeQuerySingle ('select count(*) from tags'); if ($nTags == 0) return NULL; $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, str_format (localize("tags.alphabetical", $nTags), $nTags), "text",