Commit 04906794 authored by David Lesieur's avatar David Lesieur

Refactored nodereference/userreference facets.

parent 10b29059
; $Id$
name = Node Reference Facets
description = "Provides facets based on Node Reference fields."
name = Reference Facets
description = "Provides facets based on Node Reference and User Reference fields."
dependencies = content faceted_search cck_facets search
package = Faceted Search
......@@ -3,7 +3,7 @@
/**
* @file
* Provides facets based on Node Reference fields.
* Provides facets based on Node Reference and User Reference fields.
*/
/**
......@@ -14,28 +14,31 @@
* @return
* Array of factory functions keyed by field type.
*/
function nodereference_facets_cck_facets_factory($type) {
function reference_facets_cck_facets_factory($type) {
if ($type == 'category') {
return array('nodereference' => 'nodereference_facets_create_category');
return array(
'nodereference' => 'reference_facets_create_category',
'userreference' => 'reference_facets_create_category',
);
}
}
/**
* Create category for the specified field value.
*/
function nodereference_facets_create_category($field, $value, $count = NULL, $category_path = TRUE) {
$category = new nodereference_facet_category($field, $value, $count);
function reference_facets_create_category($field, $value, $count = NULL, $category_path = TRUE) {
$category = new reference_facet_category($field, $value, $count);
return $category_path ? array($category) : $category;
}
/**
* A facet category for Node Reference fields.
* A facet category for Node Reference and User Reference fields.
*/
class nodereference_facet_category extends cck_facet_category {
class reference_facet_category extends cck_facet_category {
/**
* Constructor.
*/
function nodereference_facet_category($field, $value, $count = NULL) {
function reference_facet_category($field, $value, $count = NULL) {
parent::cck_facet_category($field, $value, $count);
}
......
; $Id$
name = User Reference Facets
description = "Provides facets based on User Reference fields."
dependencies = content faceted_search cck_facets search
package = Faceted Search
<?php
// $Id$
/**
* @file
* Provides facets based on User Reference fields.
*/
/**
* Implementation of hook_cck_facets_factory().
*
* @param $type
* Type of object to create, either 'facet' or 'category'.
* @return
* Array of factory functions keyed by field type.
*/
function userreference_facets_cck_facets_factory($type) {
if ($type == 'category') {
return array('userreference' => 'userreference_facets_create_category');
}
}
/**
* Create category for the specified field value.
*/
function userreference_facets_create_category($field, $value, $count = NULL, $category_path = TRUE) {
$category = new userreference_facet_category($field, $value, $count);
return $category_path ? array($category) : $category;
}
/**
* A facet category for User Reference fields.
*/
class userreference_facet_category extends cck_facet_category {
/**
* Constructor.
*/
function userreference_facet_category($field, $value, $count = NULL) {
parent::cck_facet_category($field, $value, $count);
}
/**
* Return the label of this category.
*
* @param $html
* TRUE when HTML is allowed in the label, FALSE otherwise. Checking this
* flag allows implementors to provide a rich-text label if desired, and an
* alternate plain text version for cases where HTML cannot be used. The
* implementor is responsible to ensure adequate security filtering.
*/
function get_label($html = FALSE) {
$db_info = content_database_info($this->_field);
reset($db_info['columns']); // Get the first database column. Other columns are ignored!
$column_name = key($db_info['columns']); // Get the column name (required for the formatter).
// Get the label using the 'plain' formatter.
$label = content_format($this->_field['field_name'], array($column_name => $this->_value), 'plain');
// Note: The label is already filtered by the CCK formatter and does not
// need to be checked here.
return $html ? $label : strip_tags($label);
}
}
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