Mercurial > defr > drupal > og_statistics
comparison og_statistics.faceted_search.inc @ 0:9ce879ecbce6
OG Stats beta 3
author | Franck Deroche <franck@defr.org> |
---|---|
date | Tue, 24 Nov 2009 14:25:13 +0100 |
parents | |
children | 48f07e7acaca |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9ce879ecbce6 |
---|---|
1 <?php | |
2 // $Id: og_statistics.faceted_search.inc,v 1.2 2009/05/29 16:46:25 dereine Exp $ | |
3 | |
4 /** | |
5 * @file | |
6 * Integration of og_statistics into faceted_search. | |
7 */ | |
8 | |
9 /** | |
10 * Implementation of hook_form_alter(). | |
11 */ | |
12 function og_statistics_form_faceted_search_edit_form_alter(&$form, &$form_state) { | |
13 $env_id = $form['env_id']['#value']; | |
14 // drupal_set_message('Faceted_search alter :'.var_export($form['info'], true)); | |
15 $form['info']['name']['#weight'] = -5; | |
16 $form['info']['title']['#weight'] = -4; | |
17 $form['info']['description']['#weight'] = -3; | |
18 $form['info']['types']['#weight'] = -2; | |
19 $form['info']['og_statistics_sort'] = array( | |
20 '#type' => 'checkbox', | |
21 '#title' => t('Sort by number of group nodes'), | |
22 '#default_value' => faceted_search_variable_get($env_id, 'og_statistics_sort', FALSE), | |
23 '#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.'), | |
24 '#weight' => -1, | |
25 ); | |
26 } | |
27 } | |
28 | |
29 /** | |
30 * Implementation of hook_faceted_search_query_alter(). | |
31 * | |
32 * This is quite late in the sequence, but were altering a facet | |
33 * (the content-type one) rather than making a new one we could hook | |
34 * in the sort(s) to. | |
35 * @todo I guess there is a much better way of doing this! Like | |
36 * maybe inheriting content-type facet and extending it and making it | |
37 * sort an option? | |
38 */ | |
39 function og_statistics_faceted_search_query_alter($search, &$query) { | |
40 if (faceted_search_variable_get($search->_env_id, 'og_statistics_sort', FALSE)) { // change for a variable | |
41 $query->tables['default']['c']['table'] = 'og_statistics'; | |
42 $query->fields['default']['score']['field'] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_node_timestamp)) - %d) * 6.43e-8)'; | |
43 } | |
44 } | |
45 |