예제 #1
0
function _api_getPerson_output($q)
{
    $output = array();
    $last_mod = 0;
    for ($i = 0; $i < $q->rows(); $i++) {
        $house = $q->field($i, 'house');
        $out = _api_getPerson_row($q->row($i), $house == HOUSE_TYPE_ROYAL ? false : true);
        $output[] = $out;
        $time = strtotime($q->field($i, 'lastupdate'));
        if ($time > $last_mod) {
            $last_mod = $time;
        }
    }
    api_output($output, $last_mod);
}
예제 #2
0
function _api_getMP_constituency($constituency) {
	$db = new ParlDB;

	if ($constituency == '')
		return false;

	if ($constituency == 'Orkney ')
		$constituency = 'Orkney &amp; Shetland';

	$normalised = normalise_constituency_name($constituency);
	if ($normalised) $constituency = $normalised;

	$q = $db->query("SELECT * FROM member
		WHERE constituency = '" . mysql_real_escape_string($constituency) . "'
		AND left_reason = 'still_in_office' AND house=1");
	if ($q->rows > 0)
		return _api_getPerson_row($q->row(0), true);

	if (get_http_var('always_return')) {
		$q = $db->query("SELECT * FROM member
			WHERE house=1 AND constituency = '".mysql_real_escape_string($constituency)."'
			ORDER BY left_house DESC LIMIT 1");
		if ($q->rows > 0)
			return _api_getPerson_row($q->row(0), true);
	}
	
	return false;
}
예제 #3
0
function _api_getMP_constituency($constituency)
{
    $db = new ParlDB();
    $out = null;
    if ($constituency == '') {
        return false;
    }
    if ($constituency == 'Orkney ') {
        $constituency = 'Orkney &amp; Shetland';
    }
    $normalised = MySociety\TheyWorkForYou\Utility\Constituencies::normaliseConstituencyName($constituency);
    if ($normalised) {
        $constituency = $normalised;
    }
    $q = $db->query("SELECT member.*, p.title, p.given_name, p.family_name, p.lordofname\n        FROM member, person_names p\n        WHERE constituency = :constituency\n            AND member.person_id = p.person_id AND p.type = 'name'\n            AND p.start_date <= left_house and left_house <= p.end_date\n        AND left_reason = 'still_in_office' AND house=:house", array(':house' => HOUSE_TYPE_COMMONS, ':constituency' => $constituency));
    if ($q->rows > 0) {
        $out = _api_getPerson_row($q->row(0), true);
    }
    if (!$out && get_http_var('always_return')) {
        $q = $db->query("SELECT member.*, p.title, p.given_name, p.family_name, p.lordofname\n            FROM member, person_names p\n            WHERE house=:house AND constituency = :constituency\n                AND member.person_id = p.person_id AND p.type = 'name'\n                AND p.start_date <= left_house and left_house <= p.end_date\n            ORDER BY left_house DESC LIMIT 1", array(':house' => HOUSE_TYPE_COMMONS, ':constituency' => $constituency));
        if ($q->rows > 0) {
            $out = _api_getPerson_row($q->row(0), true);
        }
    }
    if ($out) {
        api_output($out, isset($out['lastupdate']) ? strtotime($out['lastupdate']) : null);
        return true;
    }
    return false;
}
예제 #4
0
function _api_getRoyal_row($row)
{
    return _api_getPerson_row($row, $has_party = FALSE);
}