private function get_voting_history($getTop = 0)
 {
     $method = "/votes";
     $params = array();
     $params[0] = array("name" => "voter_ids." . $this->politician_id . "__exists", "value" => "true");
     $params[1] = array("name" => "vote_type", "value" => "passage");
     $params[2] = array("name" => "fields", "value" => "title,question,number,year,voted_at,roll_id,roll_type,voter_ids." . $this->politician_id . ",bill.bill_id,bill.official_title,chamber,congress");
     if ($getTop > 0) {
         $params[3] = array("name" => "per_page", "value" => $getTop);
     }
     $objAPI = new Sunlight($method, $params);
     try {
         if ($objAPI) {
             $jsonResp = $objAPI->getMethodResponse();
             //Get jSON response from API
             $arrResp = json_decode($jsonResp, true);
             //Turn jSON into ARRAY
             //Iterate Through response array and build a more useful one.
             $respCounter = 0;
             $voteInfo = array();
             foreach ($arrResp['results'] as $response) {
                 $voteInfo[$respCounter] = array("roll_id" => $response["roll_id"], "roll_number" => $response["number"], "roll_year" => $response["year"], "vote_date" => $response["voted_at"], "roll_type" => $response["roll_type"], "roll_question" => $response["question"], "roll_vote" => $response["voter_ids"][$this->politician_id], "bill_id" => isset($response["bill"]["bill_id"]) ? $response["bill"]["bill_id"] : null, "bill_official_title" => isset($response["bill"]["official_title"]) ? $response["bill"]["official_title"] : null, "chamber" => $response["chamber"], "congress" => $response["congress"]);
                 $respCounter++;
             }
             return $voteInfo;
         } else {
             throw new Exception("API Error: Invalid response.");
         }
     } catch (Exception $e) {
         return false;
     }
 }
예제 #2
0
 function findPoliticians($new_query)
 {
     $method = "/legislators";
     $params = array();
     $params[0] = array("name" => "query", "value" => $new_query);
     try {
         $obj_sunlight = new Sunlight($method, $params);
     } catch (Exception $e) {
         die("Error getting data!");
     }
     $json_sunlight_response = $obj_sunlight->getMethodResponse();
     return $json_sunlight_response;
 }
