| 1 |
<?php // $Id$ |
<?php // $Id: votesmart.inc,v 1.1 2008/08/06 00:27:37 vauxia Exp $ |
| 2 |
|
|
| 3 |
function votesmart_settings() { |
function votesmart_settings() { |
| 4 |
$form = array(); |
$form = array(); |
| 5 |
$form['votesmart_host'] = array( |
$form['api'] = array( |
| 6 |
|
'#type' => 'fieldset', |
| 7 |
|
'#title' => ('API Settings'), |
| 8 |
|
'#collapsible' => TRUE, |
| 9 |
|
'#collapsed' => variable_get('votesmart_key', ''), |
| 10 |
|
); |
| 11 |
|
$form['api']['votesmart_host'] = array( |
| 12 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 13 |
'#title' => t('Votesmart API server'), |
'#title' => t('Votesmart API server'), |
| 14 |
'#description' => t(''), |
'#description' => t(''), |
| 15 |
'#default_value' => variable_get('votesmart_host', 'http://api.votesmart.org/'), |
'#default_value' => variable_get('votesmart_host', 'http://api.votesmart.org/'), |
| 16 |
); |
); |
| 17 |
$form['votesmart_key'] = array( |
$form['api']['votesmart_key'] = array( |
| 18 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 19 |
'#title' => t('Votesmart API key'), |
'#title' => t('Votesmart API key'), |
| 20 |
'#description' => t(''), |
'#description' => t(''), |
| 24 |
return system_settings_form($form); |
return system_settings_form($form); |
| 25 |
} |
} |
| 26 |
|
|
| 27 |
function votesmart_lists() { |
function _votesmart_field_values($table, $data) { |
| 28 |
|
$values = array(); |
| 29 |
|
// Make sure this is a valid table array. |
| 30 |
|
if (!isset($table['votesmart'])) $table = current(votesmart_tables($table)); |
| 31 |
|
|
| 32 |
|
foreach ($table['fields'] as $name => $info) { |
| 33 |
|
if ($key = $info['votesmart']) { |
| 34 |
|
if (isset($data[$key])) $values[$name] = (string) $data[$key]; |
| 35 |
|
} |
| 36 |
|
} |
| 37 |
|
return $values; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
function _votesmart_lists($filter = array()) { |
| 41 |
|
if ($filter && !is_array($filter)) $filter = array($filter); |
| 42 |
$lists = array(); |
$lists = array(); |
| 43 |
|
|
| 44 |
$lists['states'] = array( |
$lists['states'] = array( |
| 117 |
'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId', 'year', 'office'), 'bill'), |
'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId', 'year', 'office'), 'bill'), |
| 118 |
); |
); |
| 119 |
|
|
| 120 |
|
if ($filter) { |
| 121 |
|
$ret = array(); |
| 122 |
|
foreach ($filter as $list) { |
| 123 |
|
$ret[$list] = $lists[$list]; |
| 124 |
|
} |
| 125 |
|
return $ret; |
| 126 |
|
} |
| 127 |
|
|
| 128 |
return $lists; |
return $lists; |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
function votesmart_tables() { |
function _votesmart_tables($filter = array()) { |
| 132 |
|
if ($filter && !is_array($filter)) $filter = array($filter); |
| 133 |
$tables = array(); |
$tables = array(); |
| 134 |
$tables['address'] = array( |
$tables['address'] = array( |
| 135 |
); |
); |
| 403 |
); |
); |
| 404 |
$tables['sig'] = array( |
$tables['sig'] = array( |
| 405 |
'description' => t('Special interest group'), |
'description' => t('Special interest group'), |
| 406 |
'votesmart' => array('Rating.getSig', array('sigId'), 'sig'), |
'votesmart' => array('Rating.getSig', array('sigId')), |
| 407 |
'fields' => array( |
'fields' => array( |
| 408 |
'sig_id' => array( |
'sig_id' => array( |
| 409 |
'type' => 'integer', |
'type' => 'integer', |
| 499 |
$tables['vote'] = array( |
$tables['vote'] = array( |
| 500 |
); |
); |
| 501 |
|
|
| 502 |
|
if ($filter) { |
| 503 |
|
$ret = array(); |
| 504 |
|
foreach ($filter as $table) { |
| 505 |
|
$ret[$table] = $tables[$table]; |
| 506 |
|
} |
| 507 |
|
return $ret; |
| 508 |
|
} |
| 509 |
|
|
| 510 |
return $tables; |
return $tables; |
| 511 |
} |
} |