franck@0
|
1 <?php |
franck@2
|
2 // $Id: og_statistics.faceted_search.inc,v 1.2.2.1 2009/08/12 19:56:41 dereine Exp $ |
franck@0
|
3 |
franck@0
|
4 /** |
franck@0
|
5 * @file |
franck@0
|
6 * Integration of og_statistics into faceted_search. |
franck@2
|
7 * |
franck@2
|
8 * @TODO |
franck@2
|
9 * Add every statistic field for the sort availible. |
franck@0
|
10 */ |
franck@0
|
11 |
franck@0
|
12 /** |
franck@0
|
13 * Implementation of hook_form_alter(). |
franck@0
|
14 */ |
franck@0
|
15 function og_statistics_form_faceted_search_edit_form_alter(&$form, &$form_state) { |
franck@0
|
16 $env_id = $form['env_id']['#value']; |
franck@0
|
17 // drupal_set_message('Faceted_search alter :'.var_export($form['info'], true)); |
franck@0
|
18 $form['info']['name']['#weight'] = -5; |
franck@0
|
19 $form['info']['title']['#weight'] = -4; |
franck@0
|
20 $form['info']['description']['#weight'] = -3; |
franck@0
|
21 $form['info']['types']['#weight'] = -2; |
franck@0
|
22 $form['info']['og_statistics_sort'] = array( |
franck@0
|
23 '#type' => 'checkbox', |
franck@0
|
24 '#title' => t('Sort by number of group nodes'), |
franck@0
|
25 '#default_value' => faceted_search_variable_get($env_id, 'og_statistics_sort', FALSE), |
franck@0
|
26 '#description' => t('If <em>only</em> searching group content types enables sorting by the most recent node added to the group, rather than comment added to the group node itself.'), |
franck@0
|
27 '#weight' => -1, |
franck@0
|
28 ); |
franck@0
|
29 } |
franck@0
|
30 } |
franck@0
|
31 |
franck@0
|
32 /** |
franck@0
|
33 * Implementation of hook_faceted_search_query_alter(). |
franck@0
|
34 * |
franck@0
|
35 * This is quite late in the sequence, but were altering a facet |
franck@0
|
36 * (the content-type one) rather than making a new one we could hook |
franck@0
|
37 * in the sort(s) to. |
franck@0
|
38 * @todo I guess there is a much better way of doing this! Like |
franck@0
|
39 * maybe inheriting content-type facet and extending it and making it |
franck@0
|
40 * sort an option? |
franck@0
|
41 */ |
franck@0
|
42 function og_statistics_faceted_search_query_alter($search, &$query) { |
franck@0
|
43 if (faceted_search_variable_get($search->_env_id, 'og_statistics_sort', FALSE)) { // change for a variable |
franck@0
|
44 $query->tables['default']['c']['table'] = 'og_statistics'; |
franck@0
|
45 $query->fields['default']['score']['field'] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_node_timestamp)) - %d) * 6.43e-8)'; |
franck@0
|
46 } |
franck@0
|
47 } |
franck@0
|
48 |