Skip to content

Instantly share code, notes, and snippets.

@psaia
Created September 7, 2010 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psaia/569148 to your computer and use it in GitHub Desktop.
Save psaia/569148 to your computer and use it in GitHub Desktop.
<?php
// $Id$
/**
* Bill Tracker
* A drupal module for tracking bills using class.hfdrumbone.php
* @Author Pete Saia
* @version 1.0
*/
require_once drupal_get_path('module', 'bill_tracker').'/hfdrumbone.class.php';
/**
* Setup Permissions
* @return array
**/
function bill_tracker_perm()
{
return array(
'create bill_tracker node',
'delete bill_tracker node'
);
}
/**
* Declare content type
* @return array
**/
function bill_tracker_node_info()
{
return array(
'bill_tracker' => array(
'name' => t('Bill Tracker'),
'module' => 'bill_tracker',
'description' => "Add and manage bills.",
),
);
}
/**
* Setup drupal menu and public pages
* @return array
**/
function bill_tracker_menu()
{
$items = array();
$items['admin/settings/bill_tracker/update_cache'] = array(
'page callback' => 'update_caches',
'access callback' => 'user_access',
'access arguments' => array('create bill_tracker node'),
'type' => MENU_NORMAL_ITEM,
'title' => 'Update Bill Tracker Cache');
// public pages
$items['vote-tracker'] = array(
'page callback' => 'vote_tracker_display',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'title' => 'Vote Tracker');
$items['bill-tracker'] = array(
'page callback' => 'bill_tracker_display',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'title' => 'Bill Tracker');
$items['bill-info'] = array(
'page callback' => 'single_bill_display',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'title' => 'Bill Information');
return $items;
}
/**
* Alter the add a bill form
* @return void
**/
function bill_tracker_form_alter(&$form, &$form_state, $form_id)
{
if ($form_id == 'bill_tracker_node_form')
{
$form['#validate'][] = 'bill_tracker_form_validate';
}
}
/**
* Make sure the bill is in the sunlight api. If it is,
* cache it then add it.
* @return void
**/
function bill_tracker_form_validate($form, &$form_state)
{
$bill_id = $form_state['values']['field_bill_type'][0]['value'].
$form_state['values']['field_bill_number'][0]['value'] . '-' .
$form_state['values']['field_bill_session'][0]['value'];
if ($form_state['values']['op'] !== 'Delete')
{
// init api
$api = HFDrumbone::instance('d79c4fee470849beaf8341a92ce570b6');
// get the bill object if exist
$bill_obj = $api->getData(array('bill_id' => $bill_id), 'bill');
// if doesn't exist
if (empty($bill_obj)) // bill does NOT exist in API
{
form_set_error('field_bill_number', 'Bill does not exist in the API.');
}
// form array to cache
$array = array();
$array['bill'] = $bill_obj;
$array['roll'] = ($bill_obj->votes[0]->type == 'vote') ? $api->getData(array('roll_id' => $bill_obj->votes[0]->roll_id), 'roll') : '';
$array['db_info'] = array(
'title' => $form_state['values']['title'],
'type' => $form_state['values']['field_bill_type'][0]['value'],
'related_bill' => $form_state['values']['field_related_bill'][0]['nid'],
'news' => $form_state['values']['field_news'],
'chamber' => $form_state['values']['field_chamber'][0]['value'],
'number' => $form_state['values']['field_bill_number'][0]['value'],
'session' => $form_state['values']['field_bill_session'][0]['value'],
'opinion' => $form_state['values']['field_bill_opinion'][0]['value'],
'desc' => $form_state['values']['field_bill_desc'][0]['value']
);
// cache that.
variable_set('bill_tracker_'.$bill_id, $array);
}
else
{
// ** TODO Need a better way to do this **
// (for now the cached variables just stay in drupal...)
//variable_del('bill_tracker_'.$bill_id);
}
}
/**
* Update the cache with fresh data
* @return void
**/
function update_caches()
{
// init api
$api = HFDrumbone::instance('d79c4fee470849beaf8341a92ce570b6');
// query content type
$result = db_query("SELECT * FROM {content_type_bill_tracker}");
// if no bills
if ( ! db_affected_rows($result))
{
drupal_set_message(t('There are no bills in the system'));
drupal_goto('admin/settings');
}
// form array of bills and cache
$data = array();
while($row = db_fetch_array($result))
{
$bill_obj = $api->getData(array(
'bill_id' => $row['field_bill_type_value'].$row['field_bill_number_value'] .'-'. $row['field_bill_session_value']), 'bill');
$from_cache = variable_get('bill_tracker_'.$bill_obj->bill_id, NULL);
$data['bill'] = $bill_obj;
$data['roll'] = ($bill_obj->votes[0]->type == 'vote') ? $api->getData(array('roll_id' => $bill_obj->votes[0]->roll_id), 'roll') : '';
$data['db_info'] = array( // no need to update these with the api or database, so use cached obj
'title' => $from_cache['db_info']['title'],
'related_bill' => $from_cache['db_info']['related_bill'],
'type' => $from_cache['db_info']['type'],
'number' => $from_cache['db_info']['number'],
'news' => $from_cache['db_info']['news'],
'chamber' => $from_cache['db_info']['chamber'],
'session' => $from_cache['db_info']['session'],
'opinion' => $from_cache['db_info']['opinion'],
'desc' => $from_cache['db_info']['desc']
);
variable_set('bill_tracker_'.$bill_obj->bill_id, $data);
}
drupal_set_message(t('Bill Cache Updated!'));
drupal_goto('admin/settings');
}
/*
********** Views **********
(this gets a bit messy..)
*/
/**
* Bill Tracker HTML
* @return $html
**/
function bill_tracker_display()
{
$limit = 2; // number of bills per page
$search = ($_GET['s']) ? trim(urldecode($_GET['s'])) : NULL; // get item to be searched
$page = $_GET['p']; // page number
if ( ! is_null($search)) // get total number of results
{
$sql = "
SELECT n.title, bt.*
FROM {content_type_bill_tracker} bt LEFT JOIN {node} n ON n.nid = bt.nid
WHERE (n.nid = bt.nid)
AND n.title LIKE '%%%s%%'
OR bt.field_chamber_value LIKE '%s'
OR bt.field_bill_number_value LIKE '%d'
OR bt.field_bill_session_value LIKE '%d'
";
}
else
{
$sql = "
SELECT *
FROM {content_type_bill_tracker}
";
}
$result = db_query($sql,$search,$search,$search,$search);
$total = mysql_num_rows($result);
// get results with limit and offset
if($page)
{
$start = ($page - 1) * $limit;
}
else
{
$start = 0;
}
$sql .= " LIMIT $start, $limit";
$result = db_query($sql,$search,$search,$search,$search);
// setup pagination
if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"bill-tracker-pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?p=$prev".(($search) ? '&s='.$search : '')."\">« previous</a>";
else
$pagination.= "<span class=\"disabled".(($search) ? '&s='.$search : '')."\">« previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter".(($search) ? '&s='.$search : '')."\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter".(($search) ? '&s='.$search : '')."\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?p=$lpm1".(($search) ? '&s='.$search : '')."\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?p=$lastpage".(($search) ? '&s='.$search : '')."\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?p=1".(($search) ? '&s='.$search : '')."\">1</a>";
$pagination.= "<a href=\"$targetpage?p=2".(($search) ? '&s='.$search : '')."\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter".(($search) ? '&s='.$search : '')."\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?p=$lpm1".(($search) ? '&s='.$search : '')."\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?p=$lastpage".(($search) ? '&s='.$search : '')."\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?p=1".(($search) ? '&s='.$search : '')."\">1</a>";
$pagination.= "<a href=\"$targetpage?p=2".(($search) ? '&s='.$search : '')."\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter".(($search) ? '&s='.$search : '')."\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?p=$next".(($search) ? '&s='.$search : '')."\">next »</a>";
else
$pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
// display html
$html = '';
// search field
$html .= '
<div class="bill-tracker-search">
<form method="get" action="#">
<fieldset>
<input type="text" class="txt" maxlength="20" name="s" value="'.$_GET['s'].'" />
<input type="submit" value="Search" />
</fieldset>
</form>
</div>
';
if ($total > 0)
{
while($row = db_fetch_array($result))
{
$obj = variable_get('bill_tracker_'.$row['field_bill_type_value'].$row['field_bill_number_value'].'-'.$row['field_bill_session_value'], NULL);
if ($obj)
{
$html .= '<div class="bill-tracker-row">';
$html .= '<h2 class="title"><a href="/bill-info?bill='.$obj['bill']->bill_id.'">'.$obj['db_info']['title'].' ('.$obj['bill']->type.'.'.$obj['bill']->number.')</a></h2>';
$html .= '<p>'.truncate($obj['db_info']['desc'],90).'</p>';
// show news and analysis
unset($obj['db_info']['news']['field_news_add_more']);
if (count($obj['db_info']['news']) !== 0) // clean array
{
$i = 0;
foreach ($obj['db_info']['news'] as $key => $val)
{
if (empty($val['title'])) unset($obj['db_info']['news'][$i]);
$i++;
}
}
if (count($obj['db_info']['news']) !== 0)
{
$html .= '<b>Related News and Analysis</b><br />';
foreach ($obj['db_info']['news'] as $news)
{
if ( ! empty($news['title']) AND ! empty($news['url']))
{
$html .= '<a href="'.$news['url'].'">'.$news['title'].'</a><br />';
}
}
}
// show related bill
$nid = $obj['db_info']['related_bill'];
if ( ! empty($nid))
{
$related_result = db_query("SELECT `field_bill_type_value`,`field_bill_number_value`,`field_bill_session_value` FROM {content_type_bill_tracker} WHERE `nid` = '%d'", $nid);
if ( ! db_affected_rows($related_result))
{
$related_bill = '';
}
else
{
$related_bill = db_fetch_array($related_result);
}
}
else
{
$related_bill = '';
}
if ( ! empty($related_bill))
{
$html .= '<b>Related Bill</b><br />';
$html .= '<a href="/bill-info?bill='.$related_bill['field_bill_type_value'].$related_bill['field_bill_number_value'].'-'.$related_bill['field_bill_session_value'].'">'.$related_bill['field_bill_type_value'].$related_bill['field_bill_number_value'].'-'.$related_bill['field_bill_session_value'].'</a>';
}
$html .= '</div>';
}
}
}
else
{
$html .= 'No results were returned.';
}
$html .= $pagination;
return $html;
}
/**
* Single Bill Info HTML
* @return $html
**/
function single_bill_display()
{
$bill = $_GET['bill'];
// if there is no bill parameter
if (empty($bill))
{
drupal_goto('bill-tracker');
}
// break up bill id
$type = preg_match("/[a-zA-Z]+/", $bill, $typeMatch);
$number = preg_match("/[0-9]+/", $bill, $numberMatch);
$session = preg_match("/[0-9]+$/", $bill, $sessionMatch);
// get object
$obj = variable_get('bill_tracker_'.$typeMatch[0].$numberMatch[0].'-'.$sessionMatch[0], NULL);
// make sure there were bills
if (is_null($obj))
{
drupal_goto('bill-tracker');
}
//print_r($obj);
$html = '';
$html .= '<h1 class="bill-title">'.$obj['db_info']['title'].' ('.$obj['bill']->type.'.'.$obj['bill']->number.')</h1>';
$html .= '<p>Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet. Nunc eu ullamcorper orci. Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis. In condimentum facilisis porta. Sed nec diam eu diam mattis viverra. Nulla fringilla, orci ac euismod semper, magna diam porttitor mauris, quis sollicitudin sapien justo in libero. Vestibulum mollis mauris enim. Morbi euismod magna ac lorem rutrum elementum. Donec viverra auctor lobortis. Pellentesque eu est a nulla placerat dignissim. Morbi a enim in.</p>';
$html .= '<table class="bill-tracker-single-table">';
// Sponsor
$html .= '<tr>';
$html .= '<td><b>Sponsor:&nbsp;</b></td>';
$html .= '<td>'.$obj['bill']->sponsor->first_name.' '.$obj['bill']->sponsor->last_name.' ('.$obj['bill']->sponsor->party.'-'.$obj['bill']->sponsor->state.')</td>';
$html .= '</tr>';
// Cosponsors
$i = 0;
$democrat_count = 0;
$republican_count = 0;
while (count($obj['bill']->cosponsors) > $i)
{
if ($obj['bill']->cosponsors[$i]->party == 'D')
{
$democrat_count = $democrat_count + 1;
}
else
{
$republican_count = $republican_count + 1;
}
$i++;
}
$html .= '<tr>';
$html .= '<td><b>Cosponsors:&nbsp;</b></td>';
if ($obj['bill']->cosponsors)
{
$html .= '<td><a href="#" class="cosponsors">'.count($obj['bill']->cosponsors).' Cosponsors ('.$democrat_count.' D, '.$republican_count.' R)</a>';
$html .= '<ul class="toggle-sponsors">';
foreach($obj['bill']->cosponsors as $sponsor)
{
$html .= '<li><i>'.$sponsor->first_name.' '.$sponsor->last_name.' - '.$sponsor->state.' - '.$sponsor->party.'</i></li>';
}
$html .= '</ul></td>';
}
else
{
$html .= '<td>None</td>';
}
$html .= '</tr>';
// Introduced
$html .= '<tr>';
$html .= '<td><b>Introduced:&nbsp;</b></td>';
$html .= '<td>'.substr($obj['bill']->introduced_at, 0, 10).'</td>';
$html .= '</tr>';
// NOT NEEDED FOR NOW
// $html .= '<tr>';
// $html .= '<td><b>Committees:&nbsp;</b></td>';
// $html .= '<td>Committee One<br />Committee Two<br />Committee Three</td>';
// $html .= '</tr>';
// NOT NEEDED FOR NOW
// get related bill from nid ** dirty i know, blame drup **
$nid = $obj['db_info']['related_bill'];
if ( ! empty($nid))
{
$result = db_query("SELECT `field_bill_type_value`,`field_bill_number_value`,`field_bill_session_value` FROM {content_type_bill_tracker} WHERE `nid` = '%d'", $nid);
if ( ! db_affected_rows($result))
{
$related_bill = FALSE;
}
else
{
$related_bill = db_fetch_array($result);
}
}
else
{
$related_bill = FALSE;
}
$html .= '<tr>';
$html .= '<td><b>Related Bill:&nbsp;</b></td>';
$html .= '<td>'.(( ! $related_bill) ? 'None' : '<a href="/bill-info?bill='.$related_bill['field_bill_type_value'].$related_bill['field_bill_number_value'].'-'.$related_bill['field_bill_session_value'].'">'.$related_bill['field_bill_type_value'].$related_bill['field_bill_number_value'].'-'.$related_bill['field_bill_session_value']).'</a></td>';
$html .= '</tr>';
// News and Analysis
$html .= '<tr>';
$html .= '<td><b>News and Analysis:&nbsp;</b></td>';
$html .= '<td>';
unset($obj['db_info']['news']['field_news_add_more']);
if (count($obj['db_info']['news']) !== 0) // clean array
{
$i = 0;
foreach ($obj['db_info']['news'] as $key => $val)
{
if (empty($val['title'])) unset($obj['db_info']['news'][$i]);
$i++;
}
}
if (count($obj['db_info']['news']) !== 0)
{
foreach ($obj['db_info']['news'] as $news)
{
if ( ! empty($news['title']) AND ! empty($news['url']))
{
$html .= '<a href="'.$news['url'].'">'.$news['title'].'</a><br />';
}
}
}
else
{
$html .= 'None';
}
$html .= '</td>';
$html .= '</tr>';
// Learn More
$thomas_format = $obj['bill']->session.':'.strtoupper($obj['bill']->type).$obj['bill']->number.':';
$html .= '<tr>';
$html .= '<td><b>Learn More:&nbsp;</b></td>';
$html .= '<td><a target="_blank" href="http://thomas.loc.gov/cgi-bin/bdquery/z?d'.$thomas_format.'">View in THOMAS</a></td>';
$html .= '</tr>';
// Activity
$html .= '<tr>';
$html .= '<td><b>Bill Activity:&nbsp;</b></td>';
$html .= '<td>';
if (count($obj['bill']->actions) != 0)
{
foreach ($obj['bill']->actions as $action)
{
$html .= '<b>'.substr($action->acted_at, 0, 10).'</b>';
$html .= '<div class="action">'.$action->text.'</div><br />';
}
}
else
{
$html .= 'None';
}
$html .= '</td>';
$html .= '</tr>';
$html .= '</table>';
$html .= '
<script>
$(document).ready(function(){
$(".toggle-sponsors").css("display","none");
$(".cosponsors").click(function(){
if ($(".toggle-sponsors").css("display") == "none")
{
//$(".toggle-sponsors").css("display", "block");
$(".toggle-sponsors").slideDown();
}
else
{
//$(".toggle-sponsors").css("display", "none");
$(".toggle-sponsors").slideUp();
}
return false;
});
});
</script>
';
return $html;
}
/**
* Vote Tracker HTML
* @return $html
**/
function vote_tracker_display()
{
// make query
if (isset($_GET['session']) AND isset($_GET['chamber']))
{
$result = db_query("SELECT * FROM {content_type_bill_tracker} WHERE `field_bill_session_value` = '%d' AND `field_chamber_value` = '%s'",$_GET['session'],$_GET['chamber']);
}
elseif (isset($_GET['session']))
{
$result = db_query("SELECT * FROM {content_type_bill_tracker} WHERE `field_bill_session_value` = '%d'", $_GET['session']);
}
elseif (isset($_GET['chamber']))
{
$result = db_query("SELECT * FROM {content_type_bill_tracker} WHERE `field_chamber_value` = '%s'", $_GET['chamber']);
}
else
{
$result = db_query("SELECT * FROM {content_type_bill_tracker} WHERE `field_chamber_value` = 'house'");
}
// make sure there were bills
if (db_affected_rows($result) === 0)
{
$output = 'No bills were returned.';
return $output;
}
$output = array();
while($row = db_fetch_array($result))
{
$output[] = variable_get('bill_tracker_'.$row['field_bill_type_value'].$row['field_bill_number_value'] .'-'. $row['field_bill_session_value'], NULL);
}
// form unique array of voters
$voters = array();
foreach ($output as $bill)
{
if ($bill['roll']->voters)
{
foreach ($bill['roll']->voters as $id => $val)
{
$voters[$id] = $val;
}
}
}
// start forming the html
$html = '';
// sorting controls
$html .= '<div class="vote-tracker-controls"><span>Filter: </span>';
$html .= '<select name="chamber" id="chamber_select"><option '.(($_GET['chamber']==='house') ? 'SELECTED' : '').' value="house">House</option><option '.(($_GET['chamber']==='senate') ? 'SELECTED' : '').' value="senate">Senate</option></select>';
$html .= '<select name="session" id="session_select"><option value="111">111th Congress</option></select>';
$html .= '</div>';
// start forming table
$html .= '<table id="vote-tracker-table">';
// display bills
$html .= "<thead><tr>";
$html .= "<th>Legislator</th>";
$html .= "<th>Party</th>";
$html .= "<th>State</th>";
foreach ($output as $bill)
{
$html .= "<th>".'<a title="'.truncate($bill['db_info']['desc'],40).'" class="tt-bill" href="/bill-info?bill='.$bill['bill']->bill_id.'">'.$bill['bill']->type.'.'.$bill['bill']->number."</th>";
}
$html .= "</tr></thead>";
//display the rest
$html .= '<tbody>';
if (count($voters))
{
foreach ($voters as $voterID => $result)
{
$html .= "<tr>";
$html .= "<td>" . $result->voter->first_name . " " . $result->voter->last_name . "</td>";
$html .= "<td>" . $result->voter->party . "</td>";
$html .= "<td>" . $result->voter->state . "</td>";
foreach ($output as $bill)
{
$vote = $bill['roll']->voters->$voterID->vote;
// vote: "+", "-", "0", or "P" (for aye, nay, not voting, or present)
if ($vote == '0')
{
$vote = 'Not Voting';
}
elseif ($vote == 'P')
{
$vote = 'Present';
}
elseif (is_null($vote))
{
$vote = 'n/a';
}
// do good or bad class based on opinion
if ($bill['db_info']['opinion'] == 'Good' AND $vote == '+' OR
$bill['db_info']['opinion'] == 'Bad' AND $vote == '-')
{
$class = '<td class="good">';
}
elseif ($bill['db_info']['opinion'] == 'Good' AND $vote == '-' OR
$bill['db_info']['opinion'] == 'Bad' AND $vote == '+')
{
$class = '<td class="bad">';
}
else
{
$class = '<td>';
}
$html .= $class.$vote.'</td>';
}
$html .= "</tr>";
}
}
else
{
$html .= "<tr>";
$html .= "<td>No bills that have been voted on.</td>";
$html .= "<td>n/a</td>";
$html .= "<td>n/a</td>";
foreach ($output as $bill)
{
$html .= "<td>n/a</td>";
}
$html .= "</tr>";
}
$html .= '</tbody>';
$html .= "</table>";
// the filter select box switcher
$html .= '
<script>
var chamber = document.getElementById("chamber_select"),
session = document.getElementById("session_select"),
currentUrl,
changer = function(e) {
currentUrl = location.href;
window.location = currentUrl.split("?")[0] + "?" + e.name + "=" + e.value;
}
chamber.onchange = function() { changer(this); };
session.onchange = function() { changer(this); };
</script>
';
// bill tool tip & Sort
$html .= "
<script src=\"/sites/all/themes/ffcfc/js/jquery.tablesorter.min.js\"></script>
<script>
$('#vote-tracker-table').tablesorter({
sortList: [[0,0]],
headers: {
3: { sorter: false }, 4: { sorter: false },
5: { sorter: false }, 6: { sorter: false },
7: { sorter: false }, 8: { sorter: false },
9: { sorter: false }, 10: { sorter: false },
11: { sorter: false }, 12: { sorter: false },
13: { sorter: false }, 14: { sorter: false },
15: { sorter: false }, 16: { sorter: false },
17: { sorter: false }, 18: { sorter: false },
19: { sorter: false }, 20: { sorter: false }
}
});
$(document).ready(function(){
var coord = new Array(),
boxX, boxY, boxW, boxH;
jQuery('.tt-bill').hover(
function() {
boxX = jQuery(this).parent().position().left;
boxY = jQuery(this).parent().position().top;
boxW = jQuery(this).parent().width() / 2;
boxH = jQuery(this).parent().height();
jQuery('.pagecontent .wrapper').append('<div class=\"bill-tip\"><span></span><p>'+jQuery(this).attr('title')+'</p></div>');
jQuery('.bill-tip').css({ top : boxY+boxH+9, left : boxX+boxW });
return false;
},
function() {
jQuery('.bill-tip').remove();
}
);
jQuery('.pin-a,.pin-b').css('visibility','visible');
});
</script>
";
return $html;
}
/**
* Helper Function: standard truncating
* @return string
**/
function truncate ($string, $limit, $break = ".", $pad = "...")
{
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if (false !== ($breakpoint = strpos($string, $break, $limit))) {
if ($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment