| 1 |
<?php // $Id: votesmart_factory.inc,v 1.2 2008/08/10 01:42:51 vauxia Exp $ |
<?php // $Id: votesmart_factory.inc,v 1.3 2008/08/17 15:36:33 vauxia Exp $ |
| 2 |
|
|
| 3 |
function votesmart_factory() { |
function votesmart_factory() { |
| 4 |
require_once(drupal_get_path('module', 'votesmart') .'/votesmart.inc'); |
require_once(drupal_get_path('module', 'votesmart') .'/votesmart.inc'); |
| 10 |
$lists = votesmart_lists(); |
$lists = votesmart_lists(); |
| 11 |
|
|
| 12 |
//print_r(votesmart_api('Election.getElectionByYearState', array('year' => 2008))); |
//print_r(votesmart_api('Election.getElectionByYearState', array('year' => 2008))); |
| 13 |
|
//print_r(votesmart_api('Election.getElectionByYearState', array('year' => 2008, 'stateId' => 'MN'))); |
| 14 |
//print_r(votesmart_api('Office.getOfficesByBranchLevel', array('branchId' => 'L', 'levelId' => 'L'))); |
//print_r(votesmart_api('Office.getOfficesByBranchLevel', array('branchId' => 'L', 'levelId' => 'L'))); |
| 15 |
//print_r(votesmart_get_record('election', 639)); |
//print_r(votesmart_get_record('election', 639)); |
| 16 |
//print_r(votesmart_api('Leadership.getPositions', array())); |
//print_r(votesmart_api('Leadership.getPositions', array())); |
| 17 |
//print_r(votesmart_api('Candidates.getByElection', array('electionId' => 639))); |
//print_r(votesmart_api('Candidates.getByElection', array('electionId' => 639))); |
| 18 |
//print_r(votesmart_api('Candidates.getByElection', array('electionId' => 639))); |
//print_r(votesmart_api('Candidates.getByElection', array('electionId' => 755))); |
| 19 |
|
//print_r(votesmart_api('Candidates.getByElection', array('electionId' => 756))); |
| 20 |
//print_r(votesmart_api('CandidateBio.getBio', array('candidateId' => 9490))); |
//print_r(votesmart_api('CandidateBio.getBio', array('candidateId' => 9490))); |
| 21 |
|
|
| 22 |
$states = votesmart_get_list('states'); |
$states = votesmart_get_list('states'); |
| 85 |
votesmart_factory_import_node_type($type_name, $name, $fields); |
votesmart_factory_import_node_type($type_name, $name, $fields); |
| 86 |
} |
} |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
if ($form_state['values']['election']['states']) { |
if ($form_state['values']['election']['states']) { |
| 90 |
|
module_load_include('inc', 'node', 'node.pages'); |
| 91 |
foreach ($form_state['values']['election']['year'] as $year) { |
foreach ($form_state['values']['election']['year'] as $year) { |
| 92 |
foreach ($form_state['values']['election']['states'] as $state) { |
foreach ($form_state['values']['election']['states'] as $state) { |
| 93 |
$values = array('StateId' => $state, 'year' => $year); |
$values = array('stateId' => $state, 'year' => $year); |
| 94 |
$election = votesmart_api('Election.getElectionByYearState', $values, 'election'); |
foreach (votesmart_api('Election.getElectionByYearState', $values, 'election') as $election) { |
| 95 |
|
$election = (array) $election; |
| 96 |
$s = (array) $election['stage']; |
|
| 97 |
//$values = array('electionId' => $election['electionId'], 'stageId' => $s['stageId']); |
$candidates = votesmart_api('Candidates.getByElection', array('electionId' => $election['electionId']), 'candidate'); |
| 98 |
$values = array('electionId' => $election['electionId'], 'stageId' => 'G'); |
|
| 99 |
|
foreach ($candidates as $c) { |
| 100 |
//$candidates = votesmart_api('Election.getStageCandidates', $values, 'stagecandidates.election'); |
$c = (array) $c; |
| 101 |
//$candidates = votesmart_api('Election.getStageCandidates', $values, 'candidate'); |
|
| 102 |
$candidates = votesmart_api('Candidates.getByElectionli', $values, 'candidate'); |
$values = array( |
| 103 |
module_load_include('inc', 'node', 'node.pages'); |
'type' => 'candidate', |
| 104 |
foreach ($candidates as $c) { |
'field_candidate_id' => $c['candidateId'], |
| 105 |
print_r($c); continue; |
'title' => $c['firstName'] .' '. $c['lastName'], |
| 106 |
$c = (array) $c; |
'op' => t('Save'), |
| 107 |
$values = array( |
'name' => 'admin', |
| 108 |
'type' => 'candidate', |
); |
| 109 |
'field_candidate_id' => $c['candidateId'], |
|
| 110 |
'title' => $c['firstName'] .' '. $c['lastName'], |
$values['field_election_year'][] = array('value' => $election['electionYear']); |
| 111 |
'op' => t('Save'), |
$values['field_party'][] = array('value' => $c['electionParties']); |
| 112 |
'name' => 'admin', |
if ($state != 'NA') { |
| 113 |
); |
//$values['field_state'][] = array('value' => $state); |
| 114 |
$node = (object) $values; |
} |
| 115 |
$form_state = array('values' => $values); |
|
| 116 |
drupal_execute('candidate_node_form', $form_state, $node); |
switch ($election['officeTypeId']) { |
| 117 |
|
case 'P': // Presidential |
| 118 |
|
break; |
| 119 |
|
|
| 120 |
|
case 'C': // Congressional ( house / senate ). |
| 121 |
|
// Congressional candidate has a district, senate doesn't (?) |
| 122 |
|
if ($district = $c['electionDistrictName']) { |
| 123 |
|
// TODO this presupposes you've added this named field. |
| 124 |
|
$values['field_congressional_district'] = array(array('value' => $district)); |
| 125 |
|
} |
| 126 |
|
continue; |
| 127 |
|
break; |
| 128 |
|
|
| 129 |
|
case 'L': // Legislative ( state house, state senate, etc. ) |
| 130 |
|
if ($district = $c['electionDistrictName']) { |
| 131 |
|
// TODO this presupposes you've added this named field. |
| 132 |
|
if (is_numeric($district)) { |
| 133 |
|
// TODO is the 61 vs. 61A thing a minnesota deal? |
| 134 |
|
$values['field_upper_district'] = array(array('value' => $district)); |
| 135 |
|
} |
| 136 |
|
else { |
| 137 |
|
$values['field_lower_district'] = array(array('value' => $district)); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
break; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
$node = (object) $values; |
| 144 |
|
$form_state = array('values' => $values); |
| 145 |
|
drupal_execute('candidate_node_form', $form_state, $node); |
| 146 |
|
} |
| 147 |
} |
} |
| 148 |
} |
} |
|
die; |
|
| 149 |
} |
} |
| 150 |
} |
} |
| 151 |
} |
} |
| 289 |
if (($name == 'url' || substr($name, -4) == '_url') && module_exists('link')) { |
if (($name == 'url' || substr($name, -4) == '_url') && module_exists('link')) { |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
|
// Convert to geo reference field if we've got the geo_data module and |
| 293 |
|
// appropriate tables. |
| 294 |
|
if ($geo_type = $table_field['geo_type'] && module_exists('geo_data')) { |
| 295 |
|
$field['type'] = 'geo_data'; |
| 296 |
|
$field['widget_type'] = 'geo_data_select'; |
| 297 |
|
$field['module'] = $field['widget_module'] = 'geo_data'; |
| 298 |
|
drupal_set_message(t("Adding a geo_data field for @name. You will need to go to the field settings page to link this field to the appropriate database.", array('@name' => $table_field['description'])), 'warning'); |
| 299 |
|
} |
| 300 |
|
|
| 301 |
// Convert multiple fields to postal field if we've got the postal module. |
// Convert multiple fields to postal field if we've got the postal module. |
| 302 |
|
|
| 303 |
// Convert to a votesmart field if it's an identifier. |
// Convert to a votesmart field if it's an identifier. |