Permalink
Browse files

The canonical form of the Scottish Parliament constituencies uses " a…

…nd ", not " & "
  • Loading branch information...
1 parent 4781c10 commit 2174d5a01df34446a768f1c63d7ab4436420b2d5 marklon committed May 19, 2009
Showing with 32 additions and 19 deletions.
  1. +22 −11 website/constituencies.inc
  2. +3 −3 website/decodeids.inc
  3. +3 −2 website/election.php
  4. +3 −2 website/election2007.php
  5. +1 −1 website/postcode.inc
View
@@ -1,24 +1,35 @@
<?php
-# $Id: constituencies.inc,v 1.14 2008/10/13 16:44:36 publicwhip Exp $
+# $Id: constituencies.inc,v 1.15 2009/05/19 14:56:08 marklon Exp $
# The Public Whip, Copyright (C) 2005 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under
# certain conditions. However, it comes with ABSOLUTELY NO WARRANTY.
# For details see the file LICENSE.html in the top level of the source.
-function normalise_constituency_name($db, $name, $parl = null) {
- // Use &amp; everywhere, as in DB
- $name = str_replace("&amp;", "&", $name);
- $name = str_replace(" and ", " & ", $name);
- $name = str_replace("&", "&amp;", $name);
- $name = str_replace("&amp;#39;", "&#39;", $name);
- $name = str_replace(" ", " ", $name);
- $name = trim($name);
- $name = db_scrub($name);
+function normalise_constituency_name($db, $name, $house = null, $parl = null) {
+ if ($house && ($house == 'scotland')) {
+ // For Scotland, the " and " version is canonical:
+ $name = str_replace("&amp;", "and", $name);
+ $name = str_replace("&", "and", $name);
+ $name = str_replace(" ", " ", $name);
+ $name = trim($name);
+ $name = db_scrub($name);
+ } else {
+ // Otherwise use &amp; everywhere (as in the DB for everywhere except Scotland)
+ $name = str_replace("&amp;", "&", $name);
+ $name = str_replace(" and ", " & ", $name);
+ $name = str_replace("&", "&amp;", $name);
+ $name = str_replace("&amp;#39;", "&#39;", $name);
+ $name = str_replace(" ", " ", $name);
+ $name = trim($name);
+ $name = db_scrub($name);
+ }
$qsel = "SELECT name, cons_id FROM pw_constituency";
$qwhere = " WHERE main_name".($parl ? " AND from_date < '$parl' and '$parl' < to_date" : "");
- $qwhere2 = " AND name LIKE '$name'";
+ $qwhere2 = " AND name LIKE '$name'";
+ if( $house )
+ $qwhere2 .= "AND house = '$house'";
$qorder = " ORDER BY to_date DESC LIMIT 1";
$sth1 = $db->query_onez_row_assoc($qsel.$qwhere.$qwhere2.$qorder);
View
@@ -1,5 +1,5 @@
<?php
-# $Id: decodeids.inc,v 1.48 2009/05/19 14:47:21 marklon Exp $
+# $Id: decodeids.inc,v 1.49 2009/05/19 14:56:08 marklon Exp $
# The Public Whip, Copyright (C) 2005 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under
@@ -37,7 +37,7 @@ function get_mpid_attr($db, $db2, $mpid, $bbyconstituency, $i, $voter2dream_over
# get the mpids in this class, for the person, or all reps of a constituency
if ($bbyconstituency)
- $qwhere = "constituency = '".db_scrub($constituency)."'";
+ $qwhere = "constituency = '".db_scrub($constituency)."' AND house = '".db_scrub($house)."'";
else
$qwhere = "person = $person";
@@ -247,7 +247,7 @@ function get_mpid_attr_decode($db, $db2, $i, $voter2dream_overlap=null, $pc_parl
{
$constituency = strtolower(stripslashes(html_entity_decode($mpconstituency)));
$constituency = str_replace("_", " ", $constituency);
- $constituency = normalise_constituency_name($db, $constituency);
+ $constituency = normalise_constituency_name($db, $constituency, $mphouse);
$constituency = db_scrub($constituency);
if ($constituency == "")
{
View
@@ -1,6 +1,6 @@
<?php require_once "common.inc";
-# $Id: election.php,v 1.26 2007/07/26 16:10:35 publicwhip Exp $
+# $Id: election.php,v 1.27 2009/05/19 14:56:08 marklon Exp $
# The Public Whip, Copyright (C) 2003 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under
@@ -333,14 +333,15 @@ function opinion_value($value, $curr)
# See if MP is standing again
$mpattr = $mpattr['mpprops'][0];
$constituency = str_replace("&amp;", "&", $mpattr['constituency']);
+ $house = $mpattr['house'];
$standing_again = false;
if ($mpattr['leftreason'] == "general_election_standing") {
$standing_again = true;
}
# Regional parties
- $consid = normalise_constituency_name($db, strtolower($constituency), "2001");
+ $consid = normalise_constituency_name($db, strtolower($constituency), $house, "2001");
if (!$consid) {
print "<div class=\"error\">Constituency '$constituency' not found, please <a href=\"team@publicwhip.org.uk\">let us know</a>.</div>";
exit;
View
@@ -1,6 +1,6 @@
<?php require_once "common.inc";
-# $Id: election2007.php,v 1.19 2007/10/04 23:13:51 publicwhip Exp $
+# $Id: election2007.php,v 1.20 2009/05/19 14:56:08 marklon Exp $
# The Public Whip, Copyright (C) 2003 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under
@@ -169,6 +169,7 @@
# See if MP is standing again
$mpattr = $mpattr['mpprops'][0];
$constituency = str_replace("&amp;", "&", $mpattr['constituency']);
+ $house = $mpattr['house'];
$standing_again = false;
if ($mpattr['leftreason'] == "general_election_notstanding") {
@@ -177,7 +178,7 @@
$standing_again = true; # XXX remove me
# Regional parties
- $consid = normalise_constituency_name($db, strtolower($constituency), "2001");
+ $consid = normalise_constituency_name($db, strtolower($constituency), $house, "2001");
if (!$consid) {
print "<div class=\"error\">Constituency '$constituency' not found, please <a href=\"team@publicwhip.org.uk\">let us know</a>.</div>";
# exit;
View
@@ -182,7 +182,7 @@ function postcode_to_constituency_internal($db, $postcode, $pc_parl)
# Convert to canonical name
# print "<pre>$file</pre><br>$constituency<br>";
# print $consnames[$consmatch[strtolower($constituency)]];
- $normalised = normalise_constituency_name($db, strtolower($constituency), $pc_parl);
+ $normalised = normalise_constituency_name($db, strtolower($constituency), 'commons', $pc_parl);
if ($normalised)
return $normalised;
else

0 comments on commit 2174d5a

Please sign in to comment.