예제 #3
0
 function get_results()
 {
     $method = "/bills/search";
     $params = array();
     $params[0] = array("name" => "query", "value" => urlencode($this->query));
     $params[1] = array("name" => "fields", "value" => "bill_id,bill_type,number,congress,official_title,short_title");
     $objAPI = new Sunlight($method, $params);
     try {
         if ($objAPI) {
             $jsonResponse = $objAPI->getMethodResponse();
             $arrResponse = json_decode($jsonResponse, true);
         } else {
             throw new Exception("API Error: Invalid response.");
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     return $arrResponse;
 }
예제 #4
0
 function getRecentBills()
 {
     $method = "/bills";
     $params = array();
     $params[0] = array("name" => "order", "value" => "last_action_at");
     $params[1] = array("name" => "fields", "value" => "bill_id,bill_type,number,congress,chamber,introduced_on,last_action,last_action_at,last_vote_at,last_version_on,official_title,short_title,urls.congress,sponsor_id,cosponsor_ids,last_version.urls.html,history");
     $objAPI = new Sunlight($method, $params);
     try {
         if ($objAPI) {
             $jsonResponse = $objAPI->getMethodResponse();
             return $jsonResponse;
         } else {
             throw new Exception("API Error: Invalid response.");
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         return false;
     }
     return false;
 }
예제 #5
0
 private function get_district_info()
 {
     $method = "/districts/locate";
     $params = array();
     $params[0] = array("name" => "latitude", "value" => $this->lat);
     $params[1] = array("name" => "longitude", "value" => $this->long);
     $objAPI = new Sunlight($method, $params);
     try {
         if ($objAPI) {
             $jsonResponse = $objAPI->getMethodResponse();
             $arrResponse = json_decode($jsonResponse, true);
         } else {
             throw new Exception("API Error: Invalid response.");
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     foreach ($arrResponse['results'] as $info) {
         $this->state = $info['state'];
         $this->district = $info['district'];
     }
 }
예제 #6
0
 private function get_bio_info()
 {
     $method = "/legislators";
     $params = array();
     $params[0] = array("name" => "bioguide_id", "value" => $this->politician_id);
     $objRep = new Sunlight($method, $params);
     $jsonRep = $objRep->getMethodResponse();
     $arrayRep = json_decode($jsonRep, true);
     foreach ($arrayRep['results'] as $rep) {
         $this->name_first = $rep["first_name"];
         $this->name_middle = $rep["middle_name"];
         $this->name_last = $rep["last_name"];
         $this->name_nickname = $rep["nickname"];
         $this->contact_phone = isset($rep["phone"]) ? $rep["phone"] : "Not Available";
         $this->contact_website = isset($rep["website"]) ? $rep["website"] : "Not Available";
         $this->contact_office = isset($rep["office"]) ? $rep["office"] : "Not Available";
         $this->contact_contact_form = isset($rep["contact_form"]) ? $rep["contact_form"] : "Not Available";
         $this->contact_fax = isset($rep["fax"]) ? $rep["fax"] : "Not Available";
         $this->job_title = $rep["title"];
         if (array_key_exists('district', $rep)) {
             $this->job_district = $rep["district"];
         } else {
             $this->job_district = "";
         }
         $this->state = $rep["state"];
         $this->job_term_start = $rep["term_start"];
         $this->job_term_end = $rep["term_end"];
         $this->party = $rep["party"];
         //This is deprecated...don't use it. Use
         $this->pic_link = "http://bioguide.congress.gov/bioguide/photo/" . $this->politician_id[0] . "/" . $this->politician_id . ".jpg";
         //These are better links...don't need to resize
         $this->pic_link_small = "http://theunitedstates.io/images/congress/225x275/" . $this->politician_id . ".jpg";
         $this->pic_link_medium = "http://theunitedstates.io/images/congress/450x550/" . $this->politician_id . ".jpg";
         $this->pic_link_large = "http://theunitedstates.io/images/congress/original/" . $this->politician_id . ".jpg";
         $this->twitter_id = $rep["twitter_id"];
         $this->govtrack_id = $rep["govtrack_id"];
     }
 }
예제 #7
0
 function get_bill_info($objBill)
 {
     if ($objBill) {
         $objAPI = $objBill;
     } else {
         $method = "/bills";
         $params = array();
         $params[0] = array("name" => "bill_id", "value" => $this->bill_id);
         $params[1] = array("name" => "fields", "value" => "bill_id,bill_type,number,congress,chamber,introduced_on,last_action,last_action_at,last_vote_at,last_version_on,official_title,short_title,urls.congress,sponsor_id,cosponsor_ids,last_version.urls.html,history");
         $objAPI = new Sunlight($method, $params);
     }
     try {
         if ($objAPI) {
             if ($objBill) {
                 $jsonResponse = $objAPI;
             } else {
                 $jsonResponse = $objAPI->getMethodResponse();
             }
             $arrResponse = json_decode($jsonResponse, true);
             if (!$objBill) {
                 if (count($arrResponse['results']) > 0) {
                     $arrResponse = $arrResponse['results'][0];
                 } else {
                     throw new Exception("API Error: No bill data.");
                 }
             }
             $this->bill_type = $arrResponse['bill_type'];
             $this->bill_type_display = $this->get_bill_display_type($this->bill_type);
             $this->number = $arrResponse['number'];
             $this->congress = $arrResponse['congress'];
             $this->chamber = $arrResponse['chamber'];
             $this->introduced_on = $arrResponse['introduced_on'];
             $this->last_action = $arrResponse["last_action"];
             $this->last_action_at = $arrResponse['last_action_at'];
             $this->last_vote_at = $arrResponse['last_vote_at'];
             if (!empty($arrResponse['last_version_on'])) {
                 $this->last_version_on = $arrResponse['last_version_on'];
             } else {
                 $this->last_version_on = null;
             }
             $this->official_title = $arrResponse['official_title'];
             $this->short_title = $arrResponse['short_title'];
             $this->url_congress = $arrResponse['urls']['congress'];
             $this->sponsor_id = $arrResponse['sponsor_id'];
             $this->cosponsor_ids = $arrResponse['cosponsor_ids'];
             if (!empty($arrResponse['last_version']['urls']['html'])) {
                 $this->last_version_url = $arrResponse['last_version']['urls']['html'];
             } else {
                 $this->last_version_url = null;
             }
             $this->history = $arrResponse['history'];
             $this->set_status_images();
         } else {
             throw new Exception("API Error: Invalid response.");
         }
     } catch (Exception $e) {
         //echo $e->getMessage();
     }
 }
예제 #8
0
 function display_senators_state()
 {
     $method = "/legislators";
     $params = array();
     $params[0] = array("name" => "state", "value" => $this->state);
     $params[1] = array("name" => "chamber", "value" => "senate");
     $params[2] = array("name" => "in_office", "value" => "true");
     $objReps = new Sunlight($method, $params);
     $jsonReps = $objReps->getMethodResponse();
     $arrayReps = json_decode($jsonReps, true);
     $reps = array();
     $repCounter = 0;
     foreach ($arrayReps['results'] as $rep) {
         $reps[$repCounter] = array("pNameFirst" => $rep["first_name"], "pNameLast" => $rep["last_name"], "pNameMiddle" => $rep["middle_name"], "pNamePreferred" => $rep["nickname"], "jobTitle" => $rep["title"], "picLink" => "none", "pID" => $rep["bioguide_id"]);
         $repCounter++;
     }
     return $reps;
 }
예제 #9
0
 private function get_roll_info()
 {
     $method = "/votes";
     $params = array();
     $params[0] = array("name" => "congress", "value" => $this->congress);
     $params[1] = array("name" => "roll_id", "value" => $this->roll_id);
     $params[2] = array("name" => "fields", "value" => "voter_ids,chamber,number,year,voted_at,vote_type,roll_type,question,required,result,bill_id,bill,nomination_id,nomination");
     $objSunlightResp = new Sunlight($method, $params);
     $jsonSunlightResp = $objSunlightResp->getMethodResponse();
     $arraySunlightResp = json_decode($jsonSunlightResp, true);
     foreach ($arraySunlightResp['results'] as $vote) {
         $this->number = $vote["number"];
         $this->year = $vote["year"];
         $this->chamber = $vote["chamber"];
         $this->voted_at = $vote["voted_at"];
         $this->vote_type = $vote["vote_type"];
         $this->bill_id = isset($vote["bill_id"]) ? $vote["bill_id"] : "";
         //Set nomination variables
         if (isset($vote["nomination_id"])) {
             $this->nomination_id = $vote["nomination_id"];
             $this->nomination = $vote["nomination"];
             $this->nomination["nomination_of"] = "of " . $this->nomination["nominees"][0]["name"] . " to be " . $this->nomination["nominees"][0]["position"];
         } else {
             $this->nomination_id = "";
             $this->nomination = "";
         }
         $this->roll_type = $vote["roll_type"];
         $this->question = $vote["question"];
         $this->required = $vote["required"];
         $this->result = $vote["result"];
         $this->voter_ids = $vote["voter_ids"];
         //Take the vote_type and generate a textual description
         //TODO: These need to be more in depth
         switch ($this->vote_type) {
             case 'passage':
                 $this->vote_type_description = "This is a vote on passage of a bill.";
                 break;
             case 'cloture':
                 if ($this->bill_id != "") {
                     $motion_reference = "a bill";
                 } elseif ($this->nomination_id != "") {
                     $motion_reference = "the nomination " . $this->nomination["nomination_of"];
                 } else {
                     $motion_reference = "undefined";
                 }
                 $this->vote_type_description = "This is a vote to end debate on " . $motion_reference . ". If a cloture motion is agreed to then debate will end, and a vote will be taken.";
                 break;
             case 'nomination':
                 $this->vote_type_description = "A Vote " . $this->question . " " . $this->nomination["nomination_of"];
                 break;
             case 'impeachment':
                 $this->vote_type_description = "This is a vote on impeachment.";
                 break;
             case 'treaty':
                 $this->vote_type_description = "This is a vote on a treaty.";
                 break;
             case 'recommit':
                 $this->vote_type_description = "This is a vote on a motion to recommit.";
                 break;
             case 'quorum':
                 $this->vote_type_description = "This is a vote on quorum.";
                 break;
             case 'leadership':
                 $this->vote_type_description = "This is a vote on leadership.";
                 break;
             case 'ammendment':
                 $this->vote_type_description = "This is a vote on an amendment.";
             default:
                 $this->vote_type_description = "This was a procedural vote.";
         }
     }
 }