Commit 7addc9d4 authored by David Lesieur's avatar David Lesieur

Properly handle cases where category objects cannot be created.

parent 18117832
......@@ -56,8 +56,9 @@ function cck_facets_faceted_search_collect(&$facets, $domain, $env_id, $filter,
foreach ($fields as $field) {
if ((!isset($filter) || isset($filter['cck'][$field['field_name']])) && isset($arg->{$field['field_name']}) && is_array($arg->{$field['field_name']})) {
foreach ($arg->{$field['field_name']} as $item) {
$active_path = cck_facets_create_category($field, $item);
$facets[] = cck_facets_create_facet($field, $active_path);
if ($active_path = cck_facets_create_category($field, $item)) {
$facets[] = cck_facets_create_facet($field, $active_path);
}
}
}
}
......@@ -113,16 +114,16 @@ function cck_facets_create_facet_default($field, $active_path) {
* @param $count
* Optional. The number of nodes associated to this category within the
* current search.
* @param $full_active_path
* @param $get_path
* Optional. For some field types (such as dates), a single value might be
* represented by a path of categories (e.g. yyyy > yyyy-mm > yyyy-mm-dd).
* When $full_active_path is TRUE, the full path corresponding to $value is to
* be returned, otherwise only the "leaf" category gets returned.
* When $get_path is TRUE, the full path corresponding to $value is to be
* returned, otherwise only the "leaf" category gets returned.
* @return
* Single category object (if $path was TRUE), an array of categories
* otherwise, or NULL if the category could not be created.
*/
function cck_facets_create_category($field, $value, $count = NULL, $full_active_path = TRUE) {
function cck_facets_create_category($field, $value, $count = NULL, $get_path = TRUE) {
static $factories = NULL;
if (!isset($factories)) {
$factories = module_invoke_all('cck_facets_factory', 'category');
......@@ -134,7 +135,7 @@ function cck_facets_create_category($field, $value, $count = NULL, $full_active_
// No specialized factory found for the given field type.
$factory = 'cck_facets_create_category_default';
}
return $factory($field, $value, $count, $full_active_path);
return $factory($field, $value, $count, $get_path);
}
/**
......@@ -142,7 +143,7 @@ function cck_facets_create_category($field, $value, $count = NULL, $full_active_
*
* @see cck_facets_create_category
*/
function cck_facets_create_category_default($field, $value, $count, $full_active_path) {
function cck_facets_create_category_default($field, $value, $count, $get_path) {
$db_info = _cck_facets_db_info($field);
$column = reset($db_info['columns']); // Get the first database column. Other columns are ignored.
if (is_array($value)) {
......@@ -157,7 +158,7 @@ function cck_facets_create_category_default($field, $value, $count, $full_active
}
}
$category = new cck_facet_category($field, $value, $count);
return $full_active_path ? array($category) : $category;
return $get_path ? array($category) : $category;
}
/**
......@@ -295,7 +296,9 @@ class cck_facet extends faceted_search_facet {
$categories = array();
while ($result = db_fetch_object($results)) {
// Add a new category.
$categories[] = cck_facets_create_category($this->_field, array($key => $result->{$field_alias}), $result->count, FALSE);
if ($category = cck_facets_create_category($this->_field, array($key => $result->{$field_alias}), $result->count, FALSE)) {
$categories[] = $category;
}
}
return $categories;
}
......
......@@ -24,9 +24,11 @@ function reference_facets_cck_facets_factory($type) {
}
/**
* Create category for the specified field value.
* Create category, or a path of categories for the specified field value.
*
* @see cck_facets_create_category
*/
function reference_facets_create_category($field, $value, $count = NULL, $category_path = TRUE) {
function reference_facets_create_category($field, $value, $count = NULL, $get_path = TRUE) {
$db_info = _cck_facets_db_info($field);
$column = reset($db_info['columns']); // Get the first database column. Other columns are ignored.
if (is_array($value)) {
......@@ -34,14 +36,12 @@ function reference_facets_create_category($field, $value, $count = NULL, $catego
$key = key($db_info['columns']);
$value = $value[$key];
}
else {
// Perform basic validation on user-specified value.
if (!is_numeric($value)) {
return FALSE;
}
// Perform basic validation on user-specified value.
if (is_numeric($value) && $value > 0) {
$category = new reference_facet_category($field, $value, $count);
return $get_path ? array($category) : $category;
}
$category = new reference_facet_category($field, $value, $count);
return $category_path ? array($category) : $category;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment