Centralize some of the database function (linked to the normalized search). re #48, #49

This commit is contained in:
Sébastien Lucas 2014-05-28 16:13:57 +02:00
vanhempi 81fbe584db
commit 9aee96d7e2
8 muutettua tiedostoa jossa 12 lisäystä ja 9 poistoa

Näytä tiedosto

@ -39,7 +39,7 @@ class Author extends Base {
} }
public static function getCount() { 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, $entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID,
str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text", str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS)));

Näytä tiedosto

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

Näytä tiedosto

@ -428,13 +428,12 @@ class Book extends Base {
} }
public static function getBookCount($database = NULL) { public static function getBookCount($database = NULL) {
$nBooks = parent::getDb ($database)->query('select count(*) from books')->fetchColumn(); return parent::executeQuerySingle ('select count(*) from books', $database);
return $nBooks;
} }
public static function getCount() { public static function getCount() {
global $config; global $config;
$nBooks = parent::getDb ()->query('select count(*) from books')->fetchColumn(); $nBooks = parent::executeQuerySingle ('select count(*) from books');
$result = array(); $result = array();
$entry = new Entry (localize ("allbooks.title"), $entry = new Entry (localize ("allbooks.title"),
self::ALL_BOOKS_ID, self::ALL_BOOKS_ID,

Näytä tiedosto

@ -36,7 +36,7 @@ class language extends Base {
} }
public static function getCount() { 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; if ($nLanguages == 0) return NULL;
$entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text",

Näytä tiedosto

@ -28,7 +28,7 @@ class Publisher extends Base {
} }
public static function getCount() { 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; if ($nPublishers == 0) return NULL;
$entry = new Entry (localize("publishers.title"), self::ALL_PUBLISHERS_ID, $entry = new Entry (localize("publishers.title"), self::ALL_PUBLISHERS_ID,
str_format (localize("publishers.alphabetical", $nPublishers), $nPublishers), "text", str_format (localize("publishers.alphabetical", $nPublishers), $nPublishers), "text",

Näytä tiedosto

@ -30,7 +30,7 @@ class Rating extends Base {
} }
public static function getCount() { 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, $entry = new Entry (localize("ratings.title"), self::ALL_RATING_ID,
str_format (localize("ratings", $nRatings), $nRatings), "text", str_format (localize("ratings", $nRatings), $nRatings), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS)));

Näytä tiedosto

@ -28,7 +28,7 @@ class Serie extends Base {
} }
public static function getCount() { 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; if ($nSeries == 0) return NULL;
$entry = new Entry (localize("series.title"), self::ALL_SERIES_ID, $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
str_format (localize("series.alphabetical", $nSeries), $nSeries), "text", str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",

Näytä tiedosto

@ -28,7 +28,7 @@ class tag extends Base {
} }
public static function getCount() { 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; if ($nTags == 0) return NULL;
$entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID,
str_format (localize("tags.alphabetical", $nTags), $nTags), "text", str_format (localize("tags.alphabetical", $nTags), $nTags), "text",