/[drupal]/contributions/modules/cck_facets/computed_facets.module
ViewVC logotype

Contents of /contributions/modules/cck_facets/computed_facets.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri May 1 20:35:18 2009 UTC (6 months, 3 weeks ago) by davidlesieur
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +5 -7 lines
File MIME type: text/x-php
Fixed empty result set when search key value is 0.
1 <?php
2 // $Id: computed_facets.module,v 1.1 2009/05/01 20:22:10 davidlesieur Exp $
3
4 /**
5 * @file
6 * Exposes CCK Computed fields as facets.
7 */
8
9 module_load_include('inc', 'cck_facets');
10
11 /**
12 * Implementation of hook_cck_facets_collect().
13 */
14 function computed_facets_cck_facets_collect(&$facets, $field, $domain, $env, $arg = NULL) {
15 if ($field['type'] == 'computed' && $field['store']) {
16 switch ($domain) {
17 case 'facets':
18 $facets[] = new computed_facet($field);
19 break;
20
21 case 'text':
22 // Scan the given search text for a '{field_name}:"{value}"'
23 // token, and create facets from it.
24 if (!is_null($computed = faceted_search_quoted_query_extract($arg, $field['field_name']))) {
25 // Create an active facet with the value found in the search text.
26 $category = new cck_facet_category($field, $computed);
27 $facets[] = new computed_facet($field, array($category));
28 // Remove the parsed text
29 $arg = faceted_search_quoted_query_insert($arg, $field['field_name']);
30 }
31 break;
32
33 case 'node':
34 if (isset($arg->{$field['field_name']}) && is_array($arg->{$field['field_name']})) {
35 // Iterate through the field's multiple values.
36 foreach ($arg->{$field['field_name']} as $item) {
37 $value = array_shift($item);
38 if ($value != '') {
39 $category = new cck_facet_category($field, $value);
40 $facets[] = new computed_facet($field, array($category));
41 }
42 }
43 }
44 break;
45 }
46 }
47 return $arg;
48 }
49
50 /**
51 * A facet for CCK Computed fields.
52 */
53 class computed_facet extends cck_facet {
54
55 function computed_facet($field, $active_path = array()) {
56 parent::cck_facet($field, $active_path);
57 }
58
59 function get_text() {
60 if ($category = $this->get_active_category()) {
61 // Quote and escape the value.
62 return '"'. faceted_search_quoted_query_escape($category->_value) .'"';
63 }
64 return '';
65 }
66 }

  ViewVC Help
Powered by ViewVC 1.1.2