Skip to content

Commit

Permalink
[Wales] Add pages for MSs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Mar 10, 2023
1 parent 32882e6 commit 7bcfc3b
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 8 deletions.
6 changes: 6 additions & 0 deletions classes/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function isDead() {
HOUSE_TYPE_LORDS,
HOUSE_TYPE_SCOTLAND,
HOUSE_TYPE_NI,
HOUSE_TYPE_WALES,
HOUSE_TYPE_LONDON_ASSEMBLY,
);

Expand Down Expand Up @@ -430,6 +431,8 @@ public function getEnterLeaveStrings() {
$output[] = $this->left_house_line(HOUSE_TYPE_NI, 'Assembly');
$output[] = $this->entered_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament');
$output[] = $this->left_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament');
$output[] = $this->entered_house_line(HOUSE_TYPE_WALES, 'Welsh Parliament');
$output[] = $this->left_house_line(HOUSE_TYPE_WALES, 'Welsh Parliament');
$output[] = $this->entered_house_line(HOUSE_TYPE_LONDON_ASSEMBLY, 'London Assembly');
$output[] = $this->left_house_line(HOUSE_TYPE_LONDON_ASSEMBLY, 'London Assembly');

Expand Down Expand Up @@ -584,6 +587,9 @@ public static function getRepNameForHouse($house) {
case HOUSE_TYPE_SCOTLAND:
$name = 'MSP';
break;
case HOUSE_TYPE_WALES:
$name = 'MS';
break;
case HOUSE_TYPE_LONDON_ASSEMBLY:
$name = 'London Assembly Member';
break;
Expand Down
20 changes: 20 additions & 0 deletions classes/People/MSs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* MSs Class
*
* @package TheyWorkForYou
*/

namespace MySociety\TheyWorkForYou\People;

class MSs extends \MySociety\TheyWorkForYou\People {

public $type = 'mss';
public $rep_name = 'MS';
public $rep_plural = 'MSs';
public $house = HOUSE_TYPE_WALES;
public $cons_type = 'WAC';
public $reg_cons_type = 'WAE';

}

4 changes: 2 additions & 2 deletions classes/Renderer/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function get_page_keywords() {
if ($this->data['meta_keywords']) {
$this->data['meta_keywords'] .= ', ';
}
$this->data['meta_keywords'] .= 'Hansard, Official Report, Parliament, government, House of Commons, House of Lords, MP, Peer, Member of Parliament, MPs, Peers, Lords, Commons, Scottish Parliament, Northern Ireland Assembly, MSP, MLA, MSPs, MLAs, London Assembly Members';
$this->data['meta_keywords'] .= 'Hansard, Official Report, Parliament, government, House of Commons, House of Lords, MP, Peer, Member of Parliament, MPs, Peers, Lords, Commons, Scottish Parliament, Northern Ireland Assembly, MSP, MLA, MSPs, MLAs, London Assembly Members, MS, MSs, Welsh Parliament, Senedd Cymru, Senedd, Member of the Senedd';
}

$this->data['meta_description'] = "Making it easy to keep an eye on the UK’s parliaments. Discover who represents you, how they’ve voted and what they’ve said in debates.";
Expand Down Expand Up @@ -278,7 +278,7 @@ private function get_top_and_bottom_links() {
array('hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'divisions_recent', 'calendar_summary'),
array('sp_home', 'spoverview', 'msps', 'spdebatesfront', 'spwransfront'),
array('ni_home', 'nioverview', 'mlas'),
array('wales_home'),
array('wales_home', 'mss'),
array('london_home', 'lmqsfront', 'london-assembly-members'),
);

Expand Down
13 changes: 13 additions & 0 deletions classes/Utility/House.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public static function house_to_members($house) {
'singular' => 'MSP',
'plural' => 'MSPs'
),
HOUSE_TYPE_WALES => array(
'singular' => 'MS',
'plural' => 'MSs'
),
HOUSE_TYPE_LONDON_ASSEMBLY => array(
'singular' => 'Member of the London Assembly',
'plural' => 'Members of the London Assembly'
Expand Down Expand Up @@ -71,6 +75,13 @@ public static function getCountryDetails($house) {
'cons_type' => 'SPC',
'assembly_name' => 'Scottish Parliament',
),
HOUSE_TYPE_WALES => array (
'country' => 'WALES',
'assembly' => 'wales',
'location' => '&ndash; in the Senedd',
'cons_type' => 'WAC',
'assembly_name' => 'Welsh Parliament',
),
HOUSE_TYPE_LORDS => array (
'country' => 'UK',
'assembly' => 'uk-lords',
Expand Down Expand Up @@ -105,6 +116,8 @@ public static function majorToHouse($major) {
7 => array(HOUSE_TYPE_SCOTLAND),
8 => array(HOUSE_TYPE_SCOTLAND),
9 => array(HOUSE_TYPE_LONDON_ASSEMBLY),
10 => array(HOUSE_TYPE_WALES),
11 => array(HOUSE_TYPE_WALES),
101 => array(HOUSE_TYPE_LORDS),
);

Expand Down
6 changes: 3 additions & 3 deletions conf/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RewriteRule ^/mps/(c4|c4x)/$ /mps/ [R]
RewriteRule ^/mp/(c4|c4x)/([^/]+)/([^/]+)$ /mp/$2/$3 [R]

# List of rep pages
RewriteRule ^/(msp|mla|peer|london-assembly-member)s/$ /mps/index.php?representative_type=$1 [QSA]
RewriteRule ^/(msp|mla|ms|peer|london-assembly-member)s/$ /mps/index.php?representative_type=$1 [QSA]

# Section pages
RewriteRule ^/(debates|whall|wrans|wms|lords|ni|sp|spwrans|pbc|london)$ /$1/ [L,R=temporary]
Expand Down Expand Up @@ -62,10 +62,10 @@ RewriteRule ^/api/docs/?$ /api/index.php?docs=1
RewriteRule ^/api/docs/(.*)$ /api/index.php?docs=1&method=$1 [QSA]

# Other people types
RewriteRule ^/(peer|royal|mla|msp|london-assembly-member)/$ /mp/index.php?representative_type=$1 [QSA]
RewriteRule ^/(peer|royal|mla|msp|ms|london-assembly-member)/$ /mp/index.php?representative_type=$1 [QSA]
# Inherited the title in 2003
RewriteRule ^/peer/viscount_cranborne /peer/marquess_of_salisbury [R=permanent]
RewriteRule ^/(peer|royal|mla|msp|london-assembly-member)/(.+) /mp/$2?representative_type=$1 [QSA]
RewriteRule ^/(peer|royal|mla|msp|ms|london-assembly-member)/(.+) /mp/$2?representative_type=$1 [QSA]

# Calendar
RewriteRule ^/calendar/([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])$ /calendar/index.php?d=$1
Expand Down
1 change: 1 addition & 0 deletions scripts/load-people
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ my %slug_to_house_id = (
'house-of-lords' => 2,
'northern-ireland-assembly' => 3,
'scottish-parliament' => 4,
'welsh-parliament' => 5,
'london-assembly' => 6,
);

Expand Down
45 changes: 45 additions & 0 deletions www/docs/api/api_getMS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

include_once INCLUDESPATH . 'easyparliament/member.php';
include_once dirname(__FILE__) . '/api_getPerson.php';

function api_getMS_front() {
?>
<p><big>Fetch a particular MS.</big></p>

<h4>Arguments</h4>
<dl>
<dt>postcode (optional)</dt>
<dd>Fetch the MSs for a particular postcode.</dd>
<dt>constituency (optional)</dt>
<dd>The name of a constituency.</dd>
<dt>id (optional)</dt>
<dd>If you know the person ID for the member you want (returned from getMSs or elsewhere), this will return data for that person.</dd>

<dt>always_return (optional)</dt>
<dd>For the postcode and constituency options, sets whether to always try and
return an MS (due to e.g. the period before an election when there are no
MSs).</dd>

</dl>

<h4>Example Response</h4>
<pre>&lt;twfy&gt;
&lt;/twfy&gt;
</pre>

<?php
}

function api_getMS_id($id) {
return api_getPerson_id($id, HOUSE_TYPE_WALES);
}

function api_getMS_postcode($pc) {
api_getPerson_postcode($pc, HOUSE_TYPE_WALES);
}

function api_getMS_constituency($constituency) {
api_getPerson_constituency($constituency, HOUSE_TYPE_WALES);
}

46 changes: 46 additions & 0 deletions www/docs/api/api_getMSs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

include_once dirname(__FILE__) . '/api_getMembers.php';

function api_getMSs_front() {
?>
<p><big>Fetch a list of MSs.</big></p>

<h4>Arguments</h4>
<dl>
<dt>date (optional)</dt>
<dd>Fetch the list of MSs as it was on this date.</dd>
<dt>party (optional)</dt>
<dd>Fetch the list of MSs from the given party.</dd>
<dt>search (optional)</dt>
<dd>Fetch the list of MSs that match this search string in their name.</dd>
</dl>

<h4>Example Response, serialised PHP</h4>
<pre>a:646:{
i:0; a:5:{
s:9:"member_id"; s:4:"1368";
s:9:"person_id"; s:5:"10900";
s:4:"name"; s:13:"Hywel Francis";
s:5:"party"; s:6:"Labour";
s:12:"constituency"; s:8:"Aberavon";
}
i:1; ...
</pre>

<?php
}

/* See api_getMembers.php for these shared functions */
function api_getMSs_party($s) {
api_getMembers_party(HOUSE_TYPE_WALES, $s);
}
function api_getMSs_search($s) {
api_getMembers_search(HOUSE_TYPE_WALES, $s);
}
function api_getMSs_date($date) {
api_getMembers_date(HOUSE_TYPE_WALES, $date);
}
function api_getMSs($date = 'now()') {
api_getMembers(HOUSE_TYPE_WALES, $date);
}
2 changes: 2 additions & 0 deletions www/docs/api/api_getPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function api_getPerson_postcode($pc, $house) {
$types = array('NIE');
} elseif ($house == HOUSE_TYPE_SCOTLAND) {
$types = array('SPC', 'SPE');
} elseif ($house == HOUSE_TYPE_WALES) {
$types = array('WAC', 'WAE');
}
if (validate_postcode($pc)) {
$constituencies = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($pc);
Expand Down
44 changes: 42 additions & 2 deletions www/docs/mp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
case 'msp':
$this_page = 'msp';
break;
case 'ms':
$this_page = 'ms';
break;
case 'london-assembly-member':
$this_page = 'london-assembly-member';
break;
Expand Down Expand Up @@ -261,6 +264,20 @@
$title .= ' MSP, '.$MEMBER->constituency();
}

// Enhance title if this is a member of Welsh Parliament
if ($MEMBER->house(HOUSE_TYPE_WALES)) {
if ($MEMBER->house(HOUSE_TYPE_COMMONS) || $MEMBER->house(HOUSE_TYPE_LORDS)) {
$desc = str_replace('Parliament', 'the UK and Welsh Parliaments', $desc);
} else {
$desc = str_replace('Parliament', 'the Welsh Parliament', $desc);
}
$desc = str_replace(', and get email alerts on their activity', '', $desc);
if (!$MEMBER->current_member(HOUSE_TYPE_WALES)) {
$title .= ', former';
}
$title .= ' MS, '.$MEMBER->constituency();
}

$known_for = '';
$current_offices_ignoring_committees = $MEMBER->offices('current', TRUE);
if (count($current_offices_ignoring_committees) > 0) {
Expand Down Expand Up @@ -539,6 +556,8 @@ function get_regional_by_user_postcode($pc, $page) {
$this_page = "your$page";
if ($page == 'msp' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($pc)) {
regional_list($pc, 'SPC', $page);
} elseif ($page == 'ms' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsWelsh($pc)) {
regional_list($pc, 'WAC', $page);
} elseif ($page == 'mla' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($pc)) {
regional_list($pc, 'NIE', $page);
} else {
Expand Down Expand Up @@ -684,7 +703,7 @@ function person_summary_description ($MEMBER) {
$desc .= $last['from'] . ' ';
}
}
if ($house==HOUSE_TYPE_COMMONS || $house==HOUSE_TYPE_NI || $house==HOUSE_TYPE_SCOTLAND) {
if ($house==HOUSE_TYPE_COMMONS || $house==HOUSE_TYPE_NI || $house==HOUSE_TYPE_SCOTLAND || $house==HOUSE_TYPE_WALES) {
$desc .= ' ';
if ($house==HOUSE_TYPE_COMMONS) {
$desc .= '<abbr title="Member of Parliament">MP</abbr>';
Expand All @@ -695,6 +714,9 @@ function person_summary_description ($MEMBER) {
if ($house==HOUSE_TYPE_SCOTLAND) {
$desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>';
}
if ($house==HOUSE_TYPE_WALES) {
$desc .= '<abbr title="Member of the Senedd">MS</abbr>';
}
if ($party_br) {
$desc .= " ($party_br)";
}
Expand Down Expand Up @@ -984,7 +1006,7 @@ function regional_list($pc, $area_type, $rep_type) {
WHERE constituency IN ('" . join("','", $a) . "')
AND member.person_id = pn.person_id AND pn.type = 'name'
AND pn.end_date = (SELECT MAX(end_date) FROM person_names WHERE person_names.person_id = member.person_id)";
$q = $db->query($query_base . " AND left_reason = 'still_in_office' AND house in (" . HOUSE_TYPE_NI . "," . HOUSE_TYPE_SCOTLAND . ")");
$q = $db->query($query_base . " AND left_reason = 'still_in_office' AND house in (" . HOUSE_TYPE_NI . "," . HOUSE_TYPE_SCOTLAND . "," . HOUSE_TYPE_WALES . ")");
$current = true;
if (!$q->rows() && ($dissolution = MySociety\TheyWorkForYou\Dissolution::db())) {
$current = false;
Expand All @@ -1005,6 +1027,12 @@ function regional_list($pc, $area_type, $rep_type) {
} elseif ($cons == $constituencies['SPE']) {
$mreg[] = $row;
}
} elseif ($house == HOUSE_TYPE_WALES) {
if ($cons == $constituencies['WAC']) {
$mcon = $row;
} elseif ($cons == $constituencies['WAE']) {
$mreg[] = $row;
}
} else {
throw new MySociety\TheyWorkForYou\MemberException('Odd result returned!' . $house);
}
Expand All @@ -1021,6 +1049,18 @@ function regional_list($pc, $area_type, $rep_type) {
$data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MSP for ' . $mcon['constituency'];
$data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['SPE'] . ' region MSPs</strong> were:</p>';
}
} elseif ($rep_type == 'ms') {
if ($current) {
$data['members_statement'] = '<p>You have one constituency MS (Member of the Senedd) and multiple region MSs.</p>';
$data['members_statement'] .= '<p>Your <strong>constituency MS</strong> is <a href="/ms/?p=' . $mcon['person_id'] . '">';
$data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MS for ' . $mcon['constituency'];
$data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['WAE'] . ' region MSs</strong> are:</p>';
} else {
$data['members_statement'] = '<p>You had one constituency MS (Member of the Senedd) and multiple region MSs.</p>';
$data['members_statement'] .= '<p>Your <strong>constituency MS</strong> was <a href="/ms/?p=' . $mcon['person_id'] . '">';
$data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MS for ' . $mcon['constituency'];
$data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['WAE'] . ' region MSs</strong> were:</p>';
}
} else {
if ($current) {
$data['members_statement'] = '<p>You have multiple MLAs (Members of the Legislative Assembly) who represent you in ' . $constituencies['NIE'] . '. They are:</p>';
Expand Down
3 changes: 3 additions & 0 deletions www/docs/mps/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
case 'msp':
$people = new MySociety\TheyWorkForYou\People\MSPs();
break;
case 'ms':
$people = new MySociety\TheyWorkForYou\People\MSs();
break;
case 'london-assembly-member':
$people = new MySociety\TheyWorkForYou\People\LondonAssemblyMembers();
break;
Expand Down
2 changes: 2 additions & 0 deletions www/includes/easyparliament/hansardlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,8 @@ private function _get_speaker_url($house) {
$URL = new \MySociety\TheyWorkForYou\Url('mla');
} elseif ($house == HOUSE_TYPE_SCOTLAND) {
$URL = new \MySociety\TheyWorkForYou\Url('msp');
} elseif ($house == HOUSE_TYPE_WALES) {
$URL = new \MySociety\TheyWorkForYou\Url('ms');
} elseif ($house == HOUSE_TYPE_ROYAL) {
$URL = new \MySociety\TheyWorkForYou\Url('royal');
}
Expand Down
10 changes: 9 additions & 1 deletion www/includes/easyparliament/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MEMBER {
2 => 'House of Lords',
3 => 'Northern Ireland Assembly',
4 => 'Scottish Parliament',
5 => 'Senedd',
6 => 'London Assembly',
);

Expand Down Expand Up @@ -84,6 +85,7 @@ private function isHigherPriorityHouse(int $house)
if (! (bool) $this->house_disp) {
if ($house == HOUSE_TYPE_LONDON_ASSEMBLY # London Assembly
|| $house == HOUSE_TYPE_SCOTLAND # MSPs and
|| $house == HOUSE_TYPE_WALES # MSs and
|| $house == HOUSE_TYPE_NI # MLAs have lowest priority
|| $house == HOUSE_TYPE_COMMONS # MPs
) {
Expand Down Expand Up @@ -359,6 +361,8 @@ public function name_to_person_id($name, $const='') {
$params[':house'] = HOUSE_TYPE_LORDS;
} elseif ($this_page == 'msp') {
$params[':house'] = HOUSE_TYPE_SCOTLAND;
} elseif ($this_page == 'ms') {
$params[':house'] = HOUSE_TYPE_WALES;
} elseif ($this_page == 'mla') {
$params[':house'] = HOUSE_TYPE_NI;
} elseif ($this_page == 'royal') {
Expand Down Expand Up @@ -523,7 +527,7 @@ public function given_name() { return $this->given_name; }
public function family_name() { return $this->family_name; }
public function full_name($no_mp_title = false) {
$title = $this->title;
if ($no_mp_title && ($this->house_disp==HOUSE_TYPE_COMMONS || $this->house_disp==HOUSE_TYPE_NI || $this->house_disp==HOUSE_TYPE_SCOTLAND)) {
if ($no_mp_title && ($this->house_disp==HOUSE_TYPE_COMMONS || $this->house_disp==HOUSE_TYPE_NI || $this->house_disp==HOUSE_TYPE_SCOTLAND || $this->house_disp==HOUSE_TYPE_WALES)) {
$title = '';
}
return member_full_name($this->house_disp, $title, $this->given_name, $this->family_name, $this->lordofname);
Expand Down Expand Up @@ -665,6 +669,10 @@ public function url($absolute = false) {
$URL = new \MySociety\TheyWorkForYou\Url('msp');
break;

case HOUSE_TYPE_WALES:
$URL = new \MySociety\TheyWorkForYou\Url('ms');
break;

case HOUSE_TYPE_LONDON_ASSEMBLY:
$URL = new \MySociety\TheyWorkForYou\Url('london-assembly-member');
break;
Expand Down
Loading

0 comments on commit 7bcfc3b

Please sign in to comment.