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

Diff of /contributions/modules/votesmart/votesmart.inc

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.inc,v 1.1 2008/08/06 00:27:37 vauxia Exp $  <?php // $Id: votesmart.inc,v 1.2 2008/08/10 01:42:51 vauxia Exp $
2    
3  function votesmart_settings() {  function votesmart_settings() {
4    $form = array();    $form = array();
# Line 31  function _votesmart_field_values($table, Line 31  function _votesmart_field_values($table,
31    
32    foreach ($table['fields'] as $name => $info) {    foreach ($table['fields'] as $name => $info) {
33      if ($key = $info['votesmart']) {      if ($key = $info['votesmart']) {
34        if (isset($data[$key])) $values[$name] = (string) $data[$key];        if (isset($data[$key])) {
35            $values[$name] = (string) $data[$key];
36            if ($func = $info['callback']) $values[$name] = $func($values[$name]);
37          }
38      }      }
39    }    }
40    return $values;    return $values;
41  }  }
42    
43    function _votesmart_set_query($request, $input = array()) {
44      $query = array();
45      foreach($request[1] as $name => $token) {
46        if (isset($input[$token])) {
47          $query[$name] = $input[$token];
48        }
49      }
50      $request[1] = $query;
51      return $request;
52    }
53    
54  function _votesmart_lists($filter = array()) {  function _votesmart_lists($filter = array()) {
55    if ($filter && !is_array($filter)) $filter = array($filter);    if ($filter && !is_array($filter)) $filter = array($filter);
56    $lists = array();    $lists = array();
# Line 44  function _votesmart_lists($filter = arra Line 58  function _votesmart_lists($filter = arra
58    $lists['states'] = array(    $lists['states'] = array(
59      'description' => t('State'),      'description' => t('State'),
60      'table' => 'state',      'table' => 'state',
61      'votesmart' => array('State.getStateIDs', array(), 'list'),      'votesmart' => array('State.getStateIDs', array(), 'list.state'),
62        'id' => 'stateId',
63        'name' => 'name',
64    );    );
65    
66    $lists['counties'] = array(    $lists['counties'] = array(
67      'description' => t('Counties'),      'description' => t('Counties'),
68      'votesmart' => array('Local.getCounties', array('StateId'), ''),      'votesmart' => array('Local.getCounties', array('StateId' => 'state_id'), ''),
69    );    );
70    
71    $lists['elections'] = array(    $lists['elections'] = array(
72      'description' => t('Elections by state'),      'description' => t('Elections by state'),
73      'votesmart' => array('Election.getElectionByYearState', array('StateId', 'year'), ''),      'votesmart' => array('Election.getElectionByYearState', array('stateId' => 'state_id', 'year' => 'year'), 'elections.election'),
74    );    );
75    
76    $lists['office_types'] = array(    $lists['office_types'] = array(
# Line 64  function _votesmart_lists($filter = arra Line 80  function _votesmart_lists($filter = arra
80    
81    $lists['officials'] = array(    $lists['officials'] = array(
82      'description' => t('Officials'),      'description' => t('Officials'),
83      'votesmart' => array('Local.getOfficials', array('localId'), ''),      'votesmart' => array('Local.getOfficials', array('localId' => 'local_id'), ''),
84    );    );
85    
86    $lists['office_branches'] = array(    $lists['office_branches'] = array(
# Line 79  function _votesmart_lists($filter = arra Line 95  function _votesmart_lists($filter = arra
95    
96    $lists['sig_categories'] = array(    $lists['sig_categories'] = array(
97      'description' => t('Special interest Category'),      'description' => t('Special interest Category'),
98      'votesmart' => array('Rating.getCategories', array(), 'category'),      'votesmart' => array('Rating.getCategories', array('stateId' => 'state_id'), 'category'),
99    );    );
100    
101    $lists['sigs'] = array(    $lists['sigs'] = array(
102      'description' => t('Special interest group'),      'description' => t('Special interest group'),
103      'table' => 'sig',      'table' => 'sig',
104      'votesmart' => array('Rating.getSigList', array(), 'sig'),      'votesmart' => array('Rating.getSigList', array('categoryId' => 'category_id', 'stateId' => 'state_id'), 'sig'),
105    );    );
106    
107    $lists['bill_categories'] = array(    $lists['bill_categories'] = array(
108      'description' => t('Bill Categories'),      'description' => t('Bill Categories'),
109      'votesmart' => array('Votes.getCategories', array('stateId', 'year'), ''),      'votesmart' => array('Votes.getCategories', array('stateId' => 'state_id', 'year' => 'year'), ''),
110    );    );
111    
112    $lists['bills_by_year_state'] = array(    $lists['bills_by_year_state'] = array(
113      'description' => t('Bills by year'),      'description' => t('Bills by year'),
114      'table' => 'bill',      'table' => 'bill',
115      'votesmart' => array('Votes.getBillsByYearState', array('stateId', 'year'), 'bill'),      'votesmart' => array('Votes.getBillsByYearState', array('stateId' => 'state_id', 'year' => 'year'), 'bill'),
116    );    );
117    
118    $lists['bills_by_category_year_state'] = array(    $lists['bills_by_category_year_state'] = array(
119      'description' => t('Votes by year, category and state'),      'description' => t('Votes by year, category and state'),
120      'table' => 'bill',      'table' => 'bill',
121      'votesmart' => array('Votes.getBillsByCategoryYearState', array('stateId', 'year', 'categoryId'), 'bill'),      'votesmart' => array('Votes.getBillsByCategoryYearState', array('stateId' => 'state_id', 'year' => 'year', 'categoryId' => 'category_id'), 'bill'),
122    );    );
123    
124    $lists['bills_by_official_year_office'] = array(    $lists['bills_by_official_year_office'] = array(
125      'description' => t('Votes by official, year and office'),      'description' => t('Votes by official, year and office'),
126      'table' => 'bill',      'table' => 'bill',
127      'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId', 'year', 'office'), 'bill'),      'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId' => 'candidate_id', 'year' => 'year', 'office' => 'office_id'), 'bill'),
128    );    );
129    
130    $lists['bills_by_candidate_category_office'] = array(    $lists['bills_by_candidate_category_office'] = array(
131      'description' => t('Votes by official, year and office'),      'description' => t('Votes by official, year and office'),
132      'table' => 'bill',      'table' => 'bill',
133      'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId', 'year', 'office'), 'bill'),      'votesmart' => array('Votes.getBillsByOfficialYearOffice', array('candidateId' => 'candidate_id', 'year' => 'year', 'office' => 'office_id'), 'bill'),
134    );    );
135    
136    if ($filter) {    if ($filter) {
# Line 133  function _votesmart_tables($filter = arr Line 149  function _votesmart_tables($filter = arr
149    $tables = array();    $tables = array();
150    $tables['address'] = array(    $tables['address'] = array(
151    );    );
152    $tables['measures'] = array(    $tables['measure'] = array(
153        'description' => t('Measure'),
154        'votesmart' => array('Measure.getMeasure', array('measureId' => 'measure_id'), 'measure'),
155        'fields' => array(
156          'measure_id' => array(
157            'type' => 'integer',
158            'description' => t('Measure'),
159            'votesmart' => 'measureId',
160          ),
161          'measure_code' => array(
162            'type' => 'varchar',
163            'length' => 100,
164            'description' => t('Measure code'),
165            'votesmart' => 'measureCode',
166          ),
167          'title' => array(
168            'type' => 'varchar',
169            'length' => 200,
170            'description' => t('Title'),
171            'votesmart' => 'title',
172          ),
173          'election_date' => array(
174            'type' => 'varchar',
175            'length' => 200,
176            'description' => t('Election date'),
177            'votesmart' => 'electionDate',
178          ),
179          'election_type' => array(
180            'type' => 'varchar',
181            'length' => 200,
182            'description' => t('Election type'),
183            'votesmart' => 'electionType',
184          ),
185          'source' => array(
186            'type' => 'varchar',
187            'length' => 200,
188            'description' => t('Source'),
189            'votesmart' => 'source',
190          ),
191          'url' => array(
192            'type' => 'varchar',
193            'length' => 200,
194            'description' => t('URL'),
195            'votesmart' => 'url',
196          ),
197          'summary' => array(
198            'type' => 'long',
199            'description' => t('Summary'),
200            'votesmart' => 'summary',
201          ),
202          'summary_url' => array(
203            'type' => 'varchar',
204            'length' => 200,
205            'description' => t('Summary URL'),
206            'votesmart' => 'summaryUrl',
207          ),
208          'body' => array(
209            'type' => 'long',
210            'description' => t('Measure text'),
211            'votesmart' => 'measureText',
212          ),
213          'text_url' => array(
214            'type' => 'varchar',
215            'length' => 200,
216            'description' => t('Text URL'),
217            'votesmart' => 'textUrl',
218          ),
219          'pro_url' => array(
220            'type' => 'varchar',
221            'length' => 200,
222            'description' => t('Pro URL'),
223            'votesmart' => 'proUrl',
224          ),
225          'con_url' => array(
226            'type' => 'varchar',
227            'length' => 200,
228            'description' => t('Con URL'),
229            'votesmart' => 'conUrl',
230          ),
231          'yes' => array(
232            'type' => 'integer',
233            'description' => t('Yes'),
234            'votesmart' => 'yes',
235          ),
236          'no' => array(
237            'type' => 'integer',
238            'description' => t('No'),
239            'votesmart' => 'no',
240          ),
241          'outcome' => array(
242            'type' => 'varchar',
243            'length' => 200,
244            'description' => t('Outcome'),
245            'votesmart' => 'outcome',
246          ),
247        ),
248    );    );
249    $tables['bill'] = array(    $tables['bill'] = array(
250      'description' => t('Bill'),      'description' => t('Bill'),
251      'votesmart' => array('Votes.getBill', array('billId'), 'bill'),      'votesmart' => array('Votes.getBill', array('billId' => 'bill_id'), 'bill'),
252    );    );
253    $tables['bill_vote'] = array(    $tables['bill_vote'] = array(
254      'description' => t('Bill Action'),      'description' => t('Bill Action'),
255      'votesmart' => array('Votes.getBillActionVotes', array('actionId'), 'vote'),      'votesmart' => array('Votes.getBillActionVotes', array('actionId' => 'action_id'), 'vote'),
256    );    );
257    $tables['candidate'] = array(    $tables['candidate'] = array(
258        'description' => t('Candidate'),
259        'votesmart' => array('CandidateBio.getBio', array('candidateId' => 'candidate_id'), 'candidate'),
260        'fields' => array(
261          'candidate_id' => array(
262            'type' => 'integer',
263            'description' => t('Candidate'),
264            'votesmart' => 'candidateId',
265          ),
266          'fecid' => array(
267            'type' => 'varchar',
268            'size' => 100,
269            'description' => t('Federal Election Comission ID'),
270            'votesmart' => 'fecid',
271          ),
272          'first_name' => array(
273            'type' => 'varchar',
274            'size' => 100,
275            'description' => t('First name'),
276            'votesmart' => 'firstName',
277          ),
278          'middle_name' => array(
279            'type' => 'varchar',
280            'size' => 100,
281            'description' => t('Middle name'),
282            'votesmart' => 'middleName',
283          ),
284          'last_name' => array(
285            'type' => 'varchar',
286            'size' => 100,
287            'description' => t('Last name'),
288            'votesmart' => 'lastName',
289          ),
290          'suffix' => array(
291            'type' => 'varchar',
292            'size' => 10,
293            'description' => t('Suffix'),
294            'votesmart' => 'suffix',
295          ),
296          'birth_date' => array(
297            'type' => 'date',
298            'description' => t('Birth date'),
299            'votesmart' => 'birthDate',
300          ),
301          'birth_place' => array(
302            'type' => 'varchar',
303            'size' => 100,
304            'description' => t('Birth place'),
305            'votesmart' => 'birthPlace',
306          ),
307          'pronounciation' => array(
308            'type' => 'varchar',
309            'size' => 100,
310            'description' => t('Pronounciation'),
311            'votesmart' => 'pronounciation',
312          ),
313          'gender' => array(
314            'type' => 'varchar',
315            'size' => 6,
316            'description' => t('Gender'),
317            'votesmart' => 'gender',
318          ),
319          'family' => array(
320            'type' => 'varchar',
321            'size' => 100,
322            'description' => t('Family'),
323            'votesmart' => 'family',
324            'callback' => '_votesmart_split_newline',
325          ),
326          'home_city' => array(
327            'type' => 'varchar',
328            'size' => 100,
329            'description' => t('Home city'),
330            'votesmart' => 'homeCity',
331          ),
332          'home_state' => array(
333            'type' => 'varchar',
334            'size' => 2,
335            'description' => t('Home state'),
336            'votesmart' => 'homeState',
337          ),
338          'education' => array(
339            'type' => 'varchar',
340            'size' => 100,
341            'description' => t('Education'),
342            'votesmart' => 'education',
343            'callback' => '_votesmart_split_newline',
344          ),
345          'profession' => array(
346            'type' => 'varchar',
347            'size' => 100,
348            'description' => t('Profession'),
349            'votesmart' => 'profession',
350            'callback' => '_votesmart_split_newline',
351          ),
352          'political' => array(
353            'type' => 'varchar',
354            'size' => 100,
355            'description' => t('Political'),
356            'votesmart' => 'political',
357            'callback' => '_votesmart_split_newline',
358          ),
359          'religion' => array(
360            'type' => 'varchar',
361            'size' => 100,
362            'description' => t('Religion'),
363            'votesmart' => 'religion',
364          ),
365          'cong_membership' => array(
366            'type' => 'varchar',
367            'size' => 100,
368            'description' => t('Congressional membership'),
369            'votesmart' => 'congMembership',
370            'callback' => '_votesmart_split_newline',
371          ),
372          'org_membership' => array(
373            'type' => 'varchar',
374            'size' => 100,
375            'description' => t('Organizational membership'),
376            'votesmart' => 'orgMembership',
377            'callback' => '_votesmart_split_newline',
378          ),
379          'special_message' => array(
380            'type' => 'varchar',
381            'size' => 255,
382            'description' => t('Special message'),
383            'votesmart' => 'specialMsg',
384          ),
385        ),
386    );    );
387    $tables['committee'] = array(    $tables['committee'] = array(
388    );    );
# Line 151  function _votesmart_tables($filter = arr Line 390  function _votesmart_tables($filter = arr
390    );    );
391    $tables['election'] = array(    $tables['election'] = array(
392      'description' => t('Election'),      'description' => t('Election'),
393      'votesmart' => array('getElection', array('electionId'), 'election'),      'votesmart' => array('Election.getElection', array('electionId' => 'election_id')),
394      'fields' => array(      'fields' => array(
395        'election_id' => array(        'election_id' => array(
396          'type' => 'integer',          'type' => 'integer',
# Line 174  function _votesmart_tables($filter = arr Line 413  function _votesmart_tables($filter = arr
413          'type' => 'integer',          'type' => 'integer',
414          'description' => t('Office type'),          'description' => t('Office type'),
415          'votesmart' => 'officeTypeId',          'votesmart' => 'officeTypeId',
416            'votesmart_list' => 'office_types',
417        ),        ),
418        'special' => array(        'special' => array(
419          'type' => 'integer',          'type' => 'integer',
420          'description' => t('Special election'),          'description' => t('Special election'),
421          'votesmart' => 'special',          'votesmart' => 'special',
422            'callback' => '_votesmart_boolean',
423        ),        ),
424        'election_year' => array(        'year' => array(
425          'type' => 'integer',          'type' => 'integer',
426          'description' => t('Election year'),          'description' => t('Election year'),
427          'votesmart' => 'electionYear',          'votesmart' => 'electionYear',
# Line 197  function _votesmart_tables($filter = arr Line 438  function _votesmart_tables($filter = arr
438    );    );
439    $tables['office'] = array(    $tables['office'] = array(
440    );    );
   $tables['branch'] = array(  
   );  
441    $tables['officials'] = array(    $tables['officials'] = array(
442    );    );
443    $tables['state'] = array(    $tables['state'] = array(
444      'description' => t('State'),      'description' => t('State'),
445      'votesmart' => array('getState', array('stateID'), 'details'),      'votesmart' => array('State.getState', array('stateId' => 'state_id'), 'details'),
446      'fields' => array(      'fields' => array(
447        'state_id' => array(        'state_id' => array(
448          'type' => 'char',          'type' => 'char',
# Line 236  function _votesmart_tables($filter = arr Line 475  function _votesmart_tables($filter = arr
475          'votesmart' => 'capital'          'votesmart' => 'capital'
476        ),        ),
477        'area' => array(        'area' => array(
478          'type' => 'varchar',          'type' => 'int',
         'length' => 200,  
479          'description' => t('Area'),          'description' => t('Area'),
480          'votesmart' => 'area'          'votesmart' => 'area',
481            'callback' => '_votesmart_numeric',
482        ),        ),
483        'population' => array(        'population' => array(
484          'type' => 'varchar',          'type' => 'int',
         'length' => 200,  
485          'description' => t('Population'),          'description' => t('Population'),
486          'votesmart' => 'population'          'votesmart' => 'population',
487            'callback' => '_votesmart_numeric',
488        ),        ),
489        'statehood' => array(        'statehood' => array(
490          'type' => 'varchar',          'type' => 'varchar',
491          'length' => 200,          'length' => 200,
492          'description' => t('Statehood'),          'description' => t('Statehood'),
493          'votesmart' => 'statehood'          'votesmart' => 'statehood',
494            'callback' => '_votesmart_date',
495        ),        ),
496        'motto' => array(        'motto' => array(
497          'type' => 'varchar',          'type' => 'varchar',
# Line 292  function _votesmart_tables($filter = arr Line 532  function _votesmart_tables($filter = arr
532        'bicameral' => array(        'bicameral' => array(
533          'type' => 'varchar',          'type' => 'varchar',
534          'description' => t('Bicameral legislature'),          'description' => t('Bicameral legislature'),
535          'votesmart' => 'lowPoint'          'votesmart' => 'bicameral',
536            'callback' => '_votesmart_boolean',
537        ),        ),
538        'upper_legislature' => array(        'upper_legislature' => array(
539          'type' => 'varchar',          'type' => 'varchar',
# Line 310  function _votesmart_tables($filter = arr Line 551  function _votesmart_tables($filter = arr
551          'type' => 'varchar',          'type' => 'varchar',
552          'length' => 200,          'length' => 200,
553          'description' => t('Leutenant governor'),          'description' => t('Leutenant governor'),
554          'votesmart' => 'ltGov'          'votesmart' => 'ltGov',
555            'callback' => '_votesmart_boolean',
556        ),        ),
557        'senators' => array(        'senators' => array(
558          'type' => 'integer',          'type' => 'integer',
# Line 318  function _votesmart_tables($filter = arr Line 560  function _votesmart_tables($filter = arr
560          'votesmart' => 'senators'          'votesmart' => 'senators'
561        ),        ),
562        'reps' => array(        'reps' => array(
563          'type' => 'integers',          'type' => 'integer',
564          'description' => t('Representatives'),          'description' => t('Representatives'),
565          'votesmart' => 'reps'          'votesmart' => 'reps'
566        ),        ),
# Line 403  function _votesmart_tables($filter = arr Line 645  function _votesmart_tables($filter = arr
645    );    );
646    $tables['sig'] = array(    $tables['sig'] = array(
647      'description' => t('Special interest group'),      'description' => t('Special interest group'),
648                  'votesmart' => array('Rating.getSig', array('sigId')),                  'votesmart' => array('Rating.getSig', array('sigId' => 'sig_id')),
649      'fields' => array(      'fields' => array(
650        'sig_id' => array(        'sig_id' => array(
651          'type' => 'integer',          'type' => 'integer',
# Line 509  function _votesmart_tables($filter = arr Line 751  function _votesmart_tables($filter = arr
751    
752    return $tables;    return $tables;
753  }  }
754    
755    /**
756     * Basic value conversion functions.
757     */
758    function _votesmart_numeric($value) {
759      return (preg_replace('/[^\d.]/', '', $value));
760    }
761    
762    function _votesmart_boolean($value) {
763      return ($value == 't');
764    }
765    
766    function _votesmart_date($value) {
767    }
768    
769    function _votesmart_split_newline($value) {
770      return (explode("\n", $value));
771    }

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

  ViewVC Help
Powered by ViewVC 1.1.2