private function getNewMP($confirmation) { if (!$confirmation) { return array(); } $existing = $this->alert->fetch_by_token($confirmation); preg_match('/speaker:(\\d+)/', $existing['criteria'], $matches); $criteria = $matches[1]; $old_mp = new \MySociety\TheyWorkForYou\Member(array('person_id' => $criteria)); $new_mp = new \MySociety\TheyWorkForYou\Member(array('constituency' => $old_mp->constituency, 'house' => 1)); if ($this->alert->fetch_by_mp($existing['email'], $new_mp->person_id)) { $data = array('already_signed_up' => True, 'old_mp' => $old_mp->full_name(), 'mp_name' => $new_mp->full_name()); } else { $data = array('old_mp' => $old_mp->full_name(), 'new_mp' => $new_mp->full_name()); } $data['update'] = True; $data['confirmation'] = $confirmation; return $data; }
function get_person_by_postcode($pc) { global $THEUSER; $pc = preg_replace('#[^a-z0-9]#i', '', $pc); if (!validate_postcode($pc)) { twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn’t a valid postcode'); } twfy_debug('MP', "MP lookup by postcode"); $constituency = strtolower(postcode_to_constituency($pc)); if ($constituency == "connection_timed_out") { throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn’t check your postcode right now, as our postcode lookup server is under quite a lot of load.'); } elseif ($constituency == "") { twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn’t a known postcode'); } else { // Redirect to the canonical MP page, with a person id. $MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS)); if ($MEMBER->person_id()) { // This will cookie the postcode. $THEUSER->set_postcode_cookie($pc); } member_redirect($MEMBER, 302); } }
private function find_constituency($args) { if ($args['s'] != '') { $searchterm = $args['s']; } else { return false; } list($constituencies, ) = search_constituencies_by_query($searchterm); $constituency = ""; if (count($constituencies) == 1) { $constituency = $constituencies[0]; } $cons = array(); $mp_types = array('mp' => 0, 'former' => 0); if ($constituency != '') { try { // Got a match, display.... $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => 1)); $cons[] = $MEMBER; if ($MEMBER->current_member(1)) { $mp_types['mp']++; } else { $mp_types['former']++; } } catch (\MySociety\TheyWorkForYou\MemberException $e) { $cons = array(); } } elseif (count($constituencies)) { foreach ($constituencies as $constituency) { try { $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => 1)); $cons[] = $MEMBER; if ($MEMBER->current_member(1)) { $mp_types['mp']++; } else { $mp_types['former']++; } } catch (\MySociety\TheyWorkForYou\MemberException $e) { continue; } } } return array($cons, $mp_types); }
public function testGetEntryDate() { $MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => 18)); $this->assertEquals($MEMBER->getEntryDate(), '2014-05-01'); $this->assertEquals($MEMBER->getEntryDate(1), '2014-05-01'); $this->assertEquals($MEMBER->getEntryDate(2), '2010-05-01'); $this->assertEquals($MEMBER->getEntryDate(3), '2012-05-01'); $this->assertEquals($MEMBER->getEntryDate(4), '2004-05-01'); $this->assertEquals($MEMBER->getEntryDate(5), ''); }