Centralize the getCount function.

This commit is contained in:
Sébastien Lucas 2014-05-30 06:47:38 +02:00
parent 70611e5c50
commit 4be0366a0a
7 changed files with 24 additions and 34 deletions

View file

@ -39,11 +39,8 @@ class Author extends Base {
} }
public static function getCount() { public static function getCount() {
$nAuthors = parent::executeQuerySingle ('select count(*) from authors'); // str_format (localize("authors.alphabetical", count(array))
$entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID, return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS);
str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS)));
return $entry;
} }
public static function getAllAuthorsByFirstLetter() { public static function getAllAuthorsByFirstLetter() {

View file

@ -1252,6 +1252,18 @@ abstract class Base
return self::getDb ($database)->query($query)->fetchColumn(); 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) { public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
$totalResult = -1; $totalResult = -1;

View file

@ -36,12 +36,8 @@ class language extends Base {
} }
public static function getCount() { public static function getCount() {
$nLanguages = parent::executeQuerySingle ('select count(*) from languages'); // str_format (localize("languages.alphabetical", count(array))
if ($nLanguages == 0) return NULL; return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES);
$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;
} }
public static function getLanguageById ($languageId) { public static function getLanguageById ($languageId) {

View file

@ -28,12 +28,8 @@ class Publisher extends Base {
} }
public static function getCount() { public static function getCount() {
$nPublishers = parent::executeQuerySingle ('select count(*) from publishers'); // str_format (localize("publishers.alphabetical", count(array))
if ($nPublishers == 0) return NULL; return parent::getCountGeneric ("publishers", self::ALL_PUBLISHERS_ID, parent::PAGE_ALL_PUBLISHERS);
$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;
} }
public static function getPublisherByBookId ($bookId) { public static function getPublisherByBookId ($bookId) {

View file

@ -30,11 +30,8 @@ class Rating extends Base {
} }
public static function getCount() { public static function getCount() {
$nRatings = parent::executeQuerySingle ('select count(*) from ratings'); // str_format (localize("ratings", count(array))
$entry = new Entry (localize("ratings.title"), self::ALL_RATING_ID, return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
str_format (localize("ratings", $nRatings), $nRatings), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS)));
return $entry;
} }
public static function getAllRatings() { public static function getAllRatings() {

View file

@ -28,12 +28,8 @@ class Serie extends Base {
} }
public static function getCount() { public static function getCount() {
$nSeries = parent::executeQuerySingle ('select count(*) from series'); // str_format (localize("series.alphabetical", count(array))
if ($nSeries == 0) return NULL; return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
$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;
} }
public static function getSerieByBookId ($bookId) { public static function getSerieByBookId ($bookId) {

View file

@ -28,12 +28,8 @@ class tag extends Base {
} }
public static function getCount() { public static function getCount() {
$nTags = parent::executeQuerySingle ('select count(*) from tags'); // str_format (localize("tags.alphabetical", count(array))
if ($nTags == 0) return NULL; return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
$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;
} }
public static function getTagById ($tagId) { public static function getTagById ($tagId) {