Commit 5ff25cc7 authored by David Lesieur's avatar David Lesieur

#256769 by kristyb2008: Added support for Computed field.

parent c30dc333
......@@ -18,6 +18,7 @@ The supported CCK field types are:
- User Reference
- Date
- Datestamp
- Computed Field
Requirements
......@@ -41,10 +42,13 @@ Installation
3. Enable any of the following modules, depending on the types of CCK fields you
wish to expose as facets:
- CCK Text Facets (for Text fields)
- CCK Number Facets (for Number fields)
- CCK Reference Facets (for Node Reference or User Reference fields)
- CCK Date Facets (for Date or Datestamp fields)
- CCK Text Facets (for Text fields).
- CCK Number Facets (for Number fields).
- CCK Reference Facets (for Node Reference or User Reference fields).
- CCK Date Facets (for Date or Datestamp fields).
- CCK Computed Facets (for Computed fields). Note that in order to be
accessible to CCK Computed Facets, a computed field must be configured to
store its values in the database.
Only the above types of fields are supported at the moment.
......
; $Id$
name = CCK Computed Facets
description = "Exposes CCK Computed fields as facets."
core = 6.x
dependencies[] = computed_field
dependencies[] = cck_facets
package = Faceted Search
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Exposes CCK Computed fields as facets.
*/
module_load_include('inc', 'cck_facets');
/**
* Implementation of hook_cck_facets_collect().
*/
function computed_facets_cck_facets_collect(&$facets, $field, $domain, $env, $arg = NULL) {
if ($field['type'] == 'computed' && $field['store']) {
switch ($domain) {
case 'facets':
$facets[] = new computed_facet($field);
break;
case 'text':
// Scan the given search text for a '{field_name}:"{value}"'
// token, and create facets from it.
if ($computed = faceted_search_quoted_query_extract($arg, $field['field_name'])) {
if (!empty($computed)) {
// Create an active facet with the value found in the search text.
$category = new cck_facet_category($field, $computed);
$facets[] = new computed_facet($field, array($category));
}
// Remove the parsed text
$arg = faceted_search_quoted_query_insert($arg, $field['field_name']);
}
break;
case 'node':
if (isset($arg->{$field['field_name']}) && is_array($arg->{$field['field_name']})) {
// Iterate through the field's multiple values.
foreach ($arg->{$field['field_name']} as $item) {
$value = array_shift($item);
if ($value != '') {
$category = new cck_facet_category($field, $value);
$facets[] = new computed_facet($field, array($category));
}
}
}
break;
}
}
return $arg;
}
/**
* A facet for CCK Computed fields.
*/
class computed_facet extends cck_facet {
function computed_facet($field, $active_path = array()) {
parent::cck_facet($field, $active_path);
}
function get_text() {
if ($category = $this->get_active_category()) {
// Quote and escape the value.
return '"'. faceted_search_quoted_query_escape($category->_value) .'"';
}
return '';
}
}
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