|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* index.php |
|
5
|
|
|
* |
|
6
|
|
|
* For displaying info about a person for a postcode or constituency. |
|
7
|
|
|
* |
|
8
|
|
|
* This page accepts either 'm' (a member_id), 'pid' (a person_id), |
|
9
|
|
|
* 'c' (a postcode or constituency), or 'n' (a name). |
|
10
|
|
|
* |
|
11
|
|
|
* First, we check to see if a person_id's been submitted. |
|
12
|
|
|
* If so, we display that person. |
|
13
|
|
|
* |
|
14
|
|
|
* Else, we check to see if a member_id's been submitted. |
|
15
|
|
|
* If so, we display that person. |
|
16
|
|
|
* |
|
17
|
|
|
* Otherwise, we then check to see if a postcode's been submitted. |
|
18
|
|
|
* If it's valid we put it in a cookie. |
|
19
|
|
|
* |
|
20
|
|
|
* If no postcode, we check to see if a constituency's been submitted. |
|
21
|
|
|
* |
|
22
|
|
|
* If neither has been submitted, we see if either the user is logged in |
|
23
|
|
|
* and has a postcode set or the user has a cookied postcode from a previous |
|
24
|
|
|
* search. |
|
25
|
|
|
* |
|
26
|
|
|
* If we have a valid constituency after all this, we display its MP. |
|
27
|
|
|
* |
|
28
|
|
|
* Either way, we print the forms. |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
// Disable the old PAGE class. |
|
32
|
|
|
$new_style_template = TRUE; |
|
33
|
|
|
|
|
34
|
|
|
// Include all the things this page needs. |
|
35
|
|
|
include_once '../../includes/easyparliament/init.php'; |
|
36
|
|
|
include_once INCLUDESPATH . 'easyparliament/member.php'; |
|
|
|
|
|
|
37
|
|
|
include_once INCLUDESPATH . 'technorati.php'; |
|
38
|
|
|
include_once INCLUDESPATH . '../../commonlib/phplib/random.php'; |
|
39
|
|
|
include_once INCLUDESPATH . '../../commonlib/phplib/auth.php'; |
|
40
|
|
|
include_once '../api/api_getGeometry.php'; |
|
41
|
|
|
include_once '../api/api_getConstituencies.php'; |
|
42
|
|
|
|
|
43
|
|
|
// Ensure that page type is set |
|
44
|
|
|
if (get_http_var('pagetype')) { |
|
45
|
|
|
$pagetype = get_http_var('pagetype'); |
|
46
|
|
|
} else { |
|
47
|
|
|
$pagetype = 'profile'; |
|
48
|
|
|
} |
|
49
|
|
|
if ($pagetype == 'profile') { |
|
50
|
|
|
$pagetype = ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// list of years for which we have WTT response stats in |
|
54
|
|
|
// reverse chronological order. Add new years here as we |
|
55
|
|
|
// get them. |
|
56
|
|
|
// NB: also need to update ./mpinfoin.pl to import the stats |
|
57
|
|
|
$wtt_stats_years = array(2015, 2014, 2013, 2008, 2007, 2006, 2005); |
|
58
|
|
|
|
|
59
|
|
|
// Set the PID, name and constituency. |
|
60
|
|
|
$pid = get_http_var('pid') != '' ? get_http_var('pid') : get_http_var('p'); |
|
61
|
|
|
$name = strtolower(str_replace('_', ' ', get_http_var('n'))); |
|
62
|
|
|
$constituency = strtolower(str_replace('_', ' ', get_http_var('c'))); |
|
63
|
|
|
|
|
64
|
|
|
// Fix for names with non-ASCII characters |
|
65
|
|
|
if ($name == 'sion simon') $name = 'si\xf4n simon'; |
|
66
|
|
|
if ($name == 'sian james') $name = 'si\xe2n james'; |
|
67
|
|
|
if ($name == 'lembit opik') $name = 'lembit \xf6pik'; |
|
68
|
|
|
if ($name == 'bairbre de brun') $name = 'bairbre de br\xfan'; |
|
69
|
|
|
if ($name == 'daithi mckay') $name = 'daith\xed mckay'; |
|
70
|
|
|
if ($name == 'caral ni chuilin') $name = 'car\xe1l n\xed chuil\xedn'; |
|
71
|
|
|
if ($name == 'caledon du pre') $name = 'caledon du pr\xe9'; |
|
72
|
|
|
if ($name == 'sean etchingham') $name = 'se\xe1n etchingham'; |
|
73
|
|
|
if ($name == 'john tinne') $name = 'john tinn\xe9'; |
|
74
|
|
|
if ($name == 'renee short') $name = 'ren\xe9e short'; |
|
75
|
|
|
|
|
76
|
|
|
// Fix for common misspellings, name changes etc |
|
77
|
|
|
$name_fix = array( |
|
78
|
|
|
'a j beith' => 'alan beith', |
|
79
|
|
|
'micky brady' => 'mickey brady', |
|
80
|
|
|
'daniel rogerson' => 'dan rogerson', |
|
81
|
|
|
'andrew slaughter' => 'andy slaughter', |
|
82
|
|
|
'robert wilson' => array('rob wilson', 'reading east'), |
|
83
|
|
|
'james mcgovern' => 'jim mcgovern', |
|
84
|
|
|
'patrick mcfadden' => 'pat mcfadden', |
|
85
|
|
|
'chris leslie' => 'christopher leslie', |
|
86
|
|
|
'joseph meale' => 'alan meale', |
|
87
|
|
|
'james sheridan' => 'jim sheridan', |
|
88
|
|
|
'chinyelu onwurah' => 'chi onwurah', |
|
89
|
|
|
'steve rotherham' => 'steve rotheram', |
|
90
|
|
|
'michael weatherley' => 'mike weatherley', |
|
91
|
|
|
'louise bagshawe' => 'louise mensch', |
|
92
|
|
|
'andrew sawford' => 'andy sawford', |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
if (array_key_exists($name, $name_fix)) { |
|
96
|
|
|
if (is_array($name_fix[$name])) { |
|
97
|
|
|
if ($constituency == $name_fix[$name][1]) { |
|
98
|
|
|
$name = $name_fix[$name][0]; |
|
99
|
|
|
} |
|
100
|
|
|
} else { |
|
101
|
|
|
$name = $name_fix[$name]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
// Fixes for Ynys Mon, and a Unicode URL |
|
106
|
|
|
if ($constituency == 'ynys mon') $constituency = "ynys m\xf4n"; |
|
107
|
|
|
if (preg_match("#^ynys m\xc3\xb4n#i", $constituency)) { |
|
108
|
|
|
$constituency = "ynys m\xf4n"; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// If this is a request for recent appearances, redirect to search results |
|
112
|
|
|
if (get_http_var('recent')) { |
|
113
|
|
|
if ($THEUSER->postcode_is_set() && !$pid) { |
|
114
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('postcode' => $THEUSER->postcode(), 'house' => HOUSE_TYPE_COMMONS)); |
|
115
|
|
|
if ($MEMBER->person_id()) { |
|
116
|
|
|
$pid = $MEMBER->person_id(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
if ($pid) { |
|
120
|
|
|
$URL = new \MySociety\TheyWorkForYou\Url('search'); |
|
121
|
|
|
$URL->insert( array('pid'=>$pid, 'pop'=>1) ); |
|
122
|
|
|
header('Location: ' . $URL->generate('none')); |
|
123
|
|
|
exit; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
///////////////////////////////////////////////////////// |
|
128
|
|
|
// DETERMINE TYPE OF REPRESENTITIVE |
|
129
|
|
|
if (get_http_var('peer')) $this_page = 'peer'; |
|
130
|
|
|
elseif (get_http_var('royal')) $this_page = 'royal'; |
|
131
|
|
|
elseif (get_http_var('mla')) $this_page = 'mla'; |
|
132
|
|
|
elseif (get_http_var('msp')) $this_page = 'msp'; |
|
133
|
|
|
else $this_page = 'mp'; |
|
134
|
|
|
|
|
135
|
|
|
try { |
|
136
|
|
|
if (is_numeric($pid)) { |
|
137
|
|
|
$MEMBER = get_person_by_id($pid); |
|
138
|
|
|
} elseif (is_numeric(get_http_var('m'))) { |
|
139
|
|
|
get_person_by_member_id(get_http_var('m')); |
|
140
|
|
|
} elseif (get_http_var('pc')) { |
|
141
|
|
|
get_person_by_postcode(get_http_var('pc')); |
|
142
|
|
|
} elseif ($name) { |
|
143
|
|
|
$MEMBER = get_person_by_name($name, $constituency); |
|
144
|
|
|
} elseif ($constituency) { |
|
145
|
|
|
get_mp_by_constituency($constituency); |
|
146
|
|
|
} elseif (($this_page == 'msp' || $this_page == 'mla') && $THEUSER->postcode_is_set()) { |
|
147
|
|
|
get_regional_by_user_postcode($THEUSER->postcode(), $this_page); |
|
148
|
|
|
exit; |
|
149
|
|
|
} elseif ($THEUSER->postcode_is_set()) { |
|
150
|
|
|
get_mp_by_user_postcode($THEUSER->postcode()); |
|
151
|
|
|
} else { |
|
152
|
|
|
twfy_debug ('MP', "We don't have any way of telling what MP to display"); |
|
153
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Sorry, but we can’t tell which representative to display.'); |
|
154
|
|
|
} |
|
155
|
|
|
if (!isset($MEMBER) || !$MEMBER->valid) { |
|
156
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('You haven’t provided a way of identifying which representative you want'); |
|
157
|
|
|
} |
|
158
|
|
|
} catch (MySociety\TheyWorkForYou\MemberMultipleException $e) { |
|
159
|
|
|
person_list_page($e->ids); |
|
160
|
|
|
exit; |
|
161
|
|
|
} catch (MySociety\TheyWorkForYou\MemberException $e) { |
|
162
|
|
|
person_error_page($e->getMessage()); |
|
163
|
|
|
exit; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
# We have successfully looked up one person to show now. |
|
167
|
|
|
|
|
168
|
|
|
if (!DEVSITE) { |
|
|
|
|
|
|
169
|
|
|
header('Cache-Control: max-age=900'); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
twfy_debug_timestamp("before load_extra_info"); |
|
173
|
|
|
$MEMBER->load_extra_info(true); |
|
174
|
|
|
twfy_debug_timestamp("after load_extra_info"); |
|
175
|
|
|
|
|
176
|
|
|
// Basic name, title and description |
|
177
|
|
|
$member_name = ucfirst($MEMBER->full_name()); |
|
178
|
|
|
$title = $member_name; |
|
179
|
|
|
$desc = "Read $member_name's contributions to Parliament, including speeches and questions"; |
|
180
|
|
|
|
|
181
|
|
|
// Enhance description if this is a current member |
|
182
|
|
|
if ($MEMBER->current_member_anywhere()) |
|
183
|
|
|
$desc .= ', investigate their voting record, and get email alerts on their activity'; |
|
184
|
|
|
|
|
185
|
|
|
// Enhance title if this is a member of the Commons |
|
186
|
|
|
if ($MEMBER->house(HOUSE_TYPE_COMMONS)) { |
|
187
|
|
|
if (!$MEMBER->current_member(1)) { |
|
188
|
|
|
$title .= ', former'; |
|
189
|
|
|
} |
|
190
|
|
|
$title .= ' MP'; |
|
191
|
|
|
if ($MEMBER->constituency()) $title .= ', ' . $MEMBER->constituency(); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
// Enhance title if this is a member of NIA |
|
195
|
|
|
if ($MEMBER->house(HOUSE_TYPE_NI)) { |
|
196
|
|
|
if ($MEMBER->house(HOUSE_TYPE_COMMONS) || $MEMBER->house(HOUSE_TYPE_LORDS)) { |
|
197
|
|
|
$desc = str_replace('Parliament', 'Parliament and the Northern Ireland Assembly', $desc); |
|
198
|
|
|
} else { |
|
199
|
|
|
$desc = str_replace('Parliament', 'the Northern Ireland Assembly', $desc); |
|
200
|
|
|
} |
|
201
|
|
|
if (!$MEMBER->current_member(HOUSE_TYPE_NI)) { |
|
202
|
|
|
$title .= ', former'; |
|
203
|
|
|
} |
|
204
|
|
|
$title .= ' MLA'; |
|
205
|
|
|
if ($MEMBER->constituency()) $title .= ', ' . $MEMBER->constituency(); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
// Enhance title if this is a member of Scottish Parliament |
|
209
|
|
|
if ($MEMBER->house(HOUSE_TYPE_SCOTLAND)) { |
|
210
|
|
|
if ($MEMBER->house(HOUSE_TYPE_COMMONS) || $MEMBER->house(HOUSE_TYPE_LORDS)) { |
|
211
|
|
|
$desc = str_replace('Parliament', 'the UK and Scottish Parliaments', $desc); |
|
212
|
|
|
} else { |
|
213
|
|
|
$desc = str_replace('Parliament', 'the Scottish Parliament', $desc); |
|
214
|
|
|
} |
|
215
|
|
|
$desc = str_replace(', and get email alerts on their activity', '', $desc); |
|
216
|
|
|
if (!$MEMBER->current_member(HOUSE_TYPE_SCOTLAND)) { |
|
217
|
|
|
$title .= ', former'; |
|
218
|
|
|
} |
|
219
|
|
|
$title .= ' MSP, '.$MEMBER->constituency(); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
$positions = array(); |
|
223
|
|
|
|
|
224
|
|
|
// Position if this is a member of the Commons |
|
225
|
|
|
if ($MEMBER->house(HOUSE_TYPE_COMMONS)) { |
|
226
|
|
|
$position = $MEMBER->current_member(HOUSE_TYPE_COMMONS) ? 'MP' : 'Former MP'; |
|
227
|
|
|
if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency(); |
|
228
|
|
|
$positions[] = $position; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
// Position if this is a member of NIA |
|
232
|
|
|
if ($MEMBER->house(HOUSE_TYPE_NI)) { |
|
233
|
|
|
$position = $MEMBER->current_member(HOUSE_TYPE_NI) ? 'MLA' : 'Former MLA'; |
|
234
|
|
|
if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency(); |
|
235
|
|
|
$positions[] = $position; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
// Position if this is a member of Scottish Parliament |
|
239
|
|
|
if ($MEMBER->house(HOUSE_TYPE_SCOTLAND)) { |
|
240
|
|
|
$position = $MEMBER->current_member(HOUSE_TYPE_SCOTLAND) ? 'MSP' : 'Former MSP'; |
|
241
|
|
|
$position .= ', ' . $MEMBER->constituency(); |
|
242
|
|
|
$positions[] = $position; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$position = implode('; ', $positions); |
|
246
|
|
|
|
|
247
|
|
|
$current_offices = $MEMBER->offices('current', TRUE); |
|
248
|
|
|
$former_offices = $MEMBER->offices('previous', TRUE); |
|
249
|
|
|
|
|
250
|
|
|
// If this person has named non-committee offices, they override the default |
|
251
|
|
|
if (count($current_offices) > 0) { |
|
252
|
|
|
$position = $current_offices[0]; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
// Finally, if this is a Votes page, replace the page description with |
|
256
|
|
|
// something more descriptive of the actual data on the page. |
|
257
|
|
|
if ($pagetype == 'votes') { |
|
258
|
|
|
$title = "Voting record - " . $title; |
|
259
|
|
|
$desc = 'See how ' . $member_name . ' voted on topics like Employment, Social Issues, Foreign Policy, and more.'; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
// Set page metadata |
|
263
|
|
|
$DATA->set_page_metadata($this_page, 'title', $title); |
|
264
|
|
|
$DATA->set_page_metadata($this_page, 'meta_description', $desc); |
|
265
|
|
|
|
|
266
|
|
|
// Build the RSS link and add it to page data. |
|
267
|
|
|
$feedurl = $DATA->page_metadata('mp_rss', 'url') . $MEMBER->person_id() . '.rdf'; |
|
268
|
|
|
if (file_exists(BASEDIR . '/' . $feedurl)) |
|
269
|
|
|
$DATA->set_page_metadata($this_page, 'rss', $feedurl); |
|
270
|
|
|
|
|
271
|
|
|
// Prepare data for the template |
|
272
|
|
|
$data['full_name'] = $MEMBER->full_name(); |
|
273
|
|
|
$data['person_id'] = $MEMBER->person_id(); |
|
274
|
|
|
$data['member_id'] = $MEMBER->member_id(); |
|
275
|
|
|
|
|
276
|
|
|
$data['header_position'] = $position; |
|
277
|
|
|
|
|
278
|
|
|
$data['constituency'] = $MEMBER->constituency(); |
|
279
|
|
|
$data['party'] = $MEMBER->party_text(); |
|
280
|
|
|
$data['party_short'] = $MEMBER->getShortParty(); |
|
281
|
|
|
$data['current_member_anywhere'] = $MEMBER->current_member_anywhere(); |
|
282
|
|
|
$data['current_member'] = $MEMBER->current_member(); |
|
283
|
|
|
$data['the_users_mp'] = $MEMBER->the_users_mp(); |
|
284
|
|
|
$data['user_postcode'] = $THEUSER->postcode; |
|
285
|
|
|
$data['houses'] = $MEMBER->houses(); |
|
286
|
|
|
$data['member_url'] = $MEMBER->url(); |
|
287
|
|
|
$data['abs_member_url'] = $MEMBER->url(true); |
|
288
|
|
|
// If there's photo attribution information, copy it into data |
|
289
|
|
|
foreach (['photo_attribution_text', 'photo_attribution_link'] as $key) { |
|
290
|
|
|
if (isset($MEMBER->extra_info[$key])) { |
|
291
|
|
|
$data[$key] = $MEMBER->extra_info[$key]; |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
$data['profile_message'] = isset($MEMBER->extra_info['profile_message']) ? $MEMBER->extra_info['profile_message'] : ''; |
|
295
|
|
|
$data['image'] = $MEMBER->image(); |
|
296
|
|
|
$data['member_summary'] = person_summary_description($MEMBER); |
|
297
|
|
|
$data['enter_leave'] = $MEMBER->getEnterLeaveStrings(); |
|
298
|
|
|
$data['entry_date'] = $MEMBER->getEntryDate(); |
|
299
|
|
|
$data['leave_date'] = $MEMBER->getLeftDate(); |
|
300
|
|
|
$data['is_new_mp'] = $MEMBER->isNew(); |
|
301
|
|
|
$data['other_parties'] = $MEMBER->getOtherPartiesString(); |
|
302
|
|
|
$data['other_constituencies'] = $MEMBER->getOtherConstituenciesString(); |
|
303
|
|
|
$data['rebellion_rate'] = person_rebellion_rate($MEMBER); |
|
304
|
|
|
$data['recent_appearances'] = person_recent_appearances($MEMBER); |
|
305
|
|
|
$data['useful_links'] = person_useful_links($MEMBER); |
|
306
|
|
|
$data['social_links'] = person_social_links($MEMBER); |
|
307
|
|
|
$data['topics_of_interest'] = person_topics($MEMBER); |
|
308
|
|
|
$data['current_offices'] = $MEMBER->offices('current'); |
|
309
|
|
|
$data['previous_offices'] = $MEMBER->offices('previous'); |
|
310
|
|
|
$data['register_interests'] = person_register_interests($MEMBER, $MEMBER->extra_info); |
|
311
|
|
|
$data['eu_stance'] = $MEMBER->getEUStance(); |
|
312
|
|
|
|
|
313
|
|
|
# People who are or were MPs and Lords potentially have voting records, except Sinn Fein MPs |
|
314
|
|
|
$data['has_voting_record'] = ( ($MEMBER->house(HOUSE_TYPE_COMMONS) && $MEMBER->party() != 'Sinn Féin') || $MEMBER->house(HOUSE_TYPE_LORDS) ); |
|
315
|
|
|
# Everyone who is currently somewhere has email alert signup, apart from current Sinn Fein MPs who are not MLAs |
|
316
|
|
|
$data['has_email_alerts'] = ($MEMBER->current_member_anywhere() && !($MEMBER->current_member(HOUSE_TYPE_COMMONS) && $MEMBER->party() == 'Sinn Féin' && !$MEMBER->current_member(HOUSE_TYPE_NI))); |
|
317
|
|
|
$data['has_expenses'] = $data['leave_date'] > '2004-01-01'; |
|
318
|
|
|
|
|
319
|
|
|
$data['pre_2010_expenses'] = False; |
|
320
|
|
|
$data['post_2010_expenses'] = $data['leave_date'] > '2010-05-05'; |
|
321
|
|
|
|
|
322
|
|
|
if ($data['entry_date'] < '2010-05-05') { |
|
323
|
|
|
$data['pre_2010_expenses'] = True; |
|
324
|
|
|
// Set the expenses URL if we know it |
|
325
|
|
|
if (isset($MEMBER->extra_info['expenses_url'])) { |
|
326
|
|
|
$data['expenses_url_2004'] = $MEMBER->extra_info['expenses_url']; |
|
327
|
|
|
} else { |
|
328
|
|
|
$data['expenses_url_2004'] = 'http://mpsallowances.parliament.uk/mpslordsandoffices/hocallowances/allowances%2Dby%2Dmp/'; |
|
329
|
|
|
} |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
$data['constituency_previous_mps'] = constituency_previous_mps($MEMBER); |
|
333
|
|
|
$data['constituency_future_mps'] = constituency_future_mps($MEMBER); |
|
334
|
|
|
$data['public_bill_committees'] = person_pbc_membership($MEMBER); |
|
335
|
|
|
$data['numerology'] = person_numerology($MEMBER, $data['has_email_alerts'], $wtt_stats_years); |
|
336
|
|
|
$data['wtt_strings'] = get_all_writetothem_strings($MEMBER, $wtt_stats_years); |
|
337
|
|
|
|
|
338
|
|
|
$data['this_page'] = $this_page; |
|
339
|
|
|
$data['current_assembly'] = 'westminster'; |
|
340
|
|
|
if ( $this_page == 'msp' || $this_page == 'yourmsp' ) { |
|
341
|
|
|
$data['current_assembly'] = 'scotland'; |
|
342
|
|
|
} else if ( $this_page == 'mla' || $this_page == 'yourmla' ) { |
|
343
|
|
|
$data['current_assembly'] = 'ni'; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
$data['policy_last_update'] = MySociety\TheyWorkForYou\Divisions::getMostRecentDivisionDate(); |
|
347
|
|
|
|
|
348
|
|
|
// Do any necessary extra work based on the page type, and send for rendering. |
|
349
|
|
|
switch ($pagetype) { |
|
350
|
|
|
|
|
351
|
|
|
case 'votes': |
|
352
|
|
|
$policy_set = get_http_var('policy'); |
|
353
|
|
|
|
|
354
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
355
|
|
|
$divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER); |
|
356
|
|
|
$policySummaries = $divisions->getMemberDivisionDetails(); |
|
357
|
|
|
|
|
358
|
|
|
$policyOptions = array( 'summaries' => $policySummaries); |
|
359
|
|
|
|
|
360
|
|
|
// Generate voting segments |
|
361
|
|
|
$set_descriptions = $policiesList->getSetDescriptions(); |
|
362
|
|
|
if ( $policy_set && array_key_exists($policy_set, $set_descriptions) ) { |
|
363
|
|
|
$data['key_votes_segments'] = array( |
|
364
|
|
|
array( |
|
365
|
|
|
'key' => $policy_set, |
|
366
|
|
|
'title' => $set_descriptions[$policy_set], |
|
367
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
368
|
|
|
$policiesList->limitToSet($policy_set), $MEMBER, $policyOptions |
|
369
|
|
|
) |
|
370
|
|
|
) |
|
371
|
|
|
); |
|
372
|
|
|
$data['og_image'] = $MEMBER->url(true) . "/policy_set_png?policy_set=" . $policy_set; |
|
373
|
|
|
$data['page_title'] = $policiesList->getSetDescriptions()[$policy_set] . ' ' . $title . ' - TheyWorkForYou'; |
|
374
|
|
|
$data['meta_description'] = 'See how ' . $data['full_name'] . ' voted on ' . $policiesList->getSetDescriptions()[$policy_set]; |
|
375
|
|
|
$data['single_policy_page'] = true; |
|
376
|
|
|
} else { |
|
377
|
|
|
$data['single_policy_page'] = false; |
|
378
|
|
|
$data['key_votes_segments'] = array( |
|
379
|
|
|
array( |
|
380
|
|
|
'key' => 'social', |
|
381
|
|
|
'title' => $set_descriptions['social'], |
|
382
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
383
|
|
|
$policiesList->limitToSet('social'), $MEMBER, $policyOptions |
|
384
|
|
|
) |
|
385
|
|
|
), |
|
386
|
|
|
array( |
|
387
|
|
|
'key' => 'foreignpolicy', |
|
388
|
|
|
'title' => $set_descriptions['foreignpolicy'], |
|
389
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
390
|
|
|
$policiesList->limitToSet('foreignpolicy'), $MEMBER, $policyOptions |
|
391
|
|
|
) |
|
392
|
|
|
), |
|
393
|
|
|
array( |
|
394
|
|
|
'key' => 'welfare', |
|
395
|
|
|
'title' => $set_descriptions['welfare'], |
|
396
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
397
|
|
|
$policiesList->limitToSet('welfare'), $MEMBER, $policyOptions |
|
398
|
|
|
) |
|
399
|
|
|
), |
|
400
|
|
|
array( |
|
401
|
|
|
'key' => 'taxation', |
|
402
|
|
|
'title' => $set_descriptions['taxation'], |
|
403
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
404
|
|
|
$policiesList->limitToSet('taxation'), $MEMBER, $policyOptions |
|
405
|
|
|
) |
|
406
|
|
|
), |
|
407
|
|
|
array( |
|
408
|
|
|
'key' => 'business', |
|
409
|
|
|
'title' => $set_descriptions['business'], |
|
410
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
411
|
|
|
$policiesList->limitToSet('business'), $MEMBER, $policyOptions |
|
412
|
|
|
) |
|
413
|
|
|
), |
|
414
|
|
|
array( |
|
415
|
|
|
'key' => 'health', |
|
416
|
|
|
'title' => $set_descriptions['health'], |
|
417
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
418
|
|
|
$policiesList->limitToSet('health'), $MEMBER, $policyOptions |
|
419
|
|
|
) |
|
420
|
|
|
), |
|
421
|
|
|
array( |
|
422
|
|
|
'key' => 'education', |
|
423
|
|
|
'title' => $set_descriptions['education'], |
|
424
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
425
|
|
|
$policiesList->limitToSet('education'), $MEMBER, $policyOptions |
|
426
|
|
|
) |
|
427
|
|
|
), |
|
428
|
|
|
array( |
|
429
|
|
|
'key' => 'reform', |
|
430
|
|
|
'title' => $set_descriptions['reform'], |
|
431
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
432
|
|
|
$policiesList->limitToSet('reform'), $MEMBER, $policyOptions |
|
433
|
|
|
) |
|
434
|
|
|
), |
|
435
|
|
|
array( |
|
436
|
|
|
'key' => 'home', |
|
437
|
|
|
'title' => $set_descriptions['home'], |
|
438
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
439
|
|
|
$policiesList->limitToSet('home'), $MEMBER, $policyOptions |
|
440
|
|
|
) |
|
441
|
|
|
), |
|
442
|
|
|
array( |
|
443
|
|
|
'key' => 'environment', |
|
444
|
|
|
'title' => $set_descriptions['environment'], |
|
445
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
446
|
|
|
$policiesList->limitToSet('environment'), $MEMBER, $policyOptions |
|
447
|
|
|
) |
|
448
|
|
|
), |
|
449
|
|
|
array( |
|
450
|
|
|
'key' => 'transport', |
|
451
|
|
|
'title' => $set_descriptions['transport'], |
|
452
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
453
|
|
|
$policiesList->limitToSet('transport'), $MEMBER, $policyOptions |
|
454
|
|
|
) |
|
455
|
|
|
), |
|
456
|
|
|
array( |
|
457
|
|
|
'key' => 'housing', |
|
458
|
|
|
'title' => $set_descriptions['housing'], |
|
459
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
460
|
|
|
$policiesList->limitToSet('housing'), $MEMBER, $policyOptions |
|
461
|
|
|
) |
|
462
|
|
|
), |
|
463
|
|
|
array( |
|
464
|
|
|
'key' => 'misc', |
|
465
|
|
|
'title' => $set_descriptions['misc'], |
|
466
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
467
|
|
|
$policiesList->limitToSet('misc'), $MEMBER, $policyOptions |
|
468
|
|
|
) |
|
469
|
|
|
) |
|
470
|
|
|
); |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
// Send the output for rendering |
|
474
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/votes', $data); |
|
475
|
|
|
|
|
476
|
|
|
break; |
|
477
|
|
|
|
|
478
|
|
|
case 'recent': |
|
479
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
480
|
|
|
$positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
481
|
|
|
$divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList); |
|
482
|
|
|
|
|
483
|
|
|
$data['divisions'] = $divisions->getRecentMemberDivisions(); |
|
484
|
|
|
|
|
485
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/recent', $data); |
|
486
|
|
|
|
|
487
|
|
|
break; |
|
488
|
|
|
|
|
489
|
|
|
case 'divisions': |
|
490
|
|
|
$policyID = get_http_var('policy'); |
|
491
|
|
|
if ( $policyID ) { |
|
492
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies( $policyID ); |
|
493
|
|
|
} else { |
|
494
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
495
|
|
|
} |
|
496
|
|
|
$positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
497
|
|
|
$divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList); |
|
498
|
|
|
|
|
499
|
|
|
if ( $policyID ) { |
|
500
|
|
|
$data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID); |
|
501
|
|
|
} else { |
|
502
|
|
|
$data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy(); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
// Send the output for rendering |
|
506
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/divisions', $data); |
|
507
|
|
|
|
|
508
|
|
|
break; |
|
509
|
|
|
|
|
510
|
|
|
case 'policy_set_svg': |
|
511
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
512
|
|
|
$set_descriptions = $policiesList->getSetDescriptions(); |
|
513
|
|
|
$policy_set = get_http_var('policy_set'); |
|
514
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
515
|
|
|
|
|
516
|
|
|
if (!array_key_exists($policy_set, $set_descriptions)) { |
|
517
|
|
|
header('HTTP/1.0 404 Not Found'); |
|
518
|
|
|
exit(); |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
// Generate voting segments |
|
522
|
|
|
$data['segment'] = array( |
|
523
|
|
|
'key' => $policy_set, |
|
524
|
|
|
'title' => $policiesList->getSetDescriptions()[$policy_set], |
|
525
|
|
|
'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
526
|
|
|
$policiesList->limitToSet($policy_set), $MEMBER |
|
527
|
|
|
) |
|
528
|
|
|
); |
|
529
|
|
|
|
|
530
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/votes_svg', $data, true); |
|
531
|
|
|
break; |
|
532
|
|
|
|
|
533
|
|
|
case 'policy_set_png': |
|
534
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
535
|
|
|
$set_descriptions = $policiesList->getSetDescriptions(); |
|
536
|
|
|
$policy_set = get_http_var('policy_set'); |
|
537
|
|
|
|
|
538
|
|
|
if (!array_key_exists($policy_set, $set_descriptions)) { |
|
539
|
|
|
header('HTTP/1.0 404 Not Found'); |
|
540
|
|
|
exit(); |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
$im = new Imagick(); |
|
544
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
545
|
|
|
|
|
546
|
|
|
$url = $MEMBER->url(true) . "/policy_set_svg?policy_set=" . $policy_set; |
|
547
|
|
|
$svg = file_get_contents($url); |
|
548
|
|
|
$im->setOption('-antialias', true); |
|
|
|
|
|
|
549
|
|
|
$im->readImageBlob($svg); |
|
550
|
|
|
$im->setImageFormat("png24"); |
|
551
|
|
|
|
|
552
|
|
|
$filename = strtolower(str_replace(' ', '_', $MEMBER->full_name() . "_" . $policiesList->getSetDescriptions()[$policy_set] . ".png")); |
|
553
|
|
|
header("Content-type: image/png"); |
|
554
|
|
|
header('Content-Disposition: filename="' . $filename . '"'); |
|
555
|
|
|
print $im->getImageBlob(); |
|
556
|
|
|
|
|
557
|
|
|
$im->clear(); |
|
558
|
|
|
$im->destroy(); |
|
559
|
|
|
|
|
560
|
|
|
break; |
|
561
|
|
|
case '': |
|
562
|
|
|
default: |
|
|
|
|
|
|
563
|
|
|
|
|
564
|
|
|
$policiesList = new MySociety\TheyWorkForYou\Policies; |
|
565
|
|
|
$policies = $policiesList->limitToSet('summary')->shuffle(); |
|
566
|
|
|
$divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER); |
|
567
|
|
|
$policySummaries = $divisions->getMemberDivisionDetails(); |
|
568
|
|
|
|
|
569
|
|
|
$policyOptions = array('limit' => 6, 'summaries' => $policySummaries); |
|
570
|
|
|
|
|
571
|
|
|
// Generate limited voting record list |
|
572
|
|
|
$data['policyPositions'] = new MySociety\TheyWorkForYou\PolicyPositions($policies, $MEMBER, $policyOptions); |
|
573
|
|
|
|
|
574
|
|
|
// generate party policy diffs |
|
575
|
|
|
$party = new MySociety\TheyWorkForYou\Party($MEMBER->party()); |
|
576
|
|
|
$positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
577
|
|
|
$party_positions = $party->getAllPolicyPositions($policiesList); |
|
578
|
|
|
$policy_diffs = $MEMBER->getPartyPolicyDiffs($party, $policiesList, $positions, true); |
|
579
|
|
|
|
|
580
|
|
|
$data['sorted_diffs'] = $policy_diffs; |
|
581
|
|
|
# house hard coded as this is only used for the party position |
|
582
|
|
|
# comparison which is Commons only |
|
583
|
|
|
$data['party_member_count'] = $party->getCurrentMemberCount(HOUSE_TYPE_COMMONS); |
|
584
|
|
|
$data['party_positions'] = $party_positions; |
|
585
|
|
|
$data['positions'] = $positions->positionsById; |
|
586
|
|
|
$data['policies'] = $policiesList->getPolicies(); |
|
587
|
|
|
|
|
588
|
|
|
// Send the output for rendering |
|
589
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/profile', $data); |
|
590
|
|
|
|
|
591
|
|
|
break; |
|
592
|
|
|
|
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
|
|
596
|
|
|
///////////////////////////////////////////////////////// |
|
597
|
|
|
// SUPPORTING FUNCTIONS |
|
598
|
|
|
|
|
599
|
|
|
/* Person lookup functions */ |
|
600
|
|
|
|
|
601
|
|
|
function get_person_by_id($pid) { |
|
602
|
|
|
global $pagetype, $this_page; |
|
|
|
|
|
|
603
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); |
|
604
|
|
|
if (!$MEMBER->valid) { |
|
605
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Sorry, that ID number wasn’t recognised.'); |
|
606
|
|
|
} |
|
607
|
|
|
// Ensure that we're actually at the current, correct and canonical URL for the person. If not, redirect. |
|
608
|
|
|
// No need to worry about other URL syntax forms for vote pages, they shouldn't happen. |
|
609
|
|
|
$at = str_replace('/mp/', "/$this_page/", get_http_var('url')); |
|
610
|
|
|
$shouldbe = urldecode($MEMBER->url()); |
|
611
|
|
|
if ($pagetype) { |
|
612
|
|
|
$shouldbe .= "/$pagetype"; |
|
613
|
|
|
} |
|
614
|
|
|
if ($at !== $shouldbe) { |
|
615
|
|
|
member_redirect($MEMBER, 301, $pagetype); |
|
616
|
|
|
} |
|
617
|
|
|
return $MEMBER; |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
function get_person_by_member_id($member_id) { |
|
621
|
|
|
// Got a member id, redirect to the canonical MP page, with a person id. |
|
622
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('member_id' => $member_id)); |
|
623
|
|
|
member_redirect($MEMBER); |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
function get_person_by_postcode($pc) { |
|
627
|
|
|
global $THEUSER; |
|
|
|
|
|
|
628
|
|
|
$pc = preg_replace('#[^a-z0-9]#i', '', $pc); |
|
629
|
|
|
if (!validate_postcode($pc)) { |
|
630
|
|
|
twfy_debug ('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); |
|
631
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn’t a valid postcode'); |
|
632
|
|
|
} |
|
633
|
|
|
twfy_debug ('MP', "MP lookup by postcode"); |
|
634
|
|
|
$constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc)); |
|
635
|
|
|
if ($constituency == "connection_timed_out") { |
|
636
|
|
|
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.'); |
|
637
|
|
|
} elseif ($constituency == "") { |
|
638
|
|
|
twfy_debug ('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
|
639
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn’t a known postcode'); |
|
640
|
|
|
} else { |
|
641
|
|
|
// Redirect to the canonical MP page, with a person id. |
|
642
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS)); |
|
643
|
|
|
if ($MEMBER->person_id()) { |
|
644
|
|
|
// This will cookie the postcode. |
|
645
|
|
|
$THEUSER->set_postcode_cookie($pc); |
|
646
|
|
|
} |
|
647
|
|
|
member_redirect($MEMBER, 302); |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
function get_person_by_name($name, $const='') { |
|
652
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('name' => $name, 'constituency' => $const)); |
|
653
|
|
|
// Edge case, only attempt further detection if this isn't the Queen. |
|
654
|
|
|
if ($name !== 'elizabeth the second' || $const) { |
|
655
|
|
|
twfy_debug ('MP', 'Redirecting for MP found by name/constituency'); |
|
656
|
|
|
member_redirect($MEMBER); |
|
657
|
|
|
} |
|
658
|
|
|
return $MEMBER; |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
function get_mp_by_constituency($constituency) { |
|
662
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS)); |
|
663
|
|
|
member_redirect($MEMBER); |
|
664
|
|
|
} |
|
665
|
|
|
|
|
666
|
|
|
function get_regional_by_user_postcode($pc, $page) { |
|
667
|
|
|
global $this_page; |
|
|
|
|
|
|
668
|
|
|
$this_page = "your$page"; |
|
669
|
|
|
if ($page == 'msp' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($pc)) { |
|
670
|
|
|
regional_list($pc, 'SPC', $page); |
|
671
|
|
|
} elseif ($page == 'mla' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($pc)) { |
|
672
|
|
|
regional_list($pc, 'NIE', $page); |
|
673
|
|
|
} else { |
|
674
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Your set postcode is not in the right region.'); |
|
675
|
|
|
} |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
function get_mp_by_user_postcode($pc) { |
|
679
|
|
|
$MEMBER = new MySociety\TheyWorkForYou\Member(array('postcode' => $pc, 'house' => HOUSE_TYPE_COMMONS)); |
|
680
|
|
|
member_redirect($MEMBER, 302); |
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
/** |
|
684
|
|
|
* Member Redirect |
|
685
|
|
|
* |
|
686
|
|
|
* Redirect to the canonical page for a member. |
|
687
|
|
|
*/ |
|
688
|
|
|
|
|
689
|
|
|
function member_redirect (&$MEMBER, $code = 301, $pagetype = NULL) { |
|
690
|
|
|
// We come here after creating a MEMBER object by various methods. |
|
691
|
|
|
// Now we redirect to the canonical MP page, with a person_id. |
|
692
|
|
|
if ($MEMBER->person_id()) { |
|
693
|
|
|
$url = $MEMBER->url(); |
|
694
|
|
|
$params = array(); |
|
695
|
|
|
foreach ($_GET as $key => $value) { |
|
696
|
|
|
if (substr($key, 0, 4) == 'utm_' || $key == 'gclid') |
|
697
|
|
|
$params[] = "$key=$value"; |
|
698
|
|
|
} |
|
699
|
|
|
if (count($params)) |
|
700
|
|
|
$url .= '?' . join('&', $params); |
|
701
|
|
|
if ($pagetype) { |
|
702
|
|
|
$pagetype = '/' . $pagetype; |
|
703
|
|
|
} else { |
|
704
|
|
|
$pagetype = ''; |
|
705
|
|
|
} |
|
706
|
|
|
header('Location: ' . $url . $pagetype, true, $code ); |
|
707
|
|
|
exit; |
|
708
|
|
|
} |
|
709
|
|
|
} |
|
710
|
|
|
|
|
711
|
|
|
/* Error list page */ |
|
712
|
|
|
|
|
713
|
|
|
function person_list_page($ids) { |
|
714
|
|
|
global $name; |
|
|
|
|
|
|
715
|
|
|
if (!DEVSITE) { |
|
|
|
|
|
|
716
|
|
|
header('Cache-Control: max-age=900'); |
|
717
|
|
|
} |
|
718
|
|
|
$data = array('mps' => array()); |
|
719
|
|
|
foreach ($ids as $id => $constituency) { |
|
720
|
|
|
$data['mps'][] = array( |
|
721
|
|
|
'url' => WEBPATH . 'mp/?pid=' . $id, |
|
|
|
|
|
|
722
|
|
|
'name' => ucwords(strtolower($name)) . ', ' . $constituency, |
|
723
|
|
|
); |
|
724
|
|
|
} |
|
725
|
|
|
$MPSURL = new \MySociety\TheyWorkForYou\Url('mps'); |
|
726
|
|
|
$data['all_mps_url'] = $MPSURL->generate(); |
|
727
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/list', $data); |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
/* Error page */ |
|
731
|
|
|
|
|
732
|
|
|
function person_error_page($message) { |
|
733
|
|
|
global $this_page; |
|
|
|
|
|
|
734
|
|
|
switch($this_page) { |
|
735
|
|
|
case 'mla': |
|
736
|
|
|
$rep = 'MLA'; |
|
737
|
|
|
$SEARCHURL = '/postcode/'; |
|
738
|
|
|
$MPSURL = new \MySociety\TheyWorkForYou\Url('mlas'); |
|
739
|
|
|
break; |
|
740
|
|
|
case 'msp': |
|
741
|
|
|
$rep = 'MSP'; |
|
742
|
|
|
$SEARCHURL = '/postcode/'; |
|
743
|
|
|
$MPSURL = new \MySociety\TheyWorkForYou\Url('msps'); |
|
744
|
|
|
break; |
|
745
|
|
|
case 'peer': |
|
746
|
|
|
$rep = 'Lord'; |
|
747
|
|
|
$SEARCHURL = ''; |
|
748
|
|
|
$MPSURL = new \MySociety\TheyWorkForYou\Url('peers'); |
|
749
|
|
|
break; |
|
750
|
|
|
default: |
|
751
|
|
|
$rep = 'MP'; |
|
752
|
|
|
$SEARCHURL = new \MySociety\TheyWorkForYou\Url('mp'); |
|
753
|
|
|
$SEARCHURL = $SEARCHURL->generate(); |
|
754
|
|
|
$MPSURL = new \MySociety\TheyWorkForYou\Url('mps'); |
|
755
|
|
|
} |
|
756
|
|
|
|
|
757
|
|
|
$data = array( |
|
758
|
|
|
'error' => $message, |
|
759
|
|
|
'rep_name' => $rep, |
|
760
|
|
|
'all_mps_url' => $MPSURL->generate(), |
|
761
|
|
|
'rep_search_url' => $SEARCHURL, |
|
762
|
|
|
); |
|
763
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/error', $data); |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
/** |
|
767
|
|
|
* Person Positions Summary |
|
768
|
|
|
* |
|
769
|
|
|
* Generate the summary of this person's held positions. |
|
770
|
|
|
*/ |
|
771
|
|
|
|
|
772
|
|
|
function person_summary_description ($MEMBER) { |
|
773
|
|
|
$entered_house = $MEMBER->entered_house(); |
|
774
|
|
|
$current_member = $MEMBER->current_member(); |
|
775
|
|
|
$left_house = $MEMBER->left_house(); |
|
776
|
|
|
|
|
777
|
|
|
if (in_array(HOUSE_TYPE_ROYAL, $MEMBER->houses())) { # Royal short-circuit |
|
778
|
|
|
return '<strong>Acceded on ' . $entered_house[HOUSE_TYPE_ROYAL]['date_pretty'] |
|
779
|
|
|
. '<br>Coronated on 2 June 1953</strong></li>'; |
|
780
|
|
|
} |
|
781
|
|
|
$desc = ''; |
|
782
|
|
|
foreach ($MEMBER->houses() as $house) { |
|
783
|
|
|
if ($house==HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) |
|
784
|
|
|
continue; # Same info is printed further down |
|
785
|
|
|
|
|
786
|
|
|
if (!$current_member[$house]) $desc .= 'Former '; |
|
787
|
|
|
|
|
788
|
|
|
$party = $left_house[$house]['party']; |
|
789
|
|
|
$party_br = ''; |
|
790
|
|
|
if (preg_match('#^(.*?)\s*\((.*?)\)$#', $party, $m)) { |
|
791
|
|
|
$party_br = $m[2]; |
|
792
|
|
|
$party = $m[1]; |
|
793
|
|
|
} |
|
794
|
|
|
if ($party != 'unknown') |
|
795
|
|
|
$desc .= _htmlentities($party); |
|
796
|
|
|
if ($party == 'Speaker' || $party == 'Deputy Speaker') { |
|
797
|
|
|
$desc .= ', and '; |
|
798
|
|
|
# XXX: Might go horribly wrong if something odd happens |
|
799
|
|
|
if ($party == 'Deputy Speaker') { |
|
800
|
|
|
$last = end($MEMBER->other_parties); |
|
801
|
|
|
$desc .= $last['from'] . ' '; |
|
802
|
|
|
} |
|
803
|
|
|
} |
|
804
|
|
|
if ($house==HOUSE_TYPE_COMMONS || $house==HOUSE_TYPE_NI || $house==HOUSE_TYPE_SCOTLAND) { |
|
805
|
|
|
$desc .= ' '; |
|
806
|
|
|
if ($house==HOUSE_TYPE_COMMONS) $desc .= '<abbr title="Member of Parliament">MP</abbr>'; |
|
807
|
|
|
if ($house==HOUSE_TYPE_NI) $desc .= '<abbr title="Member of the Legislative Assembly">MLA</abbr>'; |
|
808
|
|
|
if ($house==HOUSE_TYPE_SCOTLAND) $desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>'; |
|
809
|
|
|
if ($party_br) { |
|
810
|
|
|
$desc .= " ($party_br)"; |
|
811
|
|
|
} |
|
812
|
|
|
$desc .= ' for ' . $left_house[$house]['constituency']; |
|
813
|
|
|
} |
|
814
|
|
|
if ($house==HOUSE_TYPE_LORDS && $party != 'Bishop') $desc .= ' Peer'; |
|
815
|
|
|
$desc .= ', '; |
|
816
|
|
|
} |
|
817
|
|
|
$desc = preg_replace('#, $#', '', $desc); |
|
818
|
|
|
return $desc; |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
/** |
|
822
|
|
|
* Person Rebellion Rate |
|
823
|
|
|
* |
|
824
|
|
|
* How often has this person rebelled against their party? |
|
825
|
|
|
* |
|
826
|
|
|
* @param MEMBER $member The member to calculate rebellion rate for. |
|
827
|
|
|
* |
|
828
|
|
|
* @return string A HTML summary of this person's rebellion rate. |
|
829
|
|
|
*/ |
|
830
|
|
|
|
|
831
|
|
|
function person_rebellion_rate ($member) { |
|
832
|
|
|
|
|
833
|
|
|
// Rebellion string may be empty. |
|
834
|
|
|
$rebellion_string = ''; |
|
835
|
|
|
|
|
836
|
|
|
if (isset($member->extra_info['public_whip_rebellions']) && $member->extra_info['public_whip_rebellions'] != 'n/a') { |
|
837
|
|
|
$displayed_stuff = 1; |
|
|
|
|
|
|
838
|
|
|
$rebels_term = 'rebelled'; |
|
839
|
|
|
|
|
840
|
|
|
$rebellion_string = 'has <a href="http://www.publicwhip.org.uk/mp.php?id=uk.org.publicwhip/member/' . $member->member_id() . '#divisions" title="See more details at Public Whip"><strong>' . _htmlentities($member->extra_info['public_whip_rebel_description']) . ' ' . $rebels_term . '</strong></a> against their party'; |
|
841
|
|
|
|
|
842
|
|
|
if (isset($member->extra_info['public_whip_rebelrank'])) { |
|
843
|
|
|
if ($member->extra_info['public_whip_data_date'] == 'complete') { |
|
844
|
|
|
$rebellion_string .= ' in their last parliament.'; |
|
845
|
|
|
} else { |
|
846
|
|
|
$rebellion_string .= ' in the current parliament.'; |
|
847
|
|
|
} |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
$rebellion_string .= ' <small><a title="What do the rebellion figures mean exactly?" href="http://www.publicwhip.org.uk/faq.php#clarify">Find out more</a>.</small>'; |
|
851
|
|
|
} |
|
852
|
|
|
|
|
853
|
|
|
return $rebellion_string; |
|
854
|
|
|
|
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
|
function person_recent_appearances($member) { |
|
858
|
|
|
global $DATA, $SEARCHENGINE, $this_page; |
|
|
|
|
|
|
859
|
|
|
|
|
860
|
|
|
$out = array(); |
|
861
|
|
|
$out['appearances'] = array(); |
|
862
|
|
|
|
|
863
|
|
|
//$this->block_start(array('id'=>'hansard', 'title'=>$title)); |
|
|
|
|
|
|
864
|
|
|
// This is really far from ideal - I don't really want $PAGE to know |
|
865
|
|
|
// anything about HANSARDLIST / DEBATELIST / WRANSLIST. |
|
866
|
|
|
// But doing this any other way is going to be a lot more work for little |
|
867
|
|
|
// benefit unfortunately. |
|
868
|
|
|
twfy_debug_timestamp(); |
|
869
|
|
|
|
|
870
|
|
|
$person_id= $member->person_id(); |
|
871
|
|
|
|
|
872
|
|
|
$memcache = new MySociety\TheyWorkForYou\Memcache; |
|
873
|
|
|
$recent = $memcache->get('recent_appear:' . $person_id); |
|
874
|
|
|
|
|
875
|
|
|
if (!$recent) { |
|
|
|
|
|
|
876
|
|
|
// Initialise the search engine |
|
877
|
|
|
$searchstring = "speaker:$person_id"; |
|
878
|
|
|
$SEARCHENGINE = new \SEARCHENGINE($searchstring); |
|
879
|
|
|
|
|
880
|
|
|
$hansard = new MySociety\TheyWorkForYou\Hansard(); |
|
881
|
|
|
$args = array ( |
|
882
|
|
|
's' => $searchstring, |
|
883
|
|
|
'p' => 1, |
|
884
|
|
|
'num' => 3, |
|
885
|
|
|
'pop' => 1, |
|
886
|
|
|
'o' => 'd', |
|
887
|
|
|
); |
|
888
|
|
|
$results = $hansard->search($searchstring, $args); |
|
889
|
|
|
$recent = serialize($results['rows']); |
|
890
|
|
|
$memcache->set('recent_appear:' . $person_id, $recent); |
|
891
|
|
|
} |
|
892
|
|
|
$out['appearances'] = unserialize($recent); |
|
893
|
|
|
twfy_debug_timestamp(); |
|
894
|
|
|
|
|
895
|
|
|
$MOREURL = new \MySociety\TheyWorkForYou\Url('search'); |
|
896
|
|
|
$MOREURL->insert( array('pid'=>$person_id, 'pop'=>1) ); |
|
897
|
|
|
|
|
898
|
|
|
$out['more_href'] = $MOREURL->generate() . '#n4'; |
|
899
|
|
|
$out['more_text'] = 'More of ' . ucfirst($member->full_name()) . '’s recent appearances'; |
|
900
|
|
|
|
|
901
|
|
|
if ($rssurl = $DATA->page_metadata($this_page, 'rss')) { |
|
902
|
|
|
// If we set an RSS feed for this page. |
|
903
|
|
|
$HELPURL = new \MySociety\TheyWorkForYou\Url('help'); |
|
904
|
|
|
$out['additional_links'] = '<a href="' . WEBPATH . $rssurl . '" title="XML version of this person’s recent appearances">RSS feed</a> (<a href="' . $HELPURL->generate() . '#rss" title="An explanation of what RSS feeds are for">?</a>)'; |
|
|
|
|
|
|
905
|
|
|
} |
|
906
|
|
|
|
|
907
|
|
|
return $out; |
|
908
|
|
|
|
|
909
|
|
|
} |
|
910
|
|
|
|
|
911
|
|
|
function person_useful_links($member) { |
|
912
|
|
|
|
|
913
|
|
|
$links = $member->extra_info(); |
|
914
|
|
|
|
|
915
|
|
|
$out = array(); |
|
916
|
|
|
|
|
917
|
|
|
if (isset($links['maiden_speech'])) { |
|
918
|
|
|
$maiden_speech = fix_gid_from_db($links['maiden_speech']); |
|
919
|
|
|
$out[] = array( |
|
920
|
|
|
'href' => WEBPATH . 'debate/?id=' . $maiden_speech, |
|
|
|
|
|
|
921
|
|
|
'text' => 'Maiden speech' |
|
922
|
|
|
); |
|
923
|
|
|
} |
|
924
|
|
|
|
|
925
|
|
|
// BIOGRAPHY. |
|
926
|
|
|
global $THEUSER; |
|
|
|
|
|
|
927
|
|
|
if (isset($links['mp_website'])) { |
|
928
|
|
|
$out[] = array( |
|
929
|
|
|
'href' => $links['mp_website'], |
|
930
|
|
|
'text' => 'Personal website' |
|
931
|
|
|
); |
|
932
|
|
|
} |
|
933
|
|
|
|
|
934
|
|
|
if (isset($links['sp_url'])) { |
|
935
|
|
|
$out[] = array( |
|
936
|
|
|
'href' => $links['sp_url'], |
|
937
|
|
|
'text' => 'Page on the Scottish Parliament website' |
|
938
|
|
|
); |
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
if (isset($links['wikipedia_url'])) { |
|
942
|
|
|
$out[] = array( |
|
943
|
|
|
'href' => $links['wikipedia_url'], |
|
944
|
|
|
'text' => 'Wikipedia page' |
|
945
|
|
|
); |
|
946
|
|
|
} |
|
947
|
|
|
|
|
948
|
|
|
if (isset($links['bbc_profile_url'])) { |
|
949
|
|
|
$out[] = array( |
|
950
|
|
|
'href' => $links['bbc_profile_url'], |
|
951
|
|
|
'text' => 'BBC News profile' |
|
952
|
|
|
); |
|
953
|
|
|
} |
|
954
|
|
|
|
|
955
|
|
|
if (isset($links['diocese_url'])) { |
|
956
|
|
|
$out[] = array( |
|
957
|
|
|
'href' => $links['diocese_url'], |
|
958
|
|
|
'text' => 'Diocese website' |
|
959
|
|
|
); |
|
960
|
|
|
} |
|
961
|
|
|
|
|
962
|
|
|
#if ($member->house(HOUSE_TYPE_COMMONS)) { |
|
|
|
|
|
|
963
|
|
|
# $out[] = array( |
|
|
|
|
|
|
964
|
|
|
# 'href' => 'http://www.edms.org.uk/mps/' . $member->person_id(), |
|
|
|
|
|
|
965
|
|
|
# 'text' => 'Early Day Motions signed by this MP' |
|
|
|
|
|
|
966
|
|
|
# ); |
|
967
|
|
|
#} |
|
968
|
|
|
|
|
969
|
|
|
if (isset($links['journa_list_link'])) { |
|
970
|
|
|
$out[] = array( |
|
971
|
|
|
'href' => $links['journa_list_link'], |
|
972
|
|
|
'text' => 'Newspaper articles written by this MP' |
|
973
|
|
|
); |
|
974
|
|
|
} |
|
975
|
|
|
|
|
976
|
|
|
return $out; |
|
977
|
|
|
} |
|
978
|
|
|
|
|
979
|
|
|
function person_social_links($member) { |
|
980
|
|
|
|
|
981
|
|
|
$links = $member->extra_info(); |
|
982
|
|
|
|
|
983
|
|
|
$out = array(); |
|
984
|
|
|
|
|
985
|
|
|
if (isset($links['twitter_username'])) { |
|
986
|
|
|
$out[] = array( |
|
987
|
|
|
'href' => 'https://twitter.com/' . _htmlentities($links['twitter_username']), |
|
988
|
|
|
'text' => '@' . _htmlentities($links['twitter_username']), |
|
989
|
|
|
'type' => 'twitter' |
|
990
|
|
|
); |
|
991
|
|
|
} |
|
992
|
|
|
|
|
993
|
|
|
if (isset($links['facebook_page'])) { |
|
994
|
|
|
$out[] = array( |
|
995
|
|
|
'href' => _htmlentities($links['facebook_page']), |
|
996
|
|
|
'text' => _htmlentities($links['facebook_page']), |
|
997
|
|
|
'type' => 'facebook' |
|
998
|
|
|
); |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
return $out; |
|
1002
|
|
|
} |
|
1003
|
|
|
|
|
1004
|
|
|
function person_topics($member) { |
|
1005
|
|
|
$out = array(); |
|
1006
|
|
|
|
|
1007
|
|
|
$extra_info = $member->extra_info(); |
|
1008
|
|
|
|
|
1009
|
|
|
if (isset($extra_info['wrans_departments'])) { |
|
1010
|
|
|
$subjects = explode(',', $extra_info['wrans_departments']); |
|
1011
|
|
|
$out = array_merge($out, $subjects); |
|
1012
|
|
|
} |
|
1013
|
|
|
|
|
1014
|
|
|
if (isset($extra_info['wrans_subjects'])) { |
|
1015
|
|
|
$subjects = explode(',', $extra_info['wrans_subjects']); |
|
1016
|
|
|
$out = array_merge($out, $subjects); |
|
1017
|
|
|
} |
|
1018
|
|
|
|
|
1019
|
|
|
return $out; |
|
1020
|
|
|
} |
|
1021
|
|
|
|
|
1022
|
|
|
function constituency_previous_mps($member) { |
|
1023
|
|
|
if ($member->house(HOUSE_TYPE_COMMONS)) { |
|
1024
|
|
|
return $member->previous_mps(); |
|
1025
|
|
|
} else { |
|
1026
|
|
|
return array(); |
|
1027
|
|
|
} |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
function constituency_future_mps($member) { |
|
1031
|
|
|
if ($member->house(HOUSE_TYPE_COMMONS)) { |
|
1032
|
|
|
return $member->future_mps(); |
|
1033
|
|
|
} else { |
|
1034
|
|
|
return array(); |
|
1035
|
|
|
} |
|
1036
|
|
|
} |
|
1037
|
|
|
|
|
1038
|
|
|
function person_pbc_membership($member) { |
|
1039
|
|
|
|
|
1040
|
|
|
$extra_info = $member->extra_info(); |
|
1041
|
|
|
$out = array('info'=>'', 'data'=>array()); |
|
1042
|
|
|
|
|
1043
|
|
|
# Public Bill Committees |
|
1044
|
|
|
if (count($extra_info['pbc'])) { |
|
1045
|
|
|
if ($member->party() == 'SNP') { |
|
1046
|
|
|
$out['info'] = 'SNP MPs only attend sittings where the legislation pertains to Scotland.'; |
|
1047
|
|
|
} |
|
1048
|
|
|
foreach ($extra_info['pbc'] as $bill_id => $arr) { |
|
1049
|
|
|
$text = ''; |
|
1050
|
|
|
if ($arr['chairman']) { |
|
1051
|
|
|
$text .= 'Chairman, '; |
|
1052
|
|
|
} |
|
1053
|
|
|
$text .= $arr['title'] . ' Committee'; |
|
1054
|
|
|
$out['data'][] = array( |
|
1055
|
|
|
'href' => '/pbc/' . $arr['session'] . '/' . urlencode($arr['title']), |
|
1056
|
|
|
'text' => $text, |
|
1057
|
|
|
'attending' => $arr['attending'] . ' out of ' . $arr['outof'] |
|
1058
|
|
|
); |
|
1059
|
|
|
} |
|
1060
|
|
|
} |
|
1061
|
|
|
|
|
1062
|
|
|
return $out; |
|
1063
|
|
|
} |
|
1064
|
|
|
|
|
1065
|
|
|
function person_numerology($member, $has_email_alerts, $wtt_stats_years) { |
|
1066
|
|
|
|
|
1067
|
|
|
$extra_info = $member->extra_info(); |
|
1068
|
|
|
|
|
1069
|
|
|
$out = array(); |
|
1070
|
|
|
|
|
1071
|
|
|
$since_text = 'in the last year'; |
|
1072
|
|
|
$year_ago = date('Y-m-d', strtotime('now -1 year')); |
|
1073
|
|
|
|
|
1074
|
|
|
# Find latest entered house |
|
1075
|
|
|
$entered_house = null; |
|
1076
|
|
|
foreach ($member->entered_house() as $h => $eh) { |
|
1077
|
|
|
if (!$entered_house || $eh['date'] > $entered_house) $entered_house = $eh['date']; |
|
1078
|
|
|
} |
|
1079
|
|
|
if ($entered_house > $year_ago) |
|
1080
|
|
|
$since_text = 'since joining Parliament'; |
|
1081
|
|
|
|
|
1082
|
|
|
$MOREURL = new \MySociety\TheyWorkForYou\Url('search'); |
|
1083
|
|
|
$section = 'section:debates section:whall section:lords section:ni'; |
|
1084
|
|
|
$MOREURL->insert(array('pid'=>$member->person_id(), 's'=>$section, 'pop'=>1)); |
|
1085
|
|
|
if ($member->party() != 'Sinn Féin') { |
|
1086
|
|
|
if (display_stats_line('debate_sectionsspoken_inlastyear', 'Has spoken in ', 'debate', ' ' . $since_text, ' <a href="' . $MOREURL->generate() . '">See all ' . $member->full_name() . '’s speeches</a>', $extra_info)) { |
|
1087
|
|
|
$out[] = display_stats_line('debate_sectionsspoken_inlastyear', 'Has spoken in ', 'debate', ' ' . $since_text, ' <a href="' . $MOREURL->generate() . '">See all ' . $member->full_name() . '’s speeches</a>', $extra_info); |
|
1088
|
|
|
} |
|
1089
|
|
|
|
|
1090
|
|
|
$MOREURL->insert(array('pid'=>$member->person_id(), 's'=>'section:wrans', 'pop'=>1)); |
|
1091
|
|
|
// We assume that if they've answered a question, they're a minister |
|
1092
|
|
|
$minister = 0; $Lminister = false; |
|
1093
|
|
|
if (isset($extra_info['wrans_answered_inlastyear']) && $extra_info['wrans_answered_inlastyear'] > 0 && $extra_info['wrans_asked_inlastyear'] == 0) |
|
1094
|
|
|
$minister = 1; |
|
1095
|
|
|
if (isset($extra_info['Lwrans_answered_inlastyear']) && $extra_info['Lwrans_answered_inlastyear'] > 0 && $extra_info['Lwrans_asked_inlastyear'] == 0) |
|
1096
|
|
|
$Lminister = true; |
|
1097
|
|
|
if ($member->party() == 'SPK' || $member->party() == 'CWM' || $member->party() == 'DCWM') { |
|
1098
|
|
|
$minister = 2; |
|
1099
|
|
|
} |
|
1100
|
|
|
if (display_stats_line('wrans_asked_inlastyear', 'Has received answers to <a href="' . $MOREURL->generate() . '">', 'written question', '</a> ' . $since_text, '', $extra_info, $minister, $Lminister)) { |
|
1101
|
|
|
$out[] = display_stats_line('wrans_asked_inlastyear', 'Has received answers to <a href="' . $MOREURL->generate() . '">', 'written question', '</a> ' . $since_text, '', $extra_info, $minister, $Lminister); |
|
1102
|
|
|
} |
|
1103
|
|
|
} |
|
1104
|
|
|
|
|
1105
|
|
|
foreach ( $wtt_stats_years as $year ) { |
|
1106
|
|
|
$wtt_displayed = display_writetothem_numbers($year, $extra_info); |
|
1107
|
|
|
if ($wtt_displayed) { |
|
1108
|
|
|
$out[] = $wtt_displayed; |
|
1109
|
|
|
break; |
|
1110
|
|
|
} |
|
1111
|
|
|
} |
|
1112
|
|
|
|
|
1113
|
|
|
$after_stuff = ' <small>(From Public Whip)</small>'; |
|
1114
|
|
|
if ($member->party() == 'SNP') { |
|
1115
|
|
|
$after_stuff .= '<br><em>Note SNP MPs do not vote on legislation not affecting Scotland.</em>'; |
|
1116
|
|
|
} elseif ($member->party() == 'SPK' || $member->party() == 'CWM' || $member->party() == 'DCWM') { |
|
1117
|
|
|
$after_stuff .= '<br><em>Speakers and deputy speakers cannot vote except to break a tie.</em>'; |
|
1118
|
|
|
} |
|
1119
|
|
|
if ($member->party() != 'Sinn Féin') { |
|
1120
|
|
|
$when = 'in this Parliament with this affiliation'; |
|
1121
|
|
|
# Lords have one record per affiliation until they leave (ignoring name changes, sigh) |
|
1122
|
|
|
if ($member->house_disp == HOUSE_TYPE_LORDS) { |
|
1123
|
|
|
$when = 'in this House with this affiliation up to the 2015 general election'; |
|
1124
|
|
|
} |
|
1125
|
|
|
$div_attend = display_stats_line('public_whip_division_attendance', 'Has voted in <a href="http://www.publicwhip.org.uk/mp.php?id=uk.org.publicwhip/member/' . $member->member_id() . '&showall=yes#divisions" title="See more details at Public Whip">', 'of vote', '</a> ' . $when, $after_stuff, $extra_info); |
|
1126
|
|
|
if ($div_attend) { |
|
1127
|
|
|
$out[] = $div_attend; |
|
1128
|
|
|
} |
|
1129
|
|
|
/* |
|
|
|
|
|
|
1130
|
|
|
if ($member->chairmens_panel) { |
|
1131
|
|
|
print '<br><em>Members of the Chairmen’s Panel act for the Speaker when chairing things such as Public Bill Committees, and as such do not vote on Bills they are involved in chairing.</em>'; |
|
1132
|
|
|
} |
|
1133
|
|
|
*/ |
|
1134
|
|
|
|
|
1135
|
|
|
if (display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid='.$member->person_id().'">', 'annotation', "</a> on this MP’s speeches", '', $extra_info)) { |
|
|
|
|
|
|
1136
|
|
|
$out[] = display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid='.$member->person_id().'">', 'annotation', "</a> on this MP’s speeches", '', $extra_info); |
|
1137
|
|
|
} |
|
1138
|
|
|
if (display_stats_line('reading_age', 'This MP’s speeches, in Hansard, are readable by an average ', '', ' year old, going by the <a href="https://en.wikipedia.org/wiki/Flesch-Kincaid_Readability_Test">Flesch-Kincaid Grade Level</a> score', '', $extra_info)) { |
|
1139
|
|
|
$out[] = display_stats_line('reading_age', 'This MP’s speeches, in Hansard, are readable by an average ', '', ' year old, going by the <a href="https://en.wikipedia.org/wiki/Flesch-Kincaid_Readability_Test">Flesch-Kincaid Grade Level</a> score', '', $extra_info); |
|
1140
|
|
|
} |
|
1141
|
|
|
} |
|
1142
|
|
|
|
|
1143
|
|
|
if (isset($extra_info['number_of_alerts']) && ($extra_info['number_of_alerts']>0 || $has_email_alerts)) { |
|
1144
|
|
|
$line = '<strong>' . _htmlentities($extra_info['number_of_alerts']) . '</strong> ' . ($extra_info['number_of_alerts']==1?'person is':'people are') . ' tracking '; |
|
1145
|
|
|
if ($member->house_disp == HOUSE_TYPE_COMMONS) $line .= 'this MP'; |
|
1146
|
|
|
elseif ($member->house_disp == HOUSE_TYPE_LORDS) $line .= 'this peer'; |
|
1147
|
|
|
elseif ($member->house_disp == HOUSE_TYPE_NI) $line .= 'this MLA'; |
|
1148
|
|
|
elseif ($member->house_disp == HOUSE_TYPE_SCOTLAND) $line .= 'this MSP'; |
|
1149
|
|
|
elseif ($member->house_disp == HOUSE_TYPE_ROYAL) $line .= $member->full_name(); |
|
1150
|
|
|
if ($has_email_alerts) { |
|
1151
|
|
|
$line .= ' — <a href="' . WEBPATH . 'alert/?pid='.$member->person_id().'">email me updates on '. $member->full_name(). '’s activity</a>'; |
|
1152
|
|
|
} |
|
1153
|
|
|
|
|
1154
|
|
|
$out[] = $line; |
|
1155
|
|
|
} |
|
1156
|
|
|
|
|
1157
|
|
|
if ($member->party() != 'Sinn Féin') { |
|
1158
|
|
|
if (display_stats_line('three_word_alliterations', 'Has used three-word alliterative phrases (e.g. "she sells seashells") ', 'time', ' in debates', ' <small>(<a href="' . WEBPATH . 'help/#numbers">Why is this here?</a>)</small>', $extra_info)) { |
|
1159
|
|
|
$line = display_stats_line('three_word_alliterations', 'Has used three-word alliterative phrases (e.g. "she sells seashells") ', 'time', ' in debates', ' <small>(<a href="' . WEBPATH . 'help/#numbers">Why is this here?</a>)</small>', $extra_info); |
|
1160
|
|
|
if (isset($extra_info['three_word_alliteration_content'])) { |
|
1161
|
|
|
$line .= "\n<!-- " . $extra_info['three_word_alliteration_content'] . " -->\n"; |
|
1162
|
|
|
} |
|
1163
|
|
|
$out[] = $line; |
|
1164
|
|
|
} |
|
1165
|
|
|
} |
|
1166
|
|
|
|
|
1167
|
|
|
return $out; |
|
1168
|
|
|
|
|
1169
|
|
|
} |
|
1170
|
|
|
|
|
1171
|
|
|
function display_stats_line($category, $blurb, $type, $inwhat, $afterstuff, $extra_info, $minister = false, $Lminister = false) { |
|
1172
|
|
|
$return = false; |
|
1173
|
|
|
if (isset($extra_info[$category])) |
|
1174
|
|
|
$return = display_stats_line_house(HOUSE_TYPE_COMMONS, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff); |
|
1175
|
|
|
if (isset($extra_info["L$category"])) |
|
1176
|
|
|
$return = display_stats_line_house(HOUSE_TYPE_LORDS, "L$category", $blurb, $type, $inwhat, $extra_info, $Lminister, $afterstuff); |
|
1177
|
|
|
return $return; |
|
1178
|
|
|
} |
|
1179
|
|
|
|
|
1180
|
|
|
function display_stats_line_house($house, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff) { |
|
1181
|
|
|
if ($category == 'wrans_asked_inlastyear' || $category == 'debate_sectionsspoken_inlastyear' || $category =='comments_on_speeches' || |
|
1182
|
|
|
$category == 'Lwrans_asked_inlastyear' || $category == 'Ldebate_sectionsspoken_inlastyear' || $category =='Lcomments_on_speeches') { |
|
1183
|
|
|
if ($extra_info[$category]==0) { |
|
1184
|
|
|
$blurb = preg_replace('#<a.*?>#', '', $blurb); |
|
1185
|
|
|
$inwhat = preg_replace('#<\/a>#', '', $inwhat); |
|
1186
|
|
|
} |
|
1187
|
|
|
} |
|
1188
|
|
|
if ($house==HOUSE_TYPE_LORDS) $inwhat = str_replace('MP', 'Lord', $inwhat); |
|
1189
|
|
|
$line = $blurb; |
|
1190
|
|
|
$line .= '<strong>' . $extra_info[$category]; |
|
1191
|
|
|
if ($type) $line .= ' ' . make_plural($type, $extra_info[$category]); |
|
1192
|
|
|
$line .= '</strong>'; |
|
1193
|
|
|
$line .= $inwhat; |
|
1194
|
|
|
if ($minister===2) { |
|
1195
|
|
|
$line .= ' — Speakers/ deputy speakers do not ask written questions'; |
|
1196
|
|
|
} elseif ($minister) |
|
1197
|
|
|
$line .= ' — Ministers do not ask written questions'; |
|
1198
|
|
|
else { |
|
1199
|
|
|
$type = ($house==HOUSE_TYPE_COMMONS?'MP':($house==HOUSE_TYPE_LORDS?'Lord':'MLA')); |
|
1200
|
|
|
if (!get_http_var('rem') && isset($extra_info[$category . '_quintile'])) { |
|
1201
|
|
|
$line .= ' — '; |
|
1202
|
|
|
$q = $extra_info[$category . '_quintile']; |
|
1203
|
|
|
if ($q == 0) { |
|
1204
|
|
|
$line .= 'well above average'; |
|
1205
|
|
|
} elseif ($q == 1) { |
|
1206
|
|
|
$line .= 'above average'; |
|
1207
|
|
|
} elseif ($q == 2) { |
|
1208
|
|
|
$line .= 'average'; |
|
1209
|
|
|
} elseif ($q == 3) { |
|
1210
|
|
|
$line .= 'below average'; |
|
1211
|
|
|
} elseif ($q == 4) { |
|
1212
|
|
|
$line .= 'well below average'; |
|
1213
|
|
|
} else { |
|
1214
|
|
|
$line .= '[Impossible quintile!]'; |
|
1215
|
|
|
} |
|
1216
|
|
|
$line .= ' amongst '; |
|
1217
|
|
|
$line .= $type . 's'; |
|
1218
|
|
|
} elseif (!get_http_var('rem') && isset($extra_info[$category . '_rank'])) { |
|
1219
|
|
|
$line .= ' — '; |
|
1220
|
|
|
#if (isset($extra_info[$category . '_rank_joint'])) |
|
|
|
|
|
|
1221
|
|
|
# print 'joint '; |
|
1222
|
|
|
$line .= make_ranking($extra_info[$category . '_rank']) . ' out of ' . $extra_info[$category . '_rank_outof']; |
|
1223
|
|
|
$line .= ' ' . $type . 's'; |
|
1224
|
|
|
} |
|
1225
|
|
|
} |
|
1226
|
|
|
$line .= ".$afterstuff"; |
|
1227
|
|
|
return $line; |
|
1228
|
|
|
} |
|
1229
|
|
|
|
|
1230
|
|
|
function display_writetothem_numbers($year, $extra_info) { |
|
1231
|
|
|
if (isset($extra_info["writetothem_responsiveness_notes_$year"])) { |
|
1232
|
|
|
return '<li>Responsiveness to messages sent via <a href="https://www.writetothem.com/stats/' . $year . '/mps">WriteToThem.com</a> in ' . $year . ': ' . $extra_info["writetothem_responsiveness_notes_$year"] . '.</li>'; |
|
1233
|
|
|
} elseif (isset($extra_info["writetothem_responsiveness_mean_$year"])) { |
|
1234
|
|
|
$mean = $extra_info["writetothem_responsiveness_mean_$year"]; |
|
1235
|
|
|
|
|
1236
|
|
|
$a = $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"]; |
|
1237
|
|
|
if ($a == 'very low') $a = 'a very low'; |
|
1238
|
|
|
if ($a == 'low') $a = 'a low'; |
|
1239
|
|
|
if ($a == 'medium') $a = 'a medium'; |
|
1240
|
|
|
if ($a == 'high') $a = 'a high'; |
|
1241
|
|
|
if ($a == 'very high') $a = 'a very high'; |
|
1242
|
|
|
$extra_info["writetothem_responsiveness_fuzzy_response_description_$year"] = $a; |
|
1243
|
|
|
|
|
1244
|
|
|
return display_stats_line("writetothem_responsiveness_fuzzy_response_description_$year", 'Replied within 2 or 3 weeks to <a href="https://www.writetothem.com/stats/'.$year.'/mps" title="From WriteToThem.com">', "", "</a> <!-- Mean: " . $mean . " --> number of messages sent via WriteToThem.com during ".$year.", according to constituents", "", $extra_info); |
|
1245
|
|
|
} |
|
1246
|
|
|
|
|
1247
|
|
|
} |
|
1248
|
|
|
|
|
1249
|
|
|
function get_all_writetothem_strings($member, $wtt_stats_years) { |
|
1250
|
|
|
$extra_info = $member->extra_info(); |
|
1251
|
|
|
$strings = array(); |
|
1252
|
|
|
foreach ( $wtt_stats_years as $year ) { |
|
1253
|
|
|
|
|
1254
|
|
|
if (isset($extra_info["writetothem_responsiveness_mean_$year"])) { |
|
1255
|
|
|
$a = $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"]; |
|
1256
|
|
|
$strings[$year] = $a; |
|
1257
|
|
|
} |
|
1258
|
|
|
} |
|
1259
|
|
|
|
|
1260
|
|
|
return $strings; |
|
1261
|
|
|
} |
|
1262
|
|
|
|
|
1263
|
|
|
function person_register_interests($member, $extra_info) { |
|
|
|
|
|
|
1264
|
|
|
if (!isset($extra_info['register_member_interests_html'])) { |
|
1265
|
|
|
return; |
|
1266
|
|
|
} |
|
1267
|
|
|
|
|
1268
|
|
|
$reg = array( 'date' => '', 'data' => '<p>Nil</p>' ); |
|
1269
|
|
|
if (isset($extra_info['register_member_interests_date'])) { |
|
1270
|
|
|
$reg['date'] = format_date($extra_info['register_member_interests_date'], SHORTDATEFORMAT); |
|
1271
|
|
|
} |
|
1272
|
|
|
if ($extra_info['register_member_interests_html'] != '') { |
|
1273
|
|
|
$reg['data'] = $extra_info['register_member_interests_html']; |
|
1274
|
|
|
} |
|
1275
|
|
|
return $reg; |
|
1276
|
|
|
} |
|
1277
|
|
|
|
|
1278
|
|
|
function regional_list($pc, $area_type, $rep_type) { |
|
1279
|
|
|
$constituencies = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($pc); |
|
1280
|
|
|
if ($constituencies == 'CONNECTION_TIMED_OUT') { |
|
1281
|
|
|
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.'); |
|
1282
|
|
|
} elseif (!$constituencies) { |
|
1283
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . htmlentities($pc) . ' isn’t a known postcode'); |
|
1284
|
|
|
} elseif (!isset($constituencies[$area_type])) { |
|
1285
|
|
|
throw new MySociety\TheyWorkForYou\MemberException(htmlentities($pc) . ' does not appear to be a valid postcode'); |
|
1286
|
|
|
} |
|
1287
|
|
|
global $PAGE; |
|
|
|
|
|
|
1288
|
|
|
$a = array_values($constituencies); |
|
|
|
|
|
|
1289
|
|
|
$db = new ParlDB; |
|
1290
|
|
|
$query_base = "SELECT member.person_id, given_name, family_name, constituency, house |
|
1291
|
|
|
FROM member, person_names pn |
|
1292
|
|
|
WHERE constituency IN ('" . join("','", $a) . "') |
|
1293
|
|
|
AND member.person_id = pn.person_id AND pn.type = 'name' |
|
1294
|
|
|
AND pn.end_date = (SELECT MAX(end_date) FROM person_names WHERE person_names.person_id = member.person_id)"; |
|
1295
|
|
|
$q = $db->query($query_base . " AND left_reason = 'still_in_office' AND house in (" . HOUSE_TYPE_NI . "," . HOUSE_TYPE_SCOTLAND . ")"); |
|
1296
|
|
|
$current = true; |
|
1297
|
|
|
if (!$q->rows() && ($dissolution = MySociety\TheyWorkForYou\Dissolution::db())) { |
|
1298
|
|
|
$current = false; |
|
1299
|
|
|
$q = $db->query($query_base . " AND $dissolution[query]", |
|
1300
|
|
|
$dissolution['params']); |
|
1301
|
|
|
} |
|
1302
|
|
|
$mcon = array(); $mreg = array(); |
|
1303
|
|
|
for ($i=0; $i<$q->rows(); $i++) { |
|
1304
|
|
|
$house = $q->field($i, 'house'); |
|
1305
|
|
|
$pid = $q->field($i, 'person_id'); |
|
|
|
|
|
|
1306
|
|
|
$cons = $q->field($i, 'constituency'); |
|
1307
|
|
|
if ($house == HOUSE_TYPE_COMMONS) { |
|
1308
|
|
|
continue; |
|
1309
|
|
|
} elseif ($house == HOUSE_TYPE_NI) { |
|
1310
|
|
|
$mreg[] = $q->row($i); |
|
1311
|
|
|
} elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
1312
|
|
|
if ($cons == $constituencies['SPC']) { |
|
1313
|
|
|
$mcon = $q->row($i); |
|
1314
|
|
|
} elseif ($cons == $constituencies['SPE']) { |
|
1315
|
|
|
$mreg[] = $q->row($i); |
|
1316
|
|
|
} |
|
1317
|
|
|
} else { |
|
1318
|
|
|
throw new MySociety\TheyWorkForYou\MemberException('Odd result returned!' . $house); |
|
1319
|
|
|
} |
|
1320
|
|
|
} |
|
1321
|
|
|
if ($rep_type == 'msp') { |
|
1322
|
|
|
if ($current) { |
|
1323
|
|
|
$data['members_statement'] = '<p>You have one constituency MSP (Member of the Scottish Parliament) and multiple region MSPs.</p>'; |
|
|
|
|
|
|
1324
|
|
|
$data['members_statement'] .= '<p>Your <strong>constituency MSP</strong> is <a href="/msp/?p=' . $mcon['person_id'] . '">'; |
|
1325
|
|
|
$data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MSP for ' . $mcon['constituency']; |
|
1326
|
|
|
$data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['SPE'] . ' region MSPs</strong> are:</p>'; |
|
1327
|
|
|
} else { |
|
1328
|
|
|
$data['members_statement'] = '<p>You had one constituency MSP (Member of the Scottish Parliament) and multiple region MSPs.</p>'; |
|
1329
|
|
|
$data['members_statement'] .= '<p>Your <strong>constituency MSP</strong> was <a href="/msp/?p=' . $mcon['person_id'] . '">'; |
|
1330
|
|
|
$data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MSP for ' . $mcon['constituency']; |
|
1331
|
|
|
$data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['SPE'] . ' region MSPs</strong> were:</p>'; |
|
1332
|
|
|
} |
|
1333
|
|
|
} else { |
|
1334
|
|
|
if ($current) { |
|
1335
|
|
|
$data['members_statement'] = '<p>You have multiple MLAs (Members of the Legislative Assembly) who represent you in ' . $constituencies['NIE'] . '. They are:</p>'; |
|
1336
|
|
|
} else { |
|
1337
|
|
|
$data['members_statement'] = '<p>You had multiple MLAs (Members of the Legislative Assembly) who represented you in ' . $constituencies['NIE'] . '. They were:</p>'; |
|
1338
|
|
|
} |
|
1339
|
|
|
} |
|
1340
|
|
|
|
|
1341
|
|
|
foreach($mreg as $reg) { |
|
1342
|
|
|
$data['members'][] = array ( |
|
1343
|
|
|
'url' => '/' . $rep_type . '/?p=' . $reg['person_id'], |
|
1344
|
|
|
'name' => $reg['given_name'] . ' ' . $reg['family_name'] |
|
1345
|
|
|
); |
|
1346
|
|
|
|
|
1347
|
|
|
} |
|
1348
|
|
|
|
|
1349
|
|
|
// Send the output for rendering |
|
1350
|
|
|
MySociety\TheyWorkForYou\Renderer::output('mp/regional_list', $data); |
|
1351
|
|
|
|
|
1352
|
|
|
} |
|
1353
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.