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

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

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


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

  ViewVC Help
Powered by ViewVC 1.1.2