/[drupal]/contributions/modules/votesmart/votesmart.module
ViewVC logotype

Diff of /contributions/modules/votesmart/votesmart.module

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

revision 1.2, Sun Aug 10 01:42:51 2008 UTC revision 1.3, Sun Aug 17 15:36:33 2008 UTC
# Line 1  Line 1 
1  <?php // $Id: votesmart.module,v 1.1 2008/08/06 00:27:37 vauxia Exp $  <?php // $Id: votesmart.module,v 1.2 2008/08/10 01:42:51 vauxia Exp $
2    
3  /**  /**
4   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 28  function votesmart_perm() { Line 28  function votesmart_perm() {
28  }  }
29    
30  /**  /**
31   * Effect a function call to the votesmart API   * Effect a function call to the Vote Smart API.
32   */   */
33  function votesmart_api() {  function votesmart_api() {
34    require_once dirname(__FILE__) . '/votesmart.api.inc';    module_load_include('api.inc', 'votesmart');
35    $args = func_get_args();    $args = func_get_args();
36    return call_user_func_array('_votesmart_api', $args);    return call_user_func_array('_votesmart_api', $args);
37  }  }
38    
39  function votesmart_get_record($table, $id) {  /**
40     * Return a name->value list array from the Vote Smart API.
41     */
42    function votesmart_get_list($list, $values = array(), $sort = TRUE) {
43      $list = current(votesmart_lists($list));
44      $request = _votesmart_set_query($list['votesmart'], $values);
45      $data = call_user_func_array('votesmart_api', $request);
46      $items = array();
47      foreach ($data as $item) {
48        $item = (array) $item;
49        $items[$item[$list['id']]] = $item[$list['name']];
50      }
51      if ($sort) ksort($items);
52      return $items;
53    }
54    
55    /**
56     * Return a single record from the Vote Smart API.
57     */
58    function votesmart_get_record($table, $id, $extra = array()) {
59      $extra = array_merge($extra, array($table .'_id' => $id));
60    $table = current(votesmart_tables($table));    $table = current(votesmart_tables($table));
61    $request = $table['votesmart'];    $request = _votesmart_set_query($table['votesmart'], $extra);
   // TODO not the right way at all.  
   $keys = array();  
   foreach($request[1] as $name) $keys[$name] = $id;  
   $request[1] = $keys;  
62    $data = call_user_func_array('votesmart_api', $request);    $data = call_user_func_array('votesmart_api', $request);
63    return _votesmart_field_values($table, $data);    return _votesmart_field_values($table, $data);
64  }  }
65    
66  function votesmart_lists($filter = NULL) {  function votesmart_lists($filter = NULL) {
67    require_once dirname(__FILE__) . '/votesmart.inc';    module_load_include('inc', 'votesmart');
68    return _votesmart_lists($filter);    return _votesmart_lists($filter);
69  }  }
70    
71  function votesmart_tables($filter = NULL) {  function votesmart_tables($filter = NULL) {
72    require_once dirname(__FILE__) . '/votesmart.inc';    module_load_include('inc', 'votesmart');
73    return _votesmart_tables($filter);    return _votesmart_tables($filter);
74  }  }
75    
# Line 75  function votesmart_token_list($type = 'a Line 91  function votesmart_token_list($type = 'a
91    
92  function votesmart_token_values($type, $object = NULL, $options = array()) {  function votesmart_token_values($type, $object = NULL, $options = array()) {
93    $object = (object) $object;    $object = (object) $object;
94    $values = array();    $table  = str_replace('votesmart_', '', $type);
   $table = str_replace('votesmart_', '', $type);  
95    
96    if ($object->votesmart_id && $data = votesmart_get_record($table, $object->votesmart_id)) {    if ($object->votesmart_id) {
97        return votesmart_get_record($table, $object->votesmart_id);
98    }    }
   return $values;  
99  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2