Small fixes to facets handling. re #21

* Fix ths duplicate of URL parameter
  * Fix when parameter is empty
This commit is contained in:
Sébastien Lucas 2013-01-20 08:30:41 +01:00
parent e5d0933971
commit 11645b2155
4 changed files with 14 additions and 3 deletions

View file

@ -133,7 +133,7 @@ class OPDSRenderer
if ($page->containsBook () && !is_null ($config['cops_books_filter']) && count ($config['cops_books_filter']) > 0) { if ($page->containsBook () && !is_null ($config['cops_books_filter']) && count ($config['cops_books_filter']) > 0) {
$Urlfilter = getURLParam ("tag", ""); $Urlfilter = getURLParam ("tag", "");
foreach ($config['cops_books_filter'] as $lib => $filter) { foreach ($config['cops_books_filter'] as $lib => $filter) {
$link = new LinkFacet ("?" . $_SERVER['QUERY_STRING'] . "&tag=" . $filter, $lib, localize ("tagword.title"), $filter == $Urlfilter); $link = new LinkFacet ("?" . addURLParameter ($_SERVER['QUERY_STRING'], "tag", $filter), $lib, localize ("tagword.title"), $filter == $Urlfilter);
self::renderLink ($link); self::renderLink ($link);
} }
} }

View file

@ -81,6 +81,17 @@ function localize($phrase, $count=-1) {
return $translations[$phrase]; return $translations[$phrase];
} }
function addURLParameter($urlParams, $paramName, $paramValue) {
$params = array();
parse_str($urlParams, $params);
if (empty ($paramValue)) {
unset ($params[$paramName]);
} else {
$params[$paramName] = $paramValue;
}
return http_build_query($params);
}
class Link class Link
{ {
const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail"; const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail";

View file

@ -119,7 +119,7 @@ class Book extends Base {
public function getFilterString () { public function getFilterString () {
$filter = getURLParam ("tag", NULL); $filter = getURLParam ("tag", NULL);
if (is_null ($filter)) return ""; if (empty ($filter)) return "";
$exists = true; $exists = true;
if (preg_match ("/^!(.*)$/", $filter, $matches)) { if (preg_match ("/^!(.*)$/", $filter, $matches)) {

View file

@ -139,7 +139,7 @@
/* /*
* Filter on tags to book list * Filter on tags to book list
*/ */
$config['cops_books_filter'] = array ("Non lus" => "!Read", "lus" => "Read"); $config['cops_books_filter'] = array ("Tout" => "", "Non lus" => "!Read", "lus" => "Read");
/* /*
* Custom Columns to add as an array containing the lookup names * Custom Columns to add as an array containing the lookup names