|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Member Class |
|
4
|
|
|
* |
|
5
|
|
|
* @package TheyWorkForYou |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace MySociety\TheyWorkForYou; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Member |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
class Member extends \MEMBER { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Is Dead |
|
18
|
|
|
* |
|
19
|
|
|
* Determine if the member has died or not. |
|
20
|
|
|
* |
|
21
|
|
|
* @return boolean If the member is dead or not. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
public function isDead() { |
|
25
|
|
|
|
|
26
|
|
|
$left_house = $this->left_house(); |
|
27
|
|
|
|
|
28
|
|
|
if ($left_house) { |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
// This member has left a house, and might be dead. See if they are. |
|
31
|
|
|
|
|
32
|
|
|
// Types of house to test for death. |
|
33
|
|
|
$house_types = array( |
|
34
|
|
|
HOUSE_TYPE_COMMONS, |
|
35
|
|
|
HOUSE_TYPE_LORDS, |
|
36
|
|
|
HOUSE_TYPE_SCOTLAND, |
|
37
|
|
|
HOUSE_TYPE_NI, |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
foreach ($house_types as $house_type) { |
|
41
|
|
|
|
|
42
|
|
|
if (in_array($house_type, $left_house) AND |
|
|
|
|
|
|
43
|
|
|
$left_house[$house_type]['reason'] AND |
|
|
|
|
|
|
44
|
|
|
$left_house[$house_type]['reason'] == 'Died' |
|
45
|
|
|
) { |
|
46
|
|
|
|
|
47
|
|
|
// This member has left a house because of death. |
|
48
|
|
|
return TRUE; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// If we get this far the member hasn't left a house due to death, and |
|
56
|
|
|
// is presumably alive. |
|
57
|
|
|
return FALSE; |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/* |
|
62
|
|
|
* Determine if the member is a new member of a house where new is |
|
63
|
|
|
* within the last 6 months. |
|
64
|
|
|
* |
|
65
|
|
|
* @param int house - identifier for the house, defaults to 1 for westminster |
|
|
|
|
|
|
66
|
|
|
* |
|
67
|
|
|
* @return boolean |
|
68
|
|
|
*/ |
|
69
|
|
|
|
|
70
|
1 |
|
public function isNew($house = HOUSE_TYPE_COMMONS) { |
|
71
|
1 |
|
$date_entered = $this->getEntryDate($house); |
|
72
|
|
|
|
|
73
|
1 |
|
if ($date_entered) { |
|
74
|
1 |
|
$date_entered = new \DateTime($date_entered); |
|
75
|
1 |
|
$now = new \DateTime(); |
|
76
|
|
|
|
|
77
|
1 |
|
$diff = $date_entered->diff($now); |
|
78
|
1 |
|
if ( $diff->y == 0 && $diff->m <= 6 ) { |
|
79
|
1 |
|
return TRUE; |
|
80
|
|
|
} |
|
81
|
1 |
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
return FALSE; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/* |
|
87
|
|
|
* Get the date the person first entered a house. May not be for their current seat. |
|
88
|
|
|
* |
|
89
|
|
|
* @param int house - identifier for the house, defaults to 1 for westminster |
|
90
|
|
|
* |
|
91
|
|
|
* @return string - blank if no entry date for that house otherwise in YYYY-MM-DD format |
|
92
|
|
|
*/ |
|
93
|
|
|
|
|
94
|
2 |
|
public function getEntryDate($house = HOUSE_TYPE_COMMONS) { |
|
95
|
2 |
|
$date_entered = ''; |
|
96
|
|
|
|
|
97
|
2 |
|
$entered_house = $this->entered_house($house); |
|
98
|
|
|
|
|
99
|
2 |
|
if ( $entered_house ) { |
|
100
|
2 |
|
$date_entered = $entered_house['date']; |
|
101
|
2 |
|
} |
|
102
|
|
|
|
|
103
|
2 |
|
return $date_entered; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/* |
|
107
|
|
|
* Get the date the person last left the house. |
|
108
|
|
|
* |
|
109
|
|
|
* @param int house - identifier for the house, defaults to 1 for westminster |
|
110
|
|
|
* |
|
111
|
|
|
* @return string - 9999-12-31 if they are still in that house otherwise in YYYY-MM-DD format |
|
112
|
|
|
*/ |
|
113
|
|
|
|
|
114
|
|
|
public function getLeftDate($house = HOUSE_TYPE_COMMONS) { |
|
115
|
|
|
$date_left = ''; |
|
116
|
|
|
|
|
117
|
|
|
$left_house = $this->left_house($house); |
|
118
|
|
|
|
|
119
|
|
|
if ( $left_house ) { |
|
120
|
|
|
$date_left = $left_house['date']; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $date_left; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function getEUStance() { |
|
128
|
|
|
if (array_key_exists('eu_ref_stance', $this->extra_info())) { |
|
129
|
|
|
return $this->extra_info()['eu_ref_stance']; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return FALSE; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Image |
|
137
|
|
|
* |
|
138
|
|
|
* Return a URL for the member's image. |
|
139
|
|
|
* |
|
140
|
|
|
* @return string The URL of the member's image. |
|
141
|
|
|
*/ |
|
142
|
|
|
|
|
143
|
|
|
public function image() { |
|
144
|
|
|
|
|
145
|
|
|
$is_lord = $this->house(HOUSE_TYPE_LORDS); |
|
146
|
|
|
if ($is_lord) { |
|
147
|
|
|
list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
|
148
|
|
|
} else { |
|
149
|
|
|
list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
// We can determine if the image exists or not by testing if size is set |
|
153
|
|
|
if ($size !== NULL) { |
|
154
|
|
|
$exists = TRUE; |
|
155
|
|
|
} else { |
|
156
|
|
|
$exists = FALSE; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return array( |
|
|
|
|
|
|
160
|
|
|
'url' => $image, |
|
161
|
|
|
'size' => $size, |
|
162
|
|
|
'exists' => $exists |
|
163
|
|
|
); |
|
164
|
|
|
|
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
// TODO: some of this probably wants to go elsewhere |
|
168
|
|
|
public function getMostRecentMembership() { |
|
169
|
|
|
$last_cons = ''; |
|
170
|
|
|
$last_house = null; |
|
171
|
|
|
$last_party = null; |
|
172
|
|
|
if ( $this->current_member_anywhere() ) { |
|
173
|
|
|
$houses = array_keys(array_filter($this->current_member(), 'strlen')); |
|
|
|
|
|
|
174
|
|
|
$last_cons = $this->constituency; |
|
175
|
|
|
$last_party = $this->party; |
|
176
|
|
|
$last_house = $this->house_disp; |
|
177
|
|
|
} else { |
|
178
|
|
|
$max_date = null; |
|
179
|
|
|
foreach ( array_keys($this->left_house) as $house ) { |
|
180
|
|
|
if ($this->left_house[$house]['date'] > $max_date ) { |
|
181
|
|
|
$max_date = $this->left_house[$house]['date']; |
|
182
|
|
|
$last_cons = $this->left_house[$house]['constituency']; |
|
183
|
|
|
$last_party = $this->left_house[$house]['party']; |
|
184
|
|
|
$last_house = $house; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
$details = array( |
|
189
|
|
|
'entered_house' => '', |
|
190
|
|
|
'left_house' => '', |
|
191
|
|
|
'cons' => $last_cons, |
|
192
|
|
|
'party' => $last_party, |
|
193
|
|
|
'house' => $last_house, |
|
194
|
|
|
'rep_name' => $this->getRepNameForHouse($last_house) |
|
195
|
|
|
); |
|
196
|
|
|
|
|
197
|
|
|
$entered_house = $this->entered_house($last_house); |
|
198
|
|
|
$left_house = $this->left_house($last_house); |
|
199
|
|
|
if ( isset($entered_house['date']) ) { |
|
200
|
|
|
$details['entered_house'] = $entered_house['date']; |
|
201
|
|
|
} |
|
202
|
|
|
if ( isset($left_house['date']) ) { |
|
203
|
|
|
$details['left_house'] = $left_house['date']; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return $details; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Offices |
|
211
|
|
|
* |
|
212
|
|
|
* Return an array of Office objects held (or previously held) by the member. |
|
213
|
|
|
* |
|
214
|
|
|
* @param string $include_only Restrict the list to include only "previous" or "current" offices. |
|
215
|
|
|
* @param bool $ignore_committees Ignore offices that appear to be committee memberships. |
|
216
|
|
|
* |
|
217
|
|
|
* @return array An array of Office objects. |
|
218
|
|
|
*/ |
|
219
|
|
|
|
|
220
|
|
|
public function offices($include_only = NULL, $ignore_committees = FALSE) { |
|
221
|
|
|
|
|
222
|
|
|
$out = array(); |
|
223
|
|
|
|
|
224
|
|
|
if (array_key_exists('office', $this->extra_info())) { |
|
225
|
|
|
$office = $this->extra_info(); |
|
226
|
|
|
$office = $office['office']; |
|
227
|
|
|
|
|
228
|
|
|
foreach ($office as $row) { |
|
229
|
|
|
if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) { |
|
230
|
|
|
$out[] = $officeObject; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
return $out; |
|
236
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
private function getOfficeObject($include_only, $ignore_committees, $row) { |
|
240
|
|
|
if (!$this->includeOffice($include_only, $row['to_date'])) { |
|
241
|
|
|
return null; |
|
242
|
|
|
} |
|
243
|
|
|
if ($ignore_committees && strpos($row['moffice_id'], 'Committee')) { |
|
244
|
|
|
return null; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
$officeObject = new Office; |
|
248
|
|
|
$officeObject->title = prettify_office($row['position'], $row['dept']); |
|
249
|
|
|
$officeObject->from_date = $row['from_date']; |
|
250
|
|
|
$officeObject->to_date = $row['to_date']; |
|
251
|
|
|
$officeObject->source = $row['source']; |
|
252
|
|
|
return $officeObject; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
private function includeOffice($include_only, $to_date) { |
|
256
|
|
|
$include_office = TRUE; |
|
257
|
|
|
|
|
258
|
|
|
// If we should only include previous offices, and the to date is in the future, suppress this office. |
|
259
|
|
|
if ($include_only == 'previous' AND $to_date == '9999-12-31') { |
|
|
|
|
|
|
260
|
|
|
$include_office = FALSE; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
// If we should only include previous offices, and the to date is in the past, suppress this office. |
|
264
|
|
|
if ($include_only == 'current' AND $to_date != '9999-12-31') { |
|
|
|
|
|
|
265
|
|
|
$include_office = FALSE; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
return $include_office; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Get Other Parties String |
|
273
|
|
|
* |
|
274
|
|
|
* Return a readable list of party changes for this member. |
|
275
|
|
|
* |
|
276
|
|
|
* @return string|null A readable list of the party changes for this member. |
|
277
|
|
|
*/ |
|
278
|
|
|
|
|
279
|
|
|
public function getOtherPartiesString() { |
|
280
|
|
|
|
|
281
|
|
|
if (!empty($this->other_parties) && $this->party != 'Speaker' && $this->party != 'Deputy Speaker') { |
|
282
|
|
|
$output = 'Party was '; |
|
283
|
|
|
$other_parties = array(); |
|
284
|
|
|
foreach ($this->other_parties as $r) { |
|
285
|
|
|
$other_parties[] = $r['from'] . ' until ' . format_date($r['date'], SHORTDATEFORMAT); |
|
286
|
|
|
} |
|
287
|
|
|
$output .= join('; ', $other_parties); |
|
288
|
|
|
return $output; |
|
289
|
|
|
} else { |
|
290
|
|
|
return NULL; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
public function getShortParty() { |
|
296
|
|
|
$party = $this->party(); |
|
297
|
|
|
if ($party == 'Labour/Co-operative') { |
|
298
|
|
|
$party = 'Labour'; |
|
299
|
|
|
} |
|
300
|
|
|
$party = str_replace(' ', '', $party); |
|
301
|
|
|
return $party; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Get Other Constituencies String |
|
306
|
|
|
* |
|
307
|
|
|
* Return a readable list of other constituencies for this member. |
|
308
|
|
|
* |
|
309
|
|
|
* @return string|null A readable list of the other constituencies for this member. |
|
310
|
|
|
*/ |
|
311
|
|
|
|
|
312
|
|
|
public function getOtherConstituenciesString() { |
|
313
|
|
|
|
|
314
|
|
|
if ($this->other_constituencies) { |
|
315
|
|
|
return 'Also represented ' . join('; ', array_keys($this->other_constituencies)); |
|
316
|
|
|
} else { |
|
317
|
|
|
return NULL; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Get Entered/Left Strings |
|
324
|
|
|
* |
|
325
|
|
|
* Return an array of readable strings covering when people entered or left |
|
326
|
|
|
* various houses. Returns an array since it's possible for a member to have |
|
327
|
|
|
* done several of these things. |
|
328
|
|
|
* |
|
329
|
|
|
* @return array An array of strings of when this member entered or left houses. |
|
330
|
|
|
*/ |
|
331
|
1 |
|
public function getEnterLeaveStrings() { |
|
332
|
1 |
|
$output = array(); |
|
333
|
|
|
|
|
334
|
1 |
|
$output[] = $this->entered_house_line(HOUSE_TYPE_LORDS, 'House of Lords'); |
|
335
|
|
|
|
|
336
|
1 |
|
if (isset($this->left_house[HOUSE_TYPE_COMMONS]) && isset($this->entered_house[HOUSE_TYPE_LORDS])) { |
|
337
|
|
|
$string = '<strong>Previously MP for '; |
|
338
|
|
|
$string .= $this->left_house[HOUSE_TYPE_COMMONS]['constituency'] . ' until '; |
|
339
|
|
|
$string .= $this->left_house[HOUSE_TYPE_COMMONS]['date_pretty'] . '</strong>'; |
|
340
|
|
|
if ($this->left_house[HOUSE_TYPE_COMMONS]['reason']) { |
|
341
|
|
|
$string .= ' — ' . $this->left_house[HOUSE_TYPE_COMMONS]['reason']; |
|
342
|
|
|
} |
|
343
|
|
|
$output[] = $string; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
1 |
|
$output[] = $this->left_house_line(HOUSE_TYPE_LORDS, 'House of Lords'); |
|
347
|
|
|
|
|
348
|
1 |
|
if (isset($this->extra_info['lordbio'])) { |
|
349
|
|
|
$output[] = '<strong>Positions held at time of appointment:</strong> ' . $this->extra_info['lordbio'] . |
|
350
|
|
|
' <small>(from <a href="' . |
|
351
|
|
|
$this->extra_info['lordbio_from'] . '">Number 10 press release</a>)</small>'; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
1 |
|
$output[] = $this->entered_house_line(HOUSE_TYPE_COMMONS, 'House of Commons'); |
|
355
|
|
|
|
|
356
|
|
|
# If they became a Lord, we handled this above. |
|
357
|
1 |
|
if ($this->house(HOUSE_TYPE_COMMONS) && !$this->current_member(HOUSE_TYPE_COMMONS) && !$this->house(HOUSE_TYPE_LORDS)) { |
|
358
|
|
|
$output[] = $this->left_house_line(HOUSE_TYPE_COMMONS, 'House of Commons'); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
1 |
|
$output[] = $this->entered_house_line(HOUSE_TYPE_NI, 'Assembly'); |
|
362
|
1 |
|
$output[] = $this->left_house_line(HOUSE_TYPE_NI, 'Assembly'); |
|
363
|
1 |
|
$output[] = $this->entered_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament'); |
|
364
|
1 |
|
$output[] = $this->left_house_line(HOUSE_TYPE_SCOTLAND, 'Scottish Parliament'); |
|
365
|
|
|
|
|
366
|
1 |
|
$output = array_values(array_filter($output)); |
|
367
|
1 |
|
return $output; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
1 |
|
private function entered_house_line($house, $house_name) { |
|
371
|
1 |
|
if (isset($this->entered_house[$house]['date'])) { |
|
372
|
1 |
|
$string = "<strong>Entered the $house_name "; |
|
373
|
1 |
|
$string .= strlen($this->entered_house[$house]['date_pretty'])==HOUSE_TYPE_SCOTLAND ? 'in ' : 'on '; |
|
374
|
1 |
|
$string .= $this->entered_house[$house]['date_pretty'] . '</strong>'; |
|
375
|
1 |
|
if ($this->entered_house[$house]['reason']) { |
|
376
|
1 |
|
$string .= ' — ' . $this->entered_house[$house]['reason']; |
|
377
|
1 |
|
} |
|
378
|
1 |
|
return $string; |
|
379
|
|
|
} |
|
380
|
1 |
|
} |
|
381
|
|
|
|
|
382
|
1 |
|
private function left_house_line($house, $house_name) { |
|
383
|
1 |
|
if ($this->house($house) && !$this->current_member($house)) { |
|
384
|
1 |
|
$string = "<strong>Left the $house_name "; |
|
385
|
1 |
|
$string .= strlen($this->left_house[$house]['date_pretty'])==4 ? 'in ' : 'on '; |
|
386
|
1 |
|
$string .= $this->left_house[$house]['date_pretty'] . '</strong>'; |
|
387
|
1 |
|
if ($this->left_house[$house]['reason']) { |
|
388
|
1 |
|
$string .= ' — ' . $this->left_house[$house]['reason']; |
|
389
|
1 |
|
} |
|
390
|
1 |
|
return $string; |
|
391
|
|
|
} |
|
392
|
1 |
|
} |
|
393
|
|
|
|
|
394
|
|
|
public function getPartyPolicyDiffs($party, $policiesList, $positions, $only_diffs = false) { |
|
395
|
|
|
$policy_diffs = array(); |
|
396
|
|
|
$party_positions = $party->getAllPolicyPositions($policiesList); |
|
397
|
|
|
|
|
398
|
|
|
if ( !$party_positions ) { |
|
399
|
|
|
return $policy_diffs; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
foreach ( $positions->positionsById as $policy_id => $details ) { |
|
403
|
|
|
if ( $details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
|
404
|
|
|
$mp_score = $details['score']; |
|
405
|
|
|
$party_score = $party_positions[$policy_id]['score']; |
|
406
|
|
|
|
|
407
|
|
|
$score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score); |
|
408
|
|
|
|
|
409
|
|
|
// skip anything that isn't a yes vs no diff |
|
410
|
|
|
if ( $only_diffs && $score_diff < 2 ) { |
|
411
|
|
|
continue; |
|
412
|
|
|
} |
|
413
|
|
|
$policy_diffs[$policy_id] = $score_diff; |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
arsort($policy_diffs); |
|
418
|
|
|
|
|
419
|
|
|
return $policy_diffs; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
private function calculatePolicyDiffScore( $mp_score, $party_score ) { |
|
423
|
|
|
$score_diff = abs($mp_score - $party_score); |
|
424
|
|
|
// if they are on opposite sides of mixture of for and against |
|
425
|
|
|
if ( |
|
426
|
|
|
( $mp_score < 0.4 && $party_score > 0.6 ) || |
|
427
|
|
|
( $mp_score > 0.6 && $party_score < 0.4 ) |
|
428
|
|
|
) { |
|
429
|
|
|
$score_diff += 2; |
|
430
|
|
|
// if on is mixture of for and against and one is for/against |
|
431
|
|
|
} else if ( |
|
432
|
|
|
( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) || |
|
|
|
|
|
|
433
|
|
|
( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) ) |
|
434
|
|
|
) { |
|
435
|
|
|
$score_diff += 1; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
return $score_diff; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
1 |
|
public static function getRegionalList($postcode, $house, $type) { |
|
442
|
1 |
|
$db = new \ParlDB; |
|
443
|
|
|
|
|
444
|
1 |
|
$mreg = array(); |
|
445
|
1 |
|
$constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); |
|
446
|
1 |
|
if ( isset($constituencies[$type]) ) { |
|
447
|
1 |
|
$cons_name = $constituencies[$type]; |
|
448
|
|
|
$query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house |
|
449
|
|
|
FROM member, person_names |
|
450
|
|
|
WHERE |
|
451
|
|
|
member.person_id = person_names.person_id |
|
452
|
|
|
AND person_names.type = 'name' |
|
453
|
|
|
AND constituency = :cons_name |
|
454
|
|
|
AND house = :house |
|
455
|
|
|
AND left_house >= start_date |
|
456
|
1 |
|
AND left_house <= end_date"; |
|
457
|
1 |
|
$q = $db->query("$query_base AND left_reason = 'still_in_office'", |
|
458
|
|
|
array( |
|
459
|
1 |
|
':house' => $house, |
|
460
|
|
|
':cons_name' => $cons_name |
|
461
|
1 |
|
) |
|
462
|
1 |
|
); |
|
463
|
1 |
|
if ( !$q->rows() && ($dissolution = Dissolution::db()) ) { |
|
464
|
|
|
$q = $db->query("$query_base AND $dissolution[query]", |
|
465
|
|
|
array( |
|
466
|
|
|
':house' => $house, |
|
467
|
|
|
':cons_name' => $cons_name, |
|
468
|
|
|
) + $dissolution['params'] |
|
469
|
|
|
); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
1 |
|
for ($i = 0; $i < $q->rows; $i++) { |
|
473
|
1 |
|
$name = member_full_name($house, $q->field($i, 'title'), |
|
474
|
1 |
|
$q->field($i, 'given_name'), $q->field($i, 'family_name'), |
|
475
|
1 |
|
$q->field($i, 'lordofname')); |
|
476
|
|
|
|
|
477
|
1 |
|
$mreg[] = array( |
|
478
|
1 |
|
'person_id' => $q->field($i, 'person_id'), |
|
479
|
1 |
|
'name' => $name, |
|
480
|
1 |
|
'house' => $q->field($i, 'house'), |
|
481
|
1 |
|
'constituency' => $q->field($i, 'constituency') |
|
482
|
1 |
|
); |
|
483
|
1 |
|
} |
|
484
|
1 |
|
} |
|
485
|
|
|
|
|
486
|
1 |
|
return $mreg; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
public static function getRepNameForHouse($house) { |
|
490
|
|
|
switch ( $house ) { |
|
491
|
|
|
case HOUSE_TYPE_COMMONS: |
|
492
|
|
|
$name = 'MP'; |
|
493
|
|
|
break; |
|
494
|
|
|
case HOUSE_TYPE_LORDS: |
|
495
|
|
|
$name = 'Peer'; |
|
496
|
|
|
break; |
|
497
|
|
|
case HOUSE_TYPE_NI: |
|
498
|
|
|
$name = 'MLA'; |
|
499
|
|
|
break; |
|
500
|
|
|
case HOUSE_TYPE_SCOTLAND: |
|
501
|
|
|
$name = 'MSP'; |
|
502
|
|
|
break; |
|
503
|
|
|
default: |
|
504
|
|
|
$name = ''; |
|
505
|
|
|
} |
|
506
|
|
|
return $name; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
} |
|
510
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.