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) {
$Urlfilter = getURLParam ("tag", "");
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);
}
}

View File

@ -81,6 +81,17 @@ function localize($phrase, $count=-1) {
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
{
const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail";

View File

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

View File

@ -139,7 +139,7 @@
/*
* 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