/[drupal]/contributions/modules/views_fastsearch/contrib/vfs_ranking_nodetype/vfs_ranking_nodetype.module
ViewVC logotype

Diff of /contributions/modules/views_fastsearch/contrib/vfs_ranking_nodetype/vfs_ranking_nodetype.module

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

revision 1.1, Thu Jan 17 04:51:33 2008 UTC revision 1.1.2.1, Thu Jan 17 04:51:33 2008 UTC
# Line 0  Line 1 
1    <?php
2    // $Id$
3    
4    /**
5     * Implement the search_ranking callback
6     *
7     * NOTE: this is a first draft
8     * - these might be better in include files, one per module
9     * - the array definition could be cleaned up
10     */
11    function vfs_ranking_nodetype_search_ranking() {
12      $ranking = array();
13    
14      // get the type weight
15      $ranking['node_rank_type'] = array(
16        'join' => 'LEFT JOIN {vfs_ranking_nodetype} nt ON nt.type = n.type',
17        'score' => 'i.score * nt.search_weight',
18      );
19    
20      return $ranking;
21    }
22    
23    function vfs_ranking_nodetype_menu($may_cache) {
24      $items = array();
25      if ($may_cache) {
26        $items[] = array(
27          'path' => 'admin/settings/vfs_ranking_nodetype',
28          'callback' => 'drupal_get_form',
29          'access' => array('administer search'),
30          'title' => 'Views Fast Search Node Rankings',
31          'description' => "Gives admins the ability to weight content types in searches",
32          'callback arguments' => array('vfs_ranking_nodetype_settings_form'),
33          'type' => MENU_NORMAL_ITEM,
34        );
35      }
36      return $items;
37    }
38    
39    function vfs_ranking_nodetype_settings_form() {
40      $form = array();
41      $form['#tree'] = true;
42      $weights = vfs_ranking_nodetype_get_weights();
43      foreach (node_get_types() as $type) {
44        $form['types'][$type->type] = $field = array (
45          '#title' => $type->name,
46          '#default_value' => $weights[$type->type],
47          '#type' => 'select',
48          '#options' => array_combine(range(0,10),range(0,10)),
49        );
50      }
51    
52      $form['submit'] = array ('#type' => 'submit','#value' => 'submit');
53      return $form;
54    }
55    
56    function vfs_ranking_nodetype_settings_form_submit($form_id,$form_values) {
57      foreach ($form_values['types'] as $type => $weight) {
58        db_query("INSERT INTO {vfs_ranking_nodetype} (type,search_weight) VALUES ('%s',%d)
59        ON DUPLICATE KEY
60        UPDATE search_weight = %d", $type,$weight,$weight);
61      }
62    }
63    
64    function vfs_ranking_nodetype_get_weights() {
65      $types = array();
66      $res = db_query('SELECT * from {vfs_ranking_nodetype}');
67      while ($row = db_fetch_object($res)) {
68        $types[$row->type] = $row->search_weight;
69      }
70      return $types;
71    }
72    
73    function theme_vfs_ranking_nodetype_settings_form($form) {
74      $output = drupal_render($form['info']);
75    
76      $header = array(t('Type'), t('Weight'));
77      foreach (element_children($form['types']) as $key) {
78        $row = array();
79        $row[] = $form['types'][$key]['#title'];
80        unset($form['types'][$key]['#title']);
81        $row[] = drupal_render($form['types'][$key]);
82        $rows[] = $row;
83      }
84      $output .= theme('table', $header, $rows);
85      $output .= drupal_render($form);
86      return $output;
87    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2