Esempio n. 1
0
    $args['sort'] = "regexp_replace";
    $GLOSSARY = new GLOSSARY($args);
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
}
// Check that people aren't trying to define silly words
if (in_array(strtolower($GLOSSARY->query), $GLOSSARY->stopwords)) {
    $GLOSSARY->query = "";
    $args['blankform'] = 1;
    $URL = new URL('help_us_out');
    $backlink = $URL->generate();
    $error_message = "Sorry, that phrase appears too many times to be a useful as a link within the parliamentary record.";
}
// do a quick searchengine count
if ($GLOSSARY->query != "") {
    $SEARCHENGINE = new SEARCHENGINE('"' . $args['s'] . '"');
    $args['count'] = $SEARCHENGINE->run_count();
    if (!$args['count']) {
        $GLOSSARY->query = "";
        $args['blankform'] = 1;
        $error_message = "Unfortunately <strong>" . $args['s'] . "</strong>, doesn't seem to appear in hansard at all...</p>";
    }
}
$PAGE->page_start();
$PAGE->stripe_start();
$data = array('title' => get_http_var('g'), 'body' => get_http_var('definition'));
// For previewing and adding a Glossary term.
// We should have post args of 'body' and 'term'.
if (get_http_var("submitterm") != '') {
    // We're submitting a comment.
    $success = $GLOSSARY->create($data);
    if ($success) {
function search_by_usage($search, $house = 0)
{
    $data = array();
    $SEARCHENGINE = new SEARCHENGINE($search);
    $data['pagetitle'] = $SEARCHENGINE->query_description_short();
    $SEARCHENGINE = new SEARCHENGINE($search . ' groupby:speech');
    $count = $SEARCHENGINE->run_count(0, 5000, 'date');
    if ($count <= 0) {
        $data['error'] = 'No results';
        return $data;
    }
    $SEARCHENGINE->run_search(0, 5000, 'date');
    $gids = $SEARCHENGINE->get_gids();
    if (count($gids) <= 0) {
        $data['error'] = 'No results';
        return $data;
    }
    if (count($gids) == 5000) {
        $data['limit_reached'] = true;
    }
    # Fetch all the speakers of the results, count them up and get min/max date usage
    $speaker_count = array();
    $gids = join('","', $gids);
    $db = new ParlDB();
    $q = $db->query('SELECT gid,person_id,hdate FROM hansard WHERE gid IN ("' . $gids . '")');
    for ($n = 0; $n < $q->rows(); $n++) {
        $gid = $q->field($n, 'gid');
        $person_id = $q->field($n, 'person_id');
        $hdate = $q->field($n, 'hdate');
        if (!isset($speaker_count[$person_id])) {
            $speaker_count[$person_id] = 0;
            $maxdate[$person_id] = '1001-01-01';
            $mindate[$person_id] = '9999-12-31';
        }
        $speaker_count[$person_id]++;
        if ($hdate < $mindate[$person_id]) {
            $mindate[$person_id] = $hdate;
        }
        if ($hdate > $maxdate[$person_id]) {
            $maxdate[$person_id] = $hdate;
        }
    }
    # Fetch details of all the speakers
    $speakers = array();
    $pids = array();
    if (count($speaker_count)) {
        $person_ids = join(',', array_keys($speaker_count));
        $q = $db->query('SELECT member_id, member.person_id, title, given_name, family_name, lordofname,
                                constituency, house, party,
                                moffice_id, dept, position, from_date, to_date, left_house
                            FROM member LEFT JOIN moffice ON member.person_id = moffice.person
                                JOIN person_names pn ON member.person_id = pn.person_id AND pn.type="name" AND pn.start_date <= left_house AND left_house <= pn.end_date
                            WHERE member.person_id IN (' . $person_ids . ')
                            ' . ($house ? " AND house={$house}" : '') . '
                            ORDER BY left_house DESC');
        for ($n = 0; $n < $q->rows(); $n++) {
            $mid = $q->field($n, 'member_id');
            if (!isset($pids[$mid])) {
                $title = $q->field($n, 'title');
                $first = $q->field($n, 'given_name');
                $last = $q->field($n, 'family_name');
                $lordofname = $q->field($n, 'lordofname');
                $house = $q->field($n, 'house');
                $party = $q->field($n, 'party');
                $full_name = ucfirst(member_full_name($house, $title, $first, $last, $lordofname));
                $pid = $q->field($n, 'person_id');
                $pids[$mid] = $pid;
                $speakers[$pid]['house'] = $house;
                $speakers[$pid]['left'] = $q->field($n, 'left_house');
            }
            $dept = $q->field($n, 'dept');
            $posn = $q->field($n, 'position');
            $moffice_id = $q->field($n, 'moffice_id');
            if ($dept && $q->field($n, 'to_date') == '9999-12-31') {
                $speakers[$pid]['office'][$moffice_id] = prettify_office($posn, $dept);
            }
            if (!isset($speakers[$pid]['name'])) {
                $speakers[$pid]['name'] = $full_name . ($house == 1 ? ' MP' : '');
                $speakers[$pid]['party'] = $party;
            }
        }
    }
    if (isset($speaker_count[0])) {
        $speakers[0] = array('party' => '', 'name' => 'Headings, procedural text, etc.', 'house' => 0, 'count' => 0);
    }
    $party_count = array();
    $ok = 0;
    foreach ($speakers as $pid => &$speaker) {
        $speaker['count'] = $speaker_count[$pid];
        $speaker['pmaxdate'] = $maxdate[$pid];
        $speaker['pmindate'] = $mindate[$pid];
        $ok = 1;
        if (!isset($party_count[$speaker['party']])) {
            $party_count[$speaker['party']] = 0;
        }
        $party_count[$speaker['party']] += $count;
    }
    function sort_by_count($a, $b)
    {
        if ($a['count'] > $b['count']) {
            return -1;
        }
        if ($a['count'] < $b['count']) {
            return 1;
        }
        return 0;
    }
    uasort($speakers, 'sort_by_count');
    arsort($party_count);
    if (!$ok) {
        $data['error'] = 'No results';
        return $data;
    }
    $data['party_count'] = $party_count;
    $data['speakers'] = $speakers;
    return $data;
}
Esempio n. 3
0
    $args['sort'] = "regexp_replace";
    $GLOSSARY = new GLOSSARY($args);
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
}
// Check that people aren't trying to define silly words
if (in_array(strtolower($GLOSSARY->query), $GLOSSARY->stopwords)) {
    $GLOSSARY->query = "";
    $args['blankform'] = 1;
    $URL = new URL('help_us_out');
    $backlink = $URL->generate();
    $error_message = "Sorry, that phrase appears too many times to be a useful as a link within the parliamentary record.";
}
// do a quick searchengine count
if ($GLOSSARY->query != "") {
    $SEARCHENGINE = new SEARCHENGINE('"' . $args['s'] . '"');
    $args['count'] = $SEARCHENGINE->run_count(0, 10000);
    if (!$args['count']) {
        $GLOSSARY->query = "";
        $args['blankform'] = 1;
        $error_message = "Unfortunately <strong>" . $args['s'] . "</strong>, doesn't seem to appear in hansard at all...</p>";
    }
}
$PAGE->page_start();
$PAGE->stripe_start();
$data = array('title' => get_http_var('g'), 'body' => get_http_var('definition'));
// For previewing and adding a Glossary term.
// We should have post args of 'body' and 'term'.
if (get_http_var("submitterm") != '') {
    // We're submitting a comment.
    $success = $GLOSSARY->create($data);
    if ($success) {