public function getRep($cons_type, $mp_house) { global $THEUSER; if (!$THEUSER->has_postcode()) { return array(); } // User is logged in and has a postcode, or not logged in with a cookied postcode. // (We don't allow the user to search for a postcode if they // already have one set in their prefs.) // this is for people who have e.g. an English postcode looking at the // Scottish homepage try { $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($THEUSER->postcode()); if (isset($constituencies[$cons_type])) { $constituency = $constituencies[$cons_type]; $MEMBER = new Member(array('constituency' => $constituency, 'house' => $mp_house)); } } catch (MemberException $e) { return array(); } if (isset($MEMBER) && $MEMBER->valid) { return $this->constructMPData($MEMBER, $THEUSER, $mp_house); } return array(); }
function get_regional_by_user_postcode($pc, $page) { global $this_page; $this_page = "your{$page}"; if ($page == 'msp' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($pc)) { regional_list($pc, 'SPC', $page); } elseif ($page == 'mla' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($pc)) { regional_list($pc, 'NIE', $page); } else { throw new MySociety\TheyWorkForYou\MemberException('Your set postcode is not in the right region.'); } }
public static function getRegionalList($postcode, $house, $type) { $db = new \ParlDB(); $dissolution_dates = array(3 => '2011-03-24', 4 => '2011-03-23'); $mreg = array(); $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); if (isset($constituencies[$type])) { $cons_name = $constituencies[$type]; $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house\n FROM member, person_names\n WHERE\n member.person_id = person_names.person_id\n AND person_names.type = 'name'\n AND constituency = :cons_name\n AND house = :house\n AND left_house >= start_date\n AND left_house <= end_date"; $q = $db->query("{$query_base} AND left_reason = 'still_in_office'", array(':house' => $house, ':cons_name' => $cons_name)); if (!$q->rows()) { $q = $db->query("{$query_base} AND left_house = :dissolution_date", array(':house' => $house, ':cons_name' => $cons_name, ':dissolution_date' => $dissolution_dates[$house])); } for ($i = 0; $i < $q->rows; $i++) { $name = member_full_name($house, $q->field($i, 'title'), $q->field($i, 'given_name'), $q->field($i, 'family_name'), $q->field($i, 'lordofname')); $mreg[] = array('person_id' => $q->field($i, 'person_id'), 'name' => $name, 'house' => $q->field($i, 'house'), 'constituency' => $q->field($i, 'constituency')); } } return $mreg; }
private function formatSearchMemberData() { if (isset($this->data['postcode'])) { try { $postcode = $this->data['postcode']; $MEMBER = new \MEMBER(array('postcode' => $postcode)); // move the postcode to the front just to be tidy $tidy_alertsearch = $postcode . " " . trim(str_replace("{$postcode}", "", $this->data['alertsearch'])); $alertsearch_display = str_replace("{$postcode} ", "", $tidy_alertsearch); $this->data['member_alertsearch'] = str_replace("{$postcode}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['member_displaysearch'] = $alertsearch_display; $this->data['member'] = $MEMBER; if ($this->data['scottish_text']) { $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); if (isset($constituencies['SPC'])) { $MEMBER = new \MEMBER(array('constituency' => $constituencies['SPC'], 'house' => 4)); $this->data['scottish_alertsearch'] = str_replace("{$postcode}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['scottish_member'] = $MEMBER; } } } catch (\MySociety\TheyWorkForYou\MemberException $e) { $this->data['member_error'] = 1; } } if ($this->data['pid']) { $MEMBER = new \MEMBER(array('person_id' => $this->data['pid'])); $this->data['pid_member'] = $MEMBER; } if ($this->data['keyword']) { $this->data['display_keyword'] = $this->prettifyCriteria($this->data['keyword']); } }
private function addRepLinks() { if ($this->user->postcode_is_set()) { $items = array('yourmp'); if (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($this->user->postcode())) { $items[] = 'yourmsp'; } elseif (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($this->user->postcode())) { $items[] = 'yourmla'; } foreach ($items as $item) { $menudata = $this->pagedata->page_metadata($item, 'menu'); $logintext = $menudata['text']; $URL = new \URL($item); $this->data['user_nav_links'][] = array('href' => $URL->generate(), 'title' => '', 'classes' => '', 'text' => $logintext); } } }