Skip to content

Commit

Permalink
Show any non-committee postion in the header.
Browse files Browse the repository at this point in the history
This should mean all ministers/shadow ministers get shown as such in the
header of their page.
  • Loading branch information
dracos authored and struan committed Mar 31, 2017
1 parent 490fa25 commit 80478b3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 79 deletions.
40 changes: 14 additions & 26 deletions classes/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@

class Member extends \MEMBER {

private $priority_offices = array(
'The Prime Minister',
'The Deputy Prime Minister ',
'Leader of Her Majesty\'s Official Opposition',
'The Chancellor of the Exchequer',
);

/**
* Is Dead
*
Expand Down Expand Up @@ -219,12 +212,12 @@ public function getMostRecentMembership() {
* Return an array of Office objects held (or previously held) by the member.
*
* @param string $include_only Restrict the list to include only "previous" or "current" offices.
* @param bool $priority_only Restrict the list to include only positions in the $priority_offices list.
* @param bool $ignore_committees Ignore offices that appear to be committee memberships.
*
* @return array An array of Office objects.
*/

public function offices($include_only = NULL, $priority_only = FALSE) {
public function offices($include_only = NULL, $ignore_committees = FALSE) {

$out = array();

Expand All @@ -233,9 +226,7 @@ public function offices($include_only = NULL, $priority_only = FALSE) {
$office = $office['office'];

foreach ($office as $row) {
$office_title = prettify_office($row['position'], $row['dept']);

if ( $officeObject = $this->getOfficeObject($include_only, $priority_only, $office_title, $row) ) {
if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) {
$out[] = $officeObject;
}
}
Expand All @@ -245,22 +236,19 @@ public function offices($include_only = NULL, $priority_only = FALSE) {

}

private function getOfficeObject($include_only, $priority_only, $office_title, $row) {
$officeObject = null;

if ( $this->includeOffice($include_only, $row['to_date']) ) {
if (($priority_only AND in_array($office_title, $this->priority_offices)) OR !$priority_only) {
$officeObject = new Office;

$officeObject->title = $office_title;

$officeObject->from_date = $row['from_date'];
$officeObject->to_date = $row['to_date'];

$officeObject->source = $row['source'];
}
private function getOfficeObject($include_only, $ignore_committees, $row) {
if (!$this->includeOffice($include_only, $row['to_date'])) {
return null;
}
if ($ignore_committees && strpos($row['moffice_id'], 'Committee')) {
return null;
}

$officeObject = new Office;
$officeObject->title = prettify_office($row['position'], $row['dept']);
$officeObject->from_date = $row['from_date'];
$officeObject->to_date = $row['to_date'];
$officeObject->source = $row['source'];
return $officeObject;
}

Expand Down
58 changes: 19 additions & 39 deletions www/docs/mp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,49 +219,39 @@
$title .= ' MSP, '.$MEMBER->constituency();
}

$positions = array();

// Position if this is a member of the Commons
if ($MEMBER->house(HOUSE_TYPE_COMMONS)) {
if (!$MEMBER->current_member(1)) {
$position_former = 'Former MP';
if ($MEMBER->constituency()) $position_former .= ', ' . $MEMBER->constituency();
} else {
$position_current = 'MP';
if ($MEMBER->constituency()) $position_current .= ', ' . $MEMBER->constituency();
}
$position = $MEMBER->current_member(HOUSE_TYPE_COMMONS) ? 'MP' : 'Former MP';
if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency();
$positions[] = $position;
}

// Position if this is a member of NIA
if ($MEMBER->house(HOUSE_TYPE_NI)) {
if (!$MEMBER->current_member(HOUSE_TYPE_NI)) {
$position_former = 'Former MLA';
if ($MEMBER->constituency()) $position_former .= ', ' . $MEMBER->constituency();
} else {
$position_current = 'MLA';
if ($MEMBER->constituency()) $position_current .= ', ' . $MEMBER->constituency();
}
$position = $MEMBER->current_member(HOUSE_TYPE_NI) ? 'MLA' : 'Former MLA';
if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency();
$positions[] = $position;
}

// Position if this is a member of Scottish Parliament
if ($MEMBER->house(HOUSE_TYPE_SCOTLAND)) {
if (!$MEMBER->current_member(HOUSE_TYPE_SCOTLAND)) {
$position_former = 'Former MSP';
} else {
$position_current = 'MSP, '.$MEMBER->constituency();
}
$position = $MEMBER->current_member(HOUSE_TYPE_SCOTLAND) ? 'MSP' : 'Former MSP';
$position .= ', ' . $MEMBER->constituency();
$positions[] = $position;
}

$position = implode('; ', $positions);

$current_offices = $MEMBER->offices('current', TRUE);
$former_offices = $MEMBER->offices('previous', TRUE);

// If this person has current named *priority* offices, they override the defaults

if (count($current_offices) > 0){
$position_current = implode('<br>', $current_offices);
}

// If this person has former named *priority* offices, they override the defaults
if (count($former_offices) > 0){
$position_former = implode('<br>', $former_offices);
// If this person has named non-committee offices, they override the default
if (count($current_offices) > 0) {
$position = $current_offices[0];
} elseif (count($former_offices) > 0) {
$position = $former_offices[0];
}

// Finally, if this is a Votes page, replace the page description with
Expand All @@ -285,17 +275,7 @@
$data['person_id'] = $MEMBER->person_id();
$data['member_id'] = $MEMBER->member_id();

if (isset($position_current)) {
$data['current_position'] = $position_current;
} else {
$data['current_position'] = NULL;
}

if (isset($position_former)) {
$data['former_position'] = $position_former;
} else {
$data['former_position'] = NULL;
}
$data['header_position'] = $position;

$data['constituency'] = $MEMBER->constituency();
$data['party'] = $MEMBER->party_text();
Expand Down
2 changes: 1 addition & 1 deletion www/includes/easyparliament/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function load_extra_info($display = false) {
}
$this->extra_info = array();

$q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC',
$q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC, moffice_id',
array(':person_id' => $this->person_id));
for ($row=0; $row<$q->rows(); $row++) {
$this->extra_info['office'][] = $q->row($row);
Expand Down
6 changes: 2 additions & 4 deletions www/includes/easyparliament/templates/html/mp/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
<?php } ?>
<div class="mp-name-and-position">
<h1><?= $full_name ?></h1>
<?php if ($current_position) { ?>
<p><?= $current_position ?></p>
<?php } else if ($former_position) { ?>
<p><?= $former_position ?></p>
<?php if ($header_position) { ?>
<p><?= $header_position ?></p>
<?php } ?>
</div>
</div>
Expand Down
22 changes: 13 additions & 9 deletions www/includes/utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,15 +933,19 @@ function prettify_office($pos, $dept) {
=> 'Minister for energy, Department of Trade and Industry',
'Minister of State (Pensions), Department for Work and Pensions'
=> 'Minister for pensions, Department for Work and Pensions',
'Parliamentary Secretary to the Treasury, HM Treasury'
=> 'Chief Whip (technically Parliamentary Secretary to the Treasury)',
"Treasurer of Her Majesty's Household, HM Household"
=> "Deputy Chief Whip (technically Treasurer of Her Majesty's Household)",
'Comptroller, HM Household' => 'Government Whip (technically Comptroller, HM Household)',
'Vice Chamberlain, HM Household' => 'Government Whip (technically Vice Chamberlain, HM Household)',
'Lords Commissioner, HM Treasury' => 'Government Whip (technically a Lords Commissioner, HM Treasury)',
'Assistant Whip, HM Treasury' => 'Assistant Whip (funded by HM Treasury)',
'Lords in Waiting, HM Household' => 'Government Whip (technically a Lord in Waiting, HM Household)',
'Parliamentary Secretary to the Treasury, HM Treasury' => 'Chief Whip',
'The Parliamentary Secretary to the Treasury' => 'Chief Whip',
"Treasurer of Her Majesty's Household, HM Household" => "Deputy Chief Whip",
"The Treasurer of Her Majesty's Household, HM Household" => "Deputy Chief Whip",
'Comptroller, HM Household' => 'Government Whip',
'Vice Chamberlain, HM Household' => 'Government Whip',
"The Vice-Chamberlain of Her Majesty's Household" => 'Government Whip',
'Lords Commissioner, HM Treasury' => 'Government Whip',
"The Lord Commissioner of Her Majesty's Treasury" => 'Government Whip',
'Assistant Whip, HM Treasury' => 'Assistant Whip',
'Lords in Waiting, HM Household' => 'Government Whip',
'Lords in Waiting (HM Household)' => 'Government Whip',
'Baronesses in Waiting, HM Household' => 'Government Whip',
);
if ($pos) { # Government post, or Chairman of Select Committee
$pretty = $pos;
Expand Down

0 comments on commit 80478b3

Please sign in to comment.