mysociety /
theyworkforyou
| 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 | * Is Dead |
||||
| 17 | * |
||||
| 18 | * Determine if the member has died or not. |
||||
| 19 | * |
||||
| 20 | * @return boolean If the member is dead or not. |
||||
| 21 | */ |
||||
| 22 | |||||
| 23 | public function isDead() { |
||||
| 24 | |||||
| 25 | $left_house = $this->left_house(); |
||||
| 26 | |||||
| 27 | if ($left_house) { |
||||
| 28 | |||||
| 29 | // This member has left a house, and might be dead. See if they are. |
||||
| 30 | |||||
| 31 | // Types of house to test for death. |
||||
| 32 | $house_types = [ |
||||
| 33 | HOUSE_TYPE_COMMONS, |
||||
| 34 | HOUSE_TYPE_LORDS, |
||||
| 35 | HOUSE_TYPE_SCOTLAND, |
||||
| 36 | HOUSE_TYPE_NI, |
||||
| 37 | HOUSE_TYPE_WALES, |
||||
| 38 | HOUSE_TYPE_LONDON_ASSEMBLY, |
||||
| 39 | ]; |
||||
| 40 | |||||
| 41 | foreach ($house_types as $house_type) { |
||||
| 42 | |||||
| 43 | if (in_array($house_type, $left_house) and |
||||
| 44 | $left_house[$house_type]['reason'] and |
||||
| 45 | $left_house[$house_type]['reason'] == 'Died' |
||||
| 46 | ) { |
||||
| 47 | |||||
| 48 | // This member has left a house because of death. |
||||
| 49 | return true; |
||||
| 50 | } |
||||
| 51 | |||||
| 52 | } |
||||
| 53 | |||||
| 54 | } |
||||
| 55 | |||||
| 56 | // If we get this far the member hasn't left a house due to death, and |
||||
| 57 | // is presumably alive. |
||||
| 58 | return false; |
||||
| 59 | |||||
| 60 | } |
||||
| 61 | |||||
| 62 | public function cohortPartyComparisonDirection() { |
||||
| 63 | // Is this MP and their cohort compared against the |
||||
| 64 | // first or last party they have? |
||||
| 65 | // By default, mirroring the partycohort query, |
||||
| 66 | // this is the first party. |
||||
| 67 | // However, this is ignored for the Speaker, and additional |
||||
| 68 | // individual overrides can be added below. |
||||
| 69 | // This makes most sense when a party switch was a long time ago. |
||||
| 70 | // As long as this person is in a cohort of 1 and has a unique set |
||||
| 71 | // of memberships (which is likely for edge cases) it doesn't matter |
||||
| 72 | 13 | // that their original party is what is used when in the party cohort |
|||
| 73 | // construction query. |
||||
| 74 | 13 | ||||
| 75 | 13 | $person_id = $this->person_id(); |
|||
| 76 | |||||
| 77 | $direction = "first"; |
||||
| 78 | 20 | if ($this->party() == "Speaker") { |
|||
| 79 | $direction = "last"; |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | // MPs who have switched parties but should be compared against their |
||||
| 83 | // current party can go here. |
||||
| 84 | $use_last_party = [10172, 14031, 25873, 10218]; |
||||
| 85 | |||||
| 86 | if (in_array($person_id, $use_last_party)) { |
||||
| 87 | $direction = "last"; |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | return $direction; |
||||
| 91 | 20 | } |
|||
| 92 | |||||
| 93 | 20 | public function currentPartyComparison() { |
|||
| 94 | 20 | # Simplify the current party when being compared to the original |
|||
| 95 | 20 | # Stops co-op and labour being seen as different |
|||
| 96 | $party = $this->party; |
||||
| 97 | if ($party == 'Labour/Co-operative') { |
||||
| 98 | $party = 'Labour'; |
||||
| 99 | } |
||||
| 100 | 20 | return $party; |
|||
| 101 | } |
||||
| 102 | 20 | ||||
| 103 | 1 | public function cohortParty($house = HOUSE_TYPE_COMMONS) { |
|||
| 104 | // The party being compared against for party comparison purposes |
||||
| 105 | // Unless specified by the condition in cohortPartyComparisonDirection |
||||
| 106 | 20 | // This is the first, not last, party a person has. |
|||
| 107 | |||||
| 108 | $person_id = $this->person_id(); |
||||
| 109 | $db = new \ParlDB(); |
||||
| 110 | |||||
| 111 | $cohort_direction = $this->cohortPartyComparisonDirection(); |
||||
| 112 | |||||
| 113 | if ($cohort_direction == "first") { |
||||
| 114 | $direction = " ASC"; |
||||
| 115 | } else { |
||||
| 116 | $direction = " DESC"; |
||||
| 117 | } |
||||
| 118 | |||||
| 119 | 20 | $row = $db->query("SELECT party from member |
|||
| 120 | where house = :house |
||||
| 121 | and person_id = :person_id |
||||
| 122 | and party != '' |
||||
| 123 | order by entered_house |
||||
| 124 | 20 | " . $direction, [":house" => $house, |
|||
| 125 | 20 | ":person_id" => $person_id])->first(); |
|||
| 126 | if ($row) { |
||||
| 127 | 20 | $party = $row["party"]; |
|||
| 128 | if ($party == 'Labour/Co-operative') { |
||||
| 129 | 20 | $party = 'Labour'; |
|||
| 130 | 20 | } elseif ($party == 'Sinn Féin') { |
|||
| 131 | $party = 'Sinn Fein'; |
||||
| 132 | 20 | } |
|||
| 133 | return slugify($party); |
||||
| 134 | } else { |
||||
| 135 | 20 | return null; |
|||
| 136 | } |
||||
| 137 | |||||
| 138 | } |
||||
| 139 | |||||
| 140 | 20 | /* |
|||
| 141 | 20 | * Determine if the member is a new member of a house where new is |
|||
| 142 | 20 | * within the last 6 months. |
|||
| 143 | 20 | * |
|||
| 144 | 20 | * @param int house - identifier for the house, defaults to 1 for westminster |
|||
|
0 ignored issues
–
show
|
|||||
| 145 | * |
||||
| 146 | * @return boolean |
||||
| 147 | 20 | */ |
|||
| 148 | |||||
| 149 | |||||
| 150 | public function isNew($house = HOUSE_TYPE_COMMONS) { |
||||
| 151 | $date_entered = $this->getEntryDate($house); |
||||
| 152 | |||||
| 153 | if ($date_entered) { |
||||
| 154 | $date_entered = new \DateTime($date_entered); |
||||
| 155 | $now = new \DateTime(); |
||||
| 156 | |||||
| 157 | $diff = $date_entered->diff($now); |
||||
| 158 | if ($diff->y == 0 && $diff->m <= 6) { |
||||
| 159 | return true; |
||||
| 160 | } |
||||
| 161 | } |
||||
| 162 | |||||
| 163 | return false; |
||||
| 164 | 1 | } |
|||
| 165 | 1 | ||||
| 166 | /* |
||||
| 167 | 1 | * Get the date the person first entered a house. May not be for their current seat. |
|||
| 168 | 1 | * |
|||
| 169 | 1 | * @param int house - identifier for the house, defaults to 1 for westminster |
|||
| 170 | * |
||||
| 171 | 1 | * @return string - blank if no entry date for that house otherwise in YYYY-MM-DD format |
|||
| 172 | 1 | */ |
|||
| 173 | 1 | ||||
| 174 | public function getEntryDate($house = HOUSE_TYPE_COMMONS) { |
||||
| 175 | $date_entered = ''; |
||||
| 176 | |||||
| 177 | 1 | $entered_house = $this->entered_house($house); |
|||
| 178 | |||||
| 179 | if ($entered_house) { |
||||
| 180 | $date_entered = $entered_house['date']; |
||||
| 181 | } |
||||
| 182 | |||||
| 183 | return $date_entered; |
||||
| 184 | } |
||||
| 185 | |||||
| 186 | /* |
||||
| 187 | * Get the date the person last left the house. |
||||
| 188 | 2 | * |
|||
| 189 | 2 | * @param int house - identifier for the house, defaults to 1 for westminster |
|||
| 190 | * |
||||
| 191 | 2 | * @return string - 9999-12-31 if they are still in that house otherwise in YYYY-MM-DD format |
|||
| 192 | */ |
||||
| 193 | 2 | ||||
| 194 | 2 | public function getLeftDate($house = HOUSE_TYPE_COMMONS) { |
|||
| 195 | $date_left = ''; |
||||
| 196 | |||||
| 197 | 2 | $left_house = $this->left_house($house); |
|||
| 198 | |||||
| 199 | if ($left_house) { |
||||
| 200 | $date_left = $left_house['date']; |
||||
| 201 | } |
||||
| 202 | |||||
| 203 | return $date_left; |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | |||||
| 207 | public function getEUStance() { |
||||
| 208 | if (array_key_exists('eu_ref_stance', $this->extra_info())) { |
||||
| 209 | return $this->extra_info()['eu_ref_stance']; |
||||
| 210 | } |
||||
| 211 | |||||
| 212 | return false; |
||||
| 213 | } |
||||
| 214 | |||||
| 215 | /** |
||||
| 216 | * Image |
||||
| 217 | * |
||||
| 218 | * Return a URL for the member's image. |
||||
| 219 | * |
||||
| 220 | * @return string The URL of the member's image. |
||||
| 221 | */ |
||||
| 222 | |||||
| 223 | public function image() { |
||||
| 224 | |||||
| 225 | $is_lord = $this->house(HOUSE_TYPE_LORDS); |
||||
| 226 | if ($is_lord) { |
||||
| 227 | [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
||||
| 228 | } else { |
||||
| 229 | [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, true); |
||||
| 230 | } |
||||
| 231 | |||||
| 232 | // We can determine if the image exists or not by testing if size is set |
||||
| 233 | if ($size !== null) { |
||||
| 234 | $exists = true; |
||||
| 235 | } else { |
||||
| 236 | $exists = false; |
||||
| 237 | } |
||||
| 238 | |||||
| 239 | return [ |
||||
|
0 ignored issues
–
show
|
|||||
| 240 | 'url' => $image, |
||||
| 241 | 'size' => $size, |
||||
| 242 | 'exists' => $exists, |
||||
| 243 | ]; |
||||
| 244 | |||||
| 245 | } |
||||
| 246 | |||||
| 247 | public function getMostRecentMembership() { |
||||
| 248 | $departures = $this->left_house(); |
||||
| 249 | |||||
| 250 | usort( |
||||
| 251 | $departures, |
||||
|
0 ignored issues
–
show
It seems like
$departures can also be of type null; however, parameter $array of usort() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 252 | function ($a, $b) { |
||||
| 253 | if ($a['date'] == $b['date']) { |
||||
| 254 | return 0; |
||||
| 255 | } elseif ($a['date'] < $b['date']) { |
||||
| 256 | return -1; |
||||
| 257 | } else { |
||||
| 258 | return 1; |
||||
| 259 | } |
||||
| 260 | } |
||||
| 261 | ); |
||||
| 262 | |||||
| 263 | $latest_membership = array_slice($departures, -1)[0]; |
||||
| 264 | $latest_membership['current'] = ($latest_membership['date'] == '9999-12-31'); |
||||
| 265 | $latest_entrance = $this->entered_house($latest_membership['house']); |
||||
| 266 | $latest_membership['start_date'] = $latest_entrance['date']; |
||||
| 267 | $latest_membership['end_date'] = $latest_membership['date']; |
||||
| 268 | $latest_membership['rep_name'] = $this->getRepNameForHouse($latest_membership['house']); |
||||
| 269 | |||||
| 270 | return $latest_membership; |
||||
| 271 | } |
||||
| 272 | |||||
| 273 | /** |
||||
| 274 | * Get Whip Removal Information |
||||
| 275 | * |
||||
| 276 | * Check if the current membership has 'whip_removed' as entered_reason and return info. |
||||
| 277 | * |
||||
| 278 | * @return array|null Information about whip removal including previous party and source URL. |
||||
| 279 | */ |
||||
| 280 | public function getWhipRemovalInfo() { |
||||
| 281 | // Check if there are any memberships |
||||
| 282 | if (empty($this->memberships)) { |
||||
| 283 | return null; |
||||
| 284 | } |
||||
| 285 | |||||
| 286 | // Get the current (most recent) membership |
||||
| 287 | $current_membership = $this->memberships[0]; |
||||
| 288 | |||||
| 289 | // Check if this is a current membership (still in office) |
||||
| 290 | if ($current_membership['left_house'] != '9999-12-31') { |
||||
| 291 | return null; |
||||
| 292 | } |
||||
| 293 | |||||
| 294 | // Check if entered_reason is 'whip_removed' for current membership |
||||
| 295 | if ($current_membership['entered_reason'] != 'whip_removed') { |
||||
| 296 | return null; |
||||
| 297 | } |
||||
| 298 | |||||
| 299 | // Find the previous membership (next in the array) |
||||
| 300 | $previous_membership = null; |
||||
| 301 | if (count($this->memberships) > 1) { |
||||
| 302 | $previous_membership = $this->memberships[1]; |
||||
| 303 | } |
||||
| 304 | |||||
| 305 | return [ |
||||
| 306 | 'has_whip_removed' => true, |
||||
| 307 | 'previous_party' => $previous_membership ? $previous_membership['party'] : null, |
||||
| 308 | 'source' => $current_membership['source'] ?? '', |
||||
| 309 | ]; |
||||
| 310 | } |
||||
| 311 | |||||
| 312 | /** |
||||
| 313 | * Offices |
||||
| 314 | * |
||||
| 315 | * Return an array of Office objects held (or previously held) by the member. |
||||
| 316 | * |
||||
| 317 | * @param string $include_only Restrict the list to include only "previous" or "current" offices. |
||||
| 318 | * @param bool $ignore_committees Ignore offices that appear to be committee memberships. |
||||
| 319 | * @param bool $committees_only Only return committee memberships. |
||||
| 320 | * |
||||
| 321 | * @return array An array of Office objects. |
||||
| 322 | */ |
||||
| 323 | |||||
| 324 | public function offices($include_only = null, $ignore_committees = false, $committees_only = false) { |
||||
| 325 | |||||
| 326 | $out = []; |
||||
| 327 | |||||
| 328 | if (array_key_exists('office', $this->extra_info())) { |
||||
| 329 | $office = $this->extra_info(); |
||||
| 330 | $office = $office['office']; |
||||
| 331 | |||||
| 332 | foreach ($office as $row) { |
||||
| 333 | if ($officeObject = $this->getOfficeObject($include_only, $ignore_committees, $committees_only, $row)) { |
||||
| 334 | $out[] = $officeObject; |
||||
| 335 | } |
||||
| 336 | } |
||||
| 337 | } |
||||
| 338 | |||||
| 339 | return $out; |
||||
| 340 | |||||
| 341 | } |
||||
| 342 | |||||
| 343 | private function getOfficeObject($include_only, $ignore_committees, $committees_only, $row) { |
||||
| 344 | if (!$this->includeOffice($include_only, $row['to_date'])) { |
||||
| 345 | return null; |
||||
| 346 | } |
||||
| 347 | if ($ignore_committees && strpos($row['moffice_id'], 'Committee')) { |
||||
| 348 | return null; |
||||
| 349 | } |
||||
| 350 | |||||
| 351 | if ($committees_only && !strpos($row['moffice_id'], 'Committee')) { |
||||
| 352 | return null; |
||||
| 353 | } |
||||
| 354 | |||||
| 355 | $officeObject = new Office(); |
||||
| 356 | $officeObject->title = prettify_office($row['position'], $row['dept']); |
||||
| 357 | $officeObject->position = $row['position']; |
||||
| 358 | $officeObject->dept = $row['dept']; |
||||
| 359 | $officeObject->from_date = $row['from_date']; |
||||
| 360 | $officeObject->to_date = $row['to_date']; |
||||
| 361 | $officeObject->source = $row['source']; |
||||
| 362 | return $officeObject; |
||||
| 363 | } |
||||
| 364 | |||||
| 365 | private function includeOffice($include_only, $to_date) { |
||||
| 366 | $include_office = true; |
||||
| 367 | |||||
| 368 | // If we should only include previous offices, and the to date is in the future, suppress this office. |
||||
| 369 | if ($include_only == 'previous' and $to_date == '9999-12-31') { |
||||
| 370 | $include_office = false; |
||||
| 371 | } |
||||
| 372 | |||||
| 373 | // If we should only include previous offices, and the to date is in the past, suppress this office. |
||||
| 374 | if ($include_only == 'current' and $to_date != '9999-12-31') { |
||||
| 375 | $include_office = false; |
||||
| 376 | } |
||||
| 377 | |||||
| 378 | return $include_office; |
||||
| 379 | } |
||||
| 380 | |||||
| 381 | /** |
||||
| 382 | * Get Other Parties String |
||||
| 383 | * |
||||
| 384 | * Return a readable list of party changes for this member. |
||||
| 385 | * |
||||
| 386 | * @return string|null A readable list of the party changes for this member. |
||||
| 387 | */ |
||||
| 388 | |||||
| 389 | public function getOtherPartiesString() { |
||||
| 390 | |||||
| 391 | if (!empty($this->other_parties) && $this->party != 'Speaker' && $this->party != 'Deputy Speaker') { |
||||
| 392 | $output = 'Party was '; |
||||
| 393 | $other_parties = []; |
||||
| 394 | foreach ($this->other_parties as $r) { |
||||
| 395 | $other_parties[] = $r['from'] . ' until ' . format_date($r['date'], SHORTDATEFORMAT); |
||||
| 396 | } |
||||
| 397 | $output .= join('; ', $other_parties); |
||||
| 398 | return $output; |
||||
| 399 | } else { |
||||
| 400 | 1 | return null; |
|||
| 401 | 1 | } |
|||
| 402 | |||||
| 403 | 1 | } |
|||
| 404 | |||||
| 405 | 1 | /** |
|||
| 406 | * Get Other Constituencies String |
||||
| 407 | * |
||||
| 408 | * Return a readable list of other constituencies for this member. |
||||
| 409 | * |
||||
| 410 | * @return string|null A readable list of the other constituencies for this member. |
||||
| 411 | */ |
||||
| 412 | |||||
| 413 | public function getOtherConstituenciesString() { |
||||
| 414 | |||||
| 415 | 1 | if ($this->other_constituencies) { |
|||
| 416 | return 'Also represented ' . join('; ', array_keys($this->other_constituencies)); |
||||
| 417 | 1 | } else { |
|||
| 418 | return null; |
||||
| 419 | } |
||||
| 420 | |||||
| 421 | } |
||||
| 422 | |||||
| 423 | 1 | /** |
|||
| 424 | * Get Entered/Left Strings |
||||
| 425 | * |
||||
| 426 | 1 | * Return an array of readable strings covering when people entered or left |
|||
| 427 | * various houses. Returns an array since it's possible for a member to have |
||||
| 428 | * done several of these things. |
||||
| 429 | * |
||||
| 430 | 1 | * @return array An array of strings of when this member entered or left houses. |
|||
| 431 | 1 | */ |
|||
| 432 | 1 | public function getEnterLeaveStrings() { |
|||
| 433 | 1 | $output = []; |
|||
| 434 | 1 | ||||
| 435 | 1 | $output[] = $this->entered_house_line(HOUSE_TYPE_LORDS, gettext('House of Lords')); |
|||
| 436 | 1 | ||||
| 437 | 1 | if (isset($this->left_house[HOUSE_TYPE_COMMONS]) && isset($this->entered_house[HOUSE_TYPE_LORDS])) { |
|||
| 438 | $string = '<strong>'; |
||||
| 439 | 1 | $string .= sprintf(gettext('Previously MP for %s until %s'), $this->left_house[HOUSE_TYPE_COMMONS]['constituency'], $this->left_house[HOUSE_TYPE_COMMONS]['date_pretty']); |
|||
| 440 | 1 | $string .= '</strong>'; |
|||
| 441 | if ($this->left_house[HOUSE_TYPE_COMMONS]['reason']) { |
||||
| 442 | $string .= ' — ' . $this->left_house[HOUSE_TYPE_COMMONS]['reason']; |
||||
| 443 | 1 | } |
|||
| 444 | 1 | $output[] = $string; |
|||
| 445 | 1 | } |
|||
| 446 | 1 | ||||
| 447 | $output[] = $this->left_house_line(HOUSE_TYPE_LORDS, gettext('House of Lords')); |
||||
| 448 | |||||
| 449 | 1 | if (isset($this->extra_info['lordbio'])) { |
|||
| 450 | $output[] = '<strong>Positions held at time of appointment:</strong> ' . $this->extra_info['lordbio'] . |
||||
| 451 | 1 | ' <small>(from <a href="' . |
|||
| 452 | 1 | $this->extra_info['lordbio_from'] . '">Number 10 press release</a>)</small>'; |
|||
| 453 | 1 | } |
|||
| 454 | |||||
| 455 | 1 | $output[] = $this->entered_house_line(HOUSE_TYPE_COMMONS, gettext('House of Commons')); |
|||
| 456 | |||||
| 457 | 1 | # If they became a Lord, we handled this above. |
|||
| 458 | if ($this->house(HOUSE_TYPE_COMMONS) && !$this->current_member(HOUSE_TYPE_COMMONS) && !$this->house(HOUSE_TYPE_LORDS)) { |
||||
| 459 | 1 | $output[] = $this->left_house_line(HOUSE_TYPE_COMMONS, gettext('House of Commons')); |
|||
| 460 | 1 | } |
|||
| 461 | 1 | ||||
| 462 | 1 | $output[] = $this->entered_house_line(HOUSE_TYPE_NI, gettext('Assembly')); |
|||
| 463 | $output[] = $this->left_house_line(HOUSE_TYPE_NI, gettext('Assembly')); |
||||
| 464 | $output[] = $this->entered_house_line(HOUSE_TYPE_SCOTLAND, gettext('Scottish Parliament')); |
||||
| 465 | 1 | $output[] = $this->left_house_line(HOUSE_TYPE_SCOTLAND, gettext('Scottish Parliament')); |
|||
| 466 | $output[] = $this->entered_house_line(HOUSE_TYPE_WALES, gettext('Senedd')); |
||||
| 467 | 1 | $output[] = $this->left_house_line(HOUSE_TYPE_WALES, gettext('Senedd')); |
|||
| 468 | 1 | $output[] = $this->entered_house_line(HOUSE_TYPE_LONDON_ASSEMBLY, gettext('London Assembly')); |
|||
| 469 | 1 | $output[] = $this->left_house_line(HOUSE_TYPE_LONDON_ASSEMBLY, gettext('London Assembly')); |
|||
| 470 | |||||
| 471 | 1 | $output = array_values(array_filter($output)); |
|||
| 472 | return $output; |
||||
| 473 | 1 | } |
|||
| 474 | |||||
| 475 | private function entered_house_line($house, $house_name) { |
||||
| 476 | if (isset($this->entered_house[$house]['date'])) { |
||||
| 477 | $string = "<strong>"; |
||||
| 478 | if (strlen($this->entered_house[$house]['date_pretty']) == 4) { |
||||
| 479 | $string .= sprintf(gettext("Entered the %s in %s"), $house_name, $this->entered_house[$house]['date_pretty']); |
||||
| 480 | } else { |
||||
| 481 | $string .= sprintf(gettext("Entered the %s on %s"), $house_name, $this->entered_house[$house]['date_pretty']); |
||||
| 482 | } |
||||
| 483 | $string .= '</strong>'; |
||||
| 484 | if ($this->entered_house[$house]['reason']) { |
||||
| 485 | $string .= ' — ' . $this->entered_house[$house]['reason']; |
||||
| 486 | } |
||||
| 487 | return $string; |
||||
| 488 | } |
||||
| 489 | } |
||||
| 490 | |||||
| 491 | private function left_house_line($house, $house_name) { |
||||
| 492 | if ($this->house($house) && !$this->current_member($house)) { |
||||
| 493 | $string = "<strong>"; |
||||
| 494 | if (strlen($this->left_house[$house]['date_pretty']) == 4) { |
||||
| 495 | $string .= sprintf(gettext("Left the %s in %s"), $house_name, $this->left_house[$house]['date_pretty']); |
||||
| 496 | } else { |
||||
| 497 | $string .= sprintf(gettext("Left the %s on %s"), $house_name, $this->left_house[$house]['date_pretty']); |
||||
| 498 | } |
||||
| 499 | $string .= '</strong>'; |
||||
| 500 | if ($this->left_house[$house]['reason']) { |
||||
| 501 | $string .= ' — ' . $this->left_house[$house]['reason']; |
||||
| 502 | } |
||||
| 503 | return $string; |
||||
| 504 | } |
||||
| 505 | } |
||||
| 506 | |||||
| 507 | public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions) { |
||||
| 508 | $policy_diffs = []; |
||||
| 509 | $party_positions = $partyCohort->getAllPolicyPositions($policiesList); |
||||
| 510 | |||||
| 511 | if (!$party_positions) { |
||||
| 512 | return $policy_diffs; |
||||
| 513 | } |
||||
| 514 | |||||
| 515 | foreach ($positions->positionsById as $policy_id => $details) { |
||||
| 516 | if ($details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
||||
| 517 | $mp_score = $details['score']; |
||||
| 518 | $party_position = $party_positions[$policy_id]; |
||||
| 519 | $party_score = $party_position['score']; |
||||
| 520 | $year_min = substr($party_position['date_min'], 0, 4); |
||||
| 521 | $year_max = substr($party_position['date_max'], 0, 4); |
||||
| 522 | if ($year_min == $year_max) { |
||||
| 523 | $party_voting_summary = sprintf("%d votes, in %d", $party_position['divisions'], $year_min); |
||||
| 524 | } else { |
||||
| 525 | $party_voting_summary = sprintf("%d votes, between %d–%d", $party_position['divisions'], $year_min, $year_max); |
||||
| 526 | } |
||||
| 527 | |||||
| 528 | $score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score); |
||||
| 529 | |||||
| 530 | $policy_diffs[$policy_id] = [ |
||||
| 531 | 'policy_text' => $details['policy'], |
||||
| 532 | 'score_difference' => $score_diff, |
||||
| 533 | 'person_position' => $details['position'], |
||||
| 534 | 'summary' => $details['summary'], |
||||
| 535 | 'party_position' => $party_position['position'], |
||||
| 536 | 'party_voting_summary' => $party_voting_summary, |
||||
| 537 | ]; |
||||
| 538 | } |
||||
| 539 | 1 | } |
|||
| 540 | 1 | ||||
| 541 | uasort($policy_diffs, function ($a, $b) { |
||||
| 542 | 1 | return $b['score_difference'] - $a['score_difference']; |
|||
| 543 | 1 | }); |
|||
| 544 | 1 | ||||
| 545 | 1 | return $policy_diffs; |
|||
| 546 | 1 | } |
|||
| 547 | |||||
| 548 | private function calculatePolicyDiffScore($mp_score, $party_score) { |
||||
| 549 | $score_diff = abs($mp_score - $party_score); |
||||
| 550 | // if they are on opposite sides of mixture of for and against |
||||
| 551 | if ( |
||||
| 552 | ($mp_score < 0.4 && $party_score > 0.6) || |
||||
| 553 | ($mp_score > 0.6 && $party_score < 0.4) |
||||
| 554 | ) { |
||||
| 555 | 1 | $score_diff += 2; |
|||
| 556 | // if on is mixture of for and against and one is for/against |
||||
| 557 | 1 | } elseif ( |
|||
| 558 | 1 | ($mp_score > 0.4 && $mp_score < 0.6 && ($party_score > 0.6 || $party_score < 0.4)) || |
|||
|
0 ignored issues
–
show
|
|||||
| 559 | ($party_score > 0.4 && $party_score < 0.6 && ($mp_score > 0.6 || $mp_score < 0.4)) |
||||
| 560 | ) { |
||||
| 561 | 1 | $score_diff += 1; |
|||
| 562 | } |
||||
| 563 | |||||
| 564 | return $score_diff; |
||||
| 565 | } |
||||
| 566 | |||||
| 567 | public static function getRegionalList($postcode, $house, $type) { |
||||
| 568 | $db = new \ParlDB(); |
||||
| 569 | |||||
| 570 | 1 | $mreg = []; |
|||
| 571 | 1 | $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); |
|||
| 572 | 1 | if (isset($constituencies[$type])) { |
|||
| 573 | 1 | $cons_name = $constituencies[$type]; |
|||
| 574 | 1 | $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house |
|||
| 575 | 1 | FROM member, person_names |
|||
| 576 | 1 | WHERE |
|||
| 577 | member.person_id = person_names.person_id |
||||
| 578 | AND person_names.type = 'name' |
||||
| 579 | AND constituency = :cons_name |
||||
| 580 | AND house = :house |
||||
| 581 | 1 | AND left_house >= start_date |
|||
| 582 | AND left_house <= end_date"; |
||||
| 583 | $q = $db->query( |
||||
| 584 | "$query_base AND left_reason = 'still_in_office'", |
||||
| 585 | [ |
||||
| 586 | ':house' => $house, |
||||
| 587 | ':cons_name' => $cons_name, |
||||
| 588 | ] |
||||
| 589 | ); |
||||
| 590 | if (!$q->rows() && ($dissolution = Dissolution::db())) { |
||||
| 591 | $q = $db->query( |
||||
| 592 | "$query_base AND $dissolution[query]", |
||||
| 593 | [ |
||||
| 594 | ':house' => $house, |
||||
| 595 | ':cons_name' => $cons_name, |
||||
| 596 | ] + $dissolution['params'] |
||||
| 597 | ); |
||||
| 598 | } |
||||
| 599 | |||||
| 600 | foreach ($q as $row) { |
||||
| 601 | $name = member_full_name($house, $row['title'], $row['given_name'], $row['family_name'], $row['lordofname']); |
||||
| 602 | $mreg[] = [ |
||||
| 603 | 'person_id' => $row['person_id'], |
||||
| 604 | 'name' => $name, |
||||
| 605 | 'house' => $row['house'], |
||||
| 606 | 'constituency' => gettext($row['constituency']), |
||||
| 607 | ]; |
||||
| 608 | } |
||||
| 609 | } |
||||
| 610 | |||||
| 611 | return $mreg; |
||||
| 612 | } |
||||
| 613 | |||||
| 614 | public static function getRepNameForHouse($house) { |
||||
| 615 | switch ($house) { |
||||
| 616 | case HOUSE_TYPE_COMMONS: |
||||
| 617 | $name = 'MP'; |
||||
| 618 | break; |
||||
| 619 | case HOUSE_TYPE_LORDS: |
||||
| 620 | $name = 'Peer'; |
||||
| 621 | break; |
||||
| 622 | case HOUSE_TYPE_NI: |
||||
| 623 | $name = 'MLA'; |
||||
| 624 | break; |
||||
| 625 | case HOUSE_TYPE_SCOTLAND: |
||||
| 626 | $name = 'MSP'; |
||||
| 627 | break; |
||||
| 628 | case HOUSE_TYPE_WALES: |
||||
| 629 | $name = 'MS'; |
||||
| 630 | break; |
||||
| 631 | case HOUSE_TYPE_LONDON_ASSEMBLY: |
||||
| 632 | $name = 'London Assembly Member'; |
||||
| 633 | break; |
||||
| 634 | case HOUSE_TYPE_ROYAL: |
||||
| 635 | $name = 'Member of royalty'; |
||||
| 636 | break; |
||||
| 637 | default: |
||||
| 638 | $name = ''; |
||||
| 639 | } |
||||
| 640 | return $name; |
||||
| 641 | } |
||||
| 642 | |||||
| 643 | } |
||||
| 644 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths