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,39 +15,39 @@ 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
|
||||||
* CustomizableObjectList objList = (CustomizableObjectList) itemList;
|
* CustomizableObjectList objList = (CustomizableObjectList) itemList;
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
* CategoryFilter catFilter = objList.addCategoryFilter("labelOfCatFilter", "rootCategory");
|
* CategoryFilter catFilter = objList.addCategoryFilter("labelOfCatFilter", "rootCategory");
|
||||||
* catFilter.setSeparator(";");
|
* catFilter.setSeparator(";");
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* {@link CustomizableObjectList#addCategoryFilter(java.lang.String, java.lang.String)} adds a
|
* {@link CustomizableObjectList#addCategoryFilter(java.lang.String, java.lang.String)} adds a
|
||||||
* category filter to the object list. The method requires two parameters: An identifier for the
|
* category filter to the object list. The method requires two parameters: An identifier for the
|
||||||
* label of the category filter (localisation for the label has to done in theme at the moment) and
|
* label of the category filter (localisation for the label has to done in theme at the moment) and
|
||||||
* the name of the root category of the category system to use for the filter.
|
* the name of the root category of the category system to use for the filter.
|
||||||
*
|
*
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
@ -80,12 +80,12 @@ public class CategoryFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for creating a category filter.
|
* Factory method for creating a category filter.
|
||||||
*
|
*
|
||||||
* @param label
|
* @param label
|
||||||
* @param categoryName
|
* @param categoryName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static CategoryFilter createCategoryFilter(final String label,
|
public static CategoryFilter createCategoryFilter(final String label,
|
||||||
final String categoryName) {
|
final String categoryName) {
|
||||||
final DataCollection collection = SessionManager.getSession().retrieve(
|
final DataCollection collection = SessionManager.getSession().retrieve(
|
||||||
Category.BASE_DATA_OBJECT_TYPE);
|
Category.BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
@ -115,21 +115,21 @@ 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
|
||||||
*/
|
*/
|
||||||
public void applyFilter(final DataCollection objects) {
|
public void applyFilter(final DataCollection objects) {
|
||||||
if (!values.isEmpty()) {
|
if (!values.isEmpty()) {
|
||||||
|
|
@ -191,8 +191,8 @@ public class CategoryFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the XML for the category filter.
|
* Creates the XML for the category filter.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Element getXml() {
|
public Element getXml() {
|
||||||
final Element filter = new Element("filter");
|
final Element filter = new Element("filter");
|
||||||
|
|
@ -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 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue