Grouped options in the Category filter (optional)

git-svn-id: https://svn.libreccm.org/ccm/trunk@2492 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-01-17 13:59:35 +00:00
parent fb97ab3bb1
commit 1ecc9a57f1
1 changed files with 60 additions and 44 deletions

View File

@ -15,22 +15,22 @@ import java.util.Map;
/** /**
* This filter allows it to filter the objects in a customisable object list by categories assigned * This filter allows it to filter the objects in a customisable object list by categories assigned
* to them. This filter is for example useful to filter objects after keywords. The keywords * to them. This filter is for example useful to filter objects after keywords. The keywords are
* are managed as an additional category system. The include the filter into a customisable object * managed as an additional category system. The include the filter into a customisable object list
* list are special JSP template is required. * are special JSP template is required.
* *
* First you have to add a customisable object list to the page by * First you have to add a customisable object list to the page by
* *
* <pre> * <pre>
* {@code * {@code
* <define:component name="itemList" * <define:component name="itemList"
* classname="com.arsdigita.navigation.ui.object.CustomizableObjectList"/> * classname="com.arsdigita.navigation.ui.object.CustomizableObjectList"/> }
* } * <
* </pre> * /pre>
* *
* In a scriptlet block following your component definitions you have to set several parameters * In a scriptlet block following your component definitions you have to set several parameters for
* for the object list (see {@link CustomizableObjectList}) To add and configure a category filter * the object list (see {@link CustomizableObjectList}) To add and configure a category filter to
* to the list add these lines: * the list add these lines:
* *
* <pre> * <pre>
* {@code * {@code
@ -115,19 +115,19 @@ public class CategoryFilter {
} }
/** /**
* Apply the filter the {@link DataCollection} of the object list. The solution for the query * Apply the filter the {@link DataCollection} of the object list. The solution for the query is
* is a bit weird, due to limitations of PDL. The simple solution would be to use the * a bit weird, due to limitations of PDL. The simple solution would be to use the predefined
* predefined query {@code objectIDsInMultipleSubtrees} from the {@code Category.pdl} of the * query {@code objectIDsInMultipleSubtrees} from the {@code Category.pdl} of the module as a
* module as a subquery in the {@code where} clause, like this: * subquery in the {@code where} clause, like this:
* {@code WHERE parent.id ALL ($objectIDsInMultipleSubtrees)}. But PDL does not support * {@code WHERE parent.id ALL ($objectIDsInMultipleSubtrees)}. But PDL does not support the
* the {@code ALL} operator. So we have to use another solution. First we retrieve the IDs * {@code ALL} operator. So we have to use another solution. First we retrieve the IDs of
* of <emph>all</emph> objects assigned to each selected category using the * <emph>all</emph> objects assigned to each selected category using the
* {@code objectIDsInSubtree} query. Using this IDs we build a long filter. For each selected * {@code objectIDsInSubtree} query. Using this IDs we build a long filter. For each selected
* category there is an segment like this: {@code (parent.id IN (1,2,3,4)} The IDs for the * category there is an segment like this: {@code (parent.id IN (1,2,3,4)} The IDs for the
* {@code IN} operator a the ones with the IDs of all objects in category. All segments are * {@code IN} operator a the ones with the IDs of all objects in category. All segments are
* combined with {@code AND}. If no items are assigned to a category, a segment with {@code 0} * combined with {@code AND}. If no items are assigned to a category, a segment with {@code 0}
* as ID is added for this category. Because there will never be an object in the database * as ID is added for this category. Because there will never be an object in the database with
* with the ID {@code 0} this works. * the ID {@code 0} this works.
* *
* @param objects * @param objects
*/ */
@ -200,7 +200,7 @@ public class CategoryFilter {
final Element invalid = new Element("invalid"); final Element invalid = new Element("invalid");
boolean invalidFound = false; boolean invalidFound = false;
final StringBuffer searchString = new StringBuffer(); final StringBuffer searchString = new StringBuffer();
final StringBuffer categoriesStr = new StringBuffer(); //final StringBuffer categoriesStr = new StringBuffer();
filter.addAttribute("type", "categoryFilter"); filter.addAttribute("type", "categoryFilter");
filter.addAttribute("label", label); filter.addAttribute("label", label);
@ -211,15 +211,19 @@ public class CategoryFilter {
Category category; Category category;
while (categories.next()) { while (categories.next()) {
category = categories.getCategory(); category = categories.getCategory();
addCategoryToFilter(categoriesElem, category, searchString); if (category.hasChildCategories()) {
if (categoriesStr.length() > 0) { addCategoryGroupToFilter(categoriesElem, category, searchString);
categoriesStr.append("; "); } else {
addCategoryToFilter(categoriesElem, category, searchString);
// if (categoriesStr.length() > 0) {
// categoriesStr.append("; ");
// }
// categoriesStr.append('"').append(category.getName()).append('"');
} }
categoriesStr.append('"').append(category.getName()).append('"');
} }
filter.newChildElement("searchString").setText(searchString.toString()); filter.newChildElement("searchString").setText(searchString.toString());
filter.newChildElement("categoriesStr").setText(categoriesStr.toString()); //filter.newChildElement("categoriesStr").setText(categoriesStr.toString());
filter.newChildElement("separator").setText(separator); filter.newChildElement("separator").setText(separator);
final Element multipleElem = filter.newChildElement("multiple"); final Element multipleElem = filter.newChildElement("multiple");
if (multiple) { if (multiple) {
@ -245,6 +249,19 @@ public class CategoryFilter {
return filter; return filter;
} }
private void addCategoryGroupToFilter(final Element parent,
final Category category,
final StringBuffer searchString) {
final Element elem = parent.newChildElement("categoryGroup");
elem.addAttribute("label", category.getName());
final CategoryCollection childs = category.getChildren();
while(childs.next()) {
final Category child = childs.getCategory();
addCategoryToFilter(elem, child, searchString);
}
}
private void addCategoryToFilter(final Element parent, private void addCategoryToFilter(final Element parent,
final Category category, final Category category,
final StringBuffer searchString) { final StringBuffer searchString) {
@ -290,5 +307,4 @@ public class CategoryFilter {
} }
} }
} }
} }