Refactor the detection of the case when no database has been selected. re #127

This commit is contained in:
Sébastien Lucas 2013-12-14 11:30:42 +01:00
parent 8a3cc9ed5c
commit a1cb83eea9
4 changed files with 12 additions and 11 deletions

View file

@ -453,8 +453,7 @@ class Page
global $config;
$this->title = $config['cops_title_default'];
$this->subtitle = $config['cops_subtitle_default'];
$database = GetUrlParam (DB);
if (is_array ($config['calibre_directory']) && is_null ($database)) {
if (Base::noDatabaseSelected ()) {
$i = 0;
foreach (array_keys ($config['calibre_directory']) as $key) {
$nBooks = Book::getBookCount ($i);
@ -484,7 +483,7 @@ class Page
}
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
if (!is_null ($database)) $this->title = Base::getDbName ();
if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName ();
}
}
@ -739,7 +738,7 @@ class PageQueryResult extends Page
$crit = "%" . $this->query . "%";
// Special case when we are doing a search and no database is selected
if (is_array ($config['calibre_directory']) && is_null (GetUrlParam (DB))) {
if (Base::noDatabaseSelected ()) {
$i = 0;
foreach ($config['calibre_directory'] as $key => $value) {
Base::clearDb ();
@ -893,6 +892,10 @@ abstract class Base
return is_array ($config['calibre_directory']);
}
public static function noDatabaseSelected () {
return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
}
public static function getDbList () {
global $config;
if (self::isMultipleDatabaseEnabled ()) {

View file

@ -631,7 +631,6 @@ function getJson ($complete = false) {
$page = getURLParam ("page", Base::PAGE_INDEX);
$query = getURLParam ("query");
$search = getURLParam ("search");
$multi = getURLParam ("multi");
$qid = getURLParam ("id");
$n = getURLParam ("n", "1");
$database = GetUrlParam (DB);
@ -641,7 +640,7 @@ function getJson ($complete = false) {
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
// Special case when no databases were chosen, we search on all databases
if (is_array ($config['calibre_directory']) && $multi === "1") {
if (Base::noDatabaseSelected ()) {
$i = 0;
foreach (array_keys ($config['calibre_directory']) as $key) {
Base::clearDb ();

View file

@ -33,7 +33,7 @@
// Access the database ASAP to be sure it's readable, redirect if that's not the case.
// It has to be done before any header is sent.
if (is_array ($config['calibre_directory']) && is_null ($database)) {
if (Base::noDatabaseSelected ()) {
$i = 0;
foreach (array_keys ($config['calibre_directory']) as $key) {
$test = Base::getDb ($i);

View file

@ -280,13 +280,12 @@ updatePage = function (data) {
limit: 24,
template: templateSuggestion,
remote: {
url: 'getJSON.php?search=1&db=%DB&query=%QUERY&multi=%MULTI',
url: 'getJSON.php?search=1&db=%DB&query=%QUERY',
replace: function (url, query) {
var multi = 0;
if (currentData.multipleDatabase === 1 && currentData.databaseId === "") {
multi = 1;
return url.replace('%QUERY', query).replace('&db=%DB', "")
}
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId).replace ("%MULTI", multi);
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId);
}
}
}