Grouped options in the Category filter (optional)
git-svn-id: https://svn.libreccm.org/ccm/trunk@2492 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
fb97ab3bb1
commit
1ecc9a57f1
|
|
@ -15,22 +15,22 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* 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
|
||||
* are managed as an additional category system. The include the filter into a customisable object
|
||||
* list are special JSP template is required.
|
||||
* to them. This filter is for example useful to filter objects after keywords. The keywords are
|
||||
* managed as an additional category system. The include the filter into a customisable object list
|
||||
* are special JSP template is required.
|
||||
*
|
||||
* First you have to add a customisable object list to the page by
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* <define:component name="itemList"
|
||||
* classname="com.arsdigita.navigation.ui.object.CustomizableObjectList"/>
|
||||
* }
|
||||
* </pre>
|
||||
* classname="com.arsdigita.navigation.ui.object.CustomizableObjectList"/> }
|
||||
* <
|
||||
* /pre>
|
||||
*
|
||||
* In a scriptlet block following your component definitions you have to set several parameters
|
||||
* for the object list (see {@link CustomizableObjectList}) To add and configure a category filter
|
||||
* to the list add these lines:
|
||||
* In a scriptlet block following your component definitions you have to set several parameters for
|
||||
* the object list (see {@link CustomizableObjectList}) To add and configure a category filter to
|
||||
* the list add these lines:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
|
|
@ -115,19 +115,19 @@ public class CategoryFilter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Apply the filter the {@link DataCollection} of the object list. The solution for the query
|
||||
* is a bit weird, due to limitations of PDL. The simple solution would be to use the
|
||||
* predefined query {@code objectIDsInMultipleSubtrees} from the {@code Category.pdl} of the
|
||||
* module as a subquery in the {@code where} clause, like this:
|
||||
* {@code WHERE parent.id ALL ($objectIDsInMultipleSubtrees)}. But PDL does not support
|
||||
* the {@code ALL} operator. So we have to use another solution. First we retrieve the IDs
|
||||
* of <emph>all</emph> objects assigned to each selected category using the
|
||||
* Apply the filter the {@link DataCollection} of the object list. The solution for the query is
|
||||
* a bit weird, due to limitations of PDL. The simple solution would be to use the predefined
|
||||
* query {@code objectIDsInMultipleSubtrees} from the {@code Category.pdl} of the module as a
|
||||
* subquery in the {@code where} clause, like this:
|
||||
* {@code WHERE parent.id ALL ($objectIDsInMultipleSubtrees)}. But PDL does not support the
|
||||
* {@code ALL} operator. So we have to use another solution. First we retrieve the IDs of
|
||||
* <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
|
||||
* 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
|
||||
* 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
|
||||
* with the ID {@code 0} this works.
|
||||
* as ID is added for this category. Because there will never be an object in the database with
|
||||
* the ID {@code 0} this works.
|
||||
*
|
||||
* @param objects
|
||||
*/
|
||||
|
|
@ -200,7 +200,7 @@ public class CategoryFilter {
|
|||
final Element invalid = new Element("invalid");
|
||||
boolean invalidFound = false;
|
||||
final StringBuffer searchString = new StringBuffer();
|
||||
final StringBuffer categoriesStr = new StringBuffer();
|
||||
//final StringBuffer categoriesStr = new StringBuffer();
|
||||
|
||||
filter.addAttribute("type", "categoryFilter");
|
||||
filter.addAttribute("label", label);
|
||||
|
|
@ -211,15 +211,19 @@ public class CategoryFilter {
|
|||
Category category;
|
||||
while (categories.next()) {
|
||||
category = categories.getCategory();
|
||||
addCategoryToFilter(categoriesElem, category, searchString);
|
||||
if (categoriesStr.length() > 0) {
|
||||
categoriesStr.append("; ");
|
||||
if (category.hasChildCategories()) {
|
||||
addCategoryGroupToFilter(categoriesElem, category, searchString);
|
||||
} 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("categoriesStr").setText(categoriesStr.toString());
|
||||
//filter.newChildElement("categoriesStr").setText(categoriesStr.toString());
|
||||
filter.newChildElement("separator").setText(separator);
|
||||
final Element multipleElem = filter.newChildElement("multiple");
|
||||
if (multiple) {
|
||||
|
|
@ -245,6 +249,19 @@ public class CategoryFilter {
|
|||
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,
|
||||
final Category category,
|
||||
final StringBuffer searchString) {
|
||||
|
|
@ -290,5 +307,4 @@ public class CategoryFilter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue