From 4be0366a0ab9e01d3731f673a5acff2706334ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 30 May 2014 06:47:38 +0200 Subject: [PATCH] Centralize the getCount function. --- author.php | 7 ++----- base.php | 12 ++++++++++++ language.php | 8 ++------ publisher.php | 8 ++------ rating.php | 7 ++----- serie.php | 8 ++------ tag.php | 8 ++------ 7 files changed, 24 insertions(+), 34 deletions(-) diff --git a/author.php b/author.php index cf7d9ae..abaa480 100644 --- a/author.php +++ b/author.php @@ -39,11 +39,8 @@ class Author extends Base { } public static function getCount() { - $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))); - return $entry; + // str_format (localize("authors.alphabetical", count(array)) + return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); } public static function getAllAuthorsByFirstLetter() { diff --git a/base.php b/base.php index 1668fd9..018276e 100644 --- a/base.php +++ b/base.php @@ -1252,6 +1252,18 @@ abstract class Base return self::getDb ($database)->query($query)->fetchColumn(); } + public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { + if (!$numberOfString) { + $numberOfString = $table . ".alphabetical"; + } + $count = self::executeQuerySingle ('select count(*) from ' . $table); + if ($count == 0) return NULL; + $entry = new Entry (localize($table . ".title"), $id, + str_format (localize($numberOfString, $count), $count), "text", + array ( new LinkNavigation ("?page=".$pageId))); + return $entry; + } + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { $totalResult = -1; diff --git a/language.php b/language.php index 4d54ec1..a9a984b 100644 --- a/language.php +++ b/language.php @@ -36,12 +36,8 @@ class language extends Base { } public static function getCount() { - $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", - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES))); - return $entry; + // str_format (localize("languages.alphabetical", count(array)) + return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); } public static function getLanguageById ($languageId) { diff --git a/publisher.php b/publisher.php index 2a6a34b..6ab09de 100644 --- a/publisher.php +++ b/publisher.php @@ -28,12 +28,8 @@ class Publisher extends Base { } public static function getCount() { - $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", - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_PUBLISHERS))); - return $entry; + // str_format (localize("publishers.alphabetical", count(array)) + return parent::getCountGeneric ("publishers", self::ALL_PUBLISHERS_ID, parent::PAGE_ALL_PUBLISHERS); } public static function getPublisherByBookId ($bookId) { diff --git a/rating.php b/rating.php index 10389e9..19f59d1 100644 --- a/rating.php +++ b/rating.php @@ -30,11 +30,8 @@ class Rating extends Base { } public static function getCount() { - $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))); - return $entry; + // str_format (localize("ratings", count(array)) + return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); } public static function getAllRatings() { diff --git a/serie.php b/serie.php index 63f40d0..7d7e18a 100644 --- a/serie.php +++ b/serie.php @@ -28,12 +28,8 @@ class Serie extends Base { } public static function getCount() { - $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", - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES))); - return $entry; + // str_format (localize("series.alphabetical", count(array)) + return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES); } public static function getSerieByBookId ($bookId) { diff --git a/tag.php b/tag.php index cd8fb1c..31e909b 100644 --- a/tag.php +++ b/tag.php @@ -28,12 +28,8 @@ class tag extends Base { } public static function getCount() { - $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", - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS))); - return $entry; + // str_format (localize("tags.alphabetical", count(array)) + return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS); } public static function getTagById ($tagId) {