annotate 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
rev   line source
franck@0 1 <?php
franck@0 2 // $Id: og_statistics.faceted_search.inc,v 1.2 2009/05/29 16:46:25 dereine Exp $
franck@0 3
franck@0 4 /**
franck@0 5 * @file
franck@0 6 * Integration of og_statistics into faceted_search.
franck@0 7 */
franck@0 8
franck@0 9 /**
franck@0 10 * Implementation of hook_form_alter().
franck@0 11 */
franck@0 12 function og_statistics_form_faceted_search_edit_form_alter(&$form, &$form_state) {
franck@0 13 $env_id = $form['env_id']['#value'];
franck@0 14 // drupal_set_message('Faceted_search alter :'.var_export($form['info'], true));
franck@0 15 $form['info']['name']['#weight'] = -5;
franck@0 16 $form['info']['title']['#weight'] = -4;
franck@0 17 $form['info']['description']['#weight'] = -3;
franck@0 18 $form['info']['types']['#weight'] = -2;
franck@0 19 $form['info']['og_statistics_sort'] = array(
franck@0 20 '#type' => 'checkbox',
franck@0 21 '#title' => t('Sort by number of group nodes'),
franck@0 22 '#default_value' => faceted_search_variable_get($env_id, 'og_statistics_sort', FALSE),
franck@0 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.'),
franck@0 24 '#weight' => -1,
franck@0 25 );
franck@0 26 }
franck@0 27 }
franck@0 28
franck@0 29 /**
franck@0 30 * Implementation of hook_faceted_search_query_alter().
franck@0 31 *
franck@0 32 * This is quite late in the sequence, but were altering a facet
franck@0 33 * (the content-type one) rather than making a new one we could hook
franck@0 34 * in the sort(s) to.
franck@0 35 * @todo I guess there is a much better way of doing this! Like
franck@0 36 * maybe inheriting content-type facet and extending it and making it
franck@0 37 * sort an option?
franck@0 38 */
franck@0 39 function og_statistics_faceted_search_query_alter($search, &$query) {
franck@0 40 if (faceted_search_variable_get($search->_env_id, 'og_statistics_sort', FALSE)) { // change for a variable
franck@0 41 $query->tables['default']['c']['table'] = 'og_statistics';
franck@0 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)';
franck@0 43 }
franck@0 44 }
franck@0 45