예제 #1
0
 /**
  * Test looking up a person by full name works as expected.
  */
 public function testSearchMemberDbLookupFullName()
 {
     // Test a full name.
     $results = search_member_db_lookup('Mary Smith');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
     // Test an inverse full name.
     $results = search_member_db_lookup('Smith Mary');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
     // Test a name with title.
     $results = search_member_db_lookup('Mrs Smith');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
 }
예제 #2
0
 private function parse_person_params()
 {
     $searchstring = '';
     # Searching from MP pages
     if ($searchspeaker = trim(get_http_var('pid'))) {
         $searchstring .= " speaker:{$searchspeaker}";
     }
     # Searching from MP pages
     if ($searchspeaker = trim(get_http_var('person'))) {
         $q = search_member_db_lookup($searchspeaker);
         $pids = array();
         $row_count = $q->rows();
         for ($i = 0; $i < $row_count; $i++) {
             $pids[$q->field($i, 'person_id')] = true;
         }
         $pids = array_keys($pids);
         if (count($pids) > 0) {
             $searchstring .= ' speaker:' . join(' speaker:', $pids);
         }
     }
     return $searchstring;
 }
예제 #3
0
function search_member_db_lookup_with_names($searchstring, $current_only = false)
{
    $q = search_member_db_lookup($searchstring, $current_only);
    if (!$q->rows) {
        return $q;
    }
    $person_ids = array();
    for ($i = 0; $i < $q->rows(); ++$i) {
        $pid = $q->field($i, 'person_id');
        $person_ids[$pid] = 1;
    }
    $pids = array_keys($person_ids);
    $pids_str = join(',', $pids);
    $where = '';
    if ($current_only) {
        $where = "AND left_house='9999-12-31'";
    }
    # This is not totally accurate (e.g. minimum entered date may be from a
    # different house, or similar), but should be good enough.
    $db = new ParlDB();
    $q = $db->query("SELECT member.person_id,\n                            title, given_name, family_name, lordofname,\n                            constituency, party,\n                            (SELECT MIN(entered_house) FROM member m WHERE m.person_id=member.person_id) min_entered_house,\n                            left_house, house\n                    FROM member, person_names pn\n                    WHERE member.person_id IN ({$pids_str}) {$where}\n                        AND member.person_id = pn.person_id AND pn.type = 'name'\n                        AND pn.start_date <= member.left_house AND member.left_house <= pn.end_date\n                        AND left_house = (SELECT MAX(left_house) FROM member m WHERE m.person_id=member.person_id)\n                    GROUP BY person_id\n                    ORDER BY family_name, lordofname, given_name, person_id");
    return $q;
}
예제 #4
0
 private function find_members()
 {
     $searchstring = trim(preg_replace('#-?[a-z]+:[a-z0-9]+#', '', $this->searchstring));
     $q = search_member_db_lookup($searchstring);
     if (!$q) {
         return array();
     }
     $members = array();
     if ($q->rows() > 0) {
         $row_count = $q->rows();
         for ($n = 0; $n < $row_count; $n++) {
             $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $q->field($n, 'person_id')));
             // search_member_db_lookup returns dups so we
             // key by person_id to work round this
             $members[$member->person_id] = $member;
         }
     }
     return $members;
 }
예제 #5
0
function construct_search_string() {
    $searchstring = trim(get_http_var('s'));

    # Stuff from advanced search form
    if ($advphrase = get_http_var('phrase')) {
        $searchstring .= ' "' . $advphrase . '"';
    }

    if ($advexclude = get_http_var('exclude')) {
        $searchstring .= ' -' . join(' -', preg_split('/\s+/', $advexclude));
    }

    if (get_http_var('from') || get_http_var('to')) {
        $from = parse_date(get_http_var('from'));
        if ($from) $from = $from['iso'];
        else $from = '1935-10-01';
        $to = parse_date(get_http_var('to'));
        if ($to) $to = $to['iso'];
        else $to = date('Y-m-d');
        $searchstring .= " $from..$to";
    }

    if ($advdept = get_http_var('department')) {
        $searchstring .= ' department:' . preg_replace('#[^a-z]#i', '', $advdept);
    }

    if ($advparty = get_http_var('party')) {
        $searchstring .= ' party:' . join(' party:', explode(',', $advparty));
    }

    if ($column = trim(get_http_var('column'))) {
        if (preg_match('#^(\d+)W$#', $column, $m)) {
            $searchstring .= " column:$m[1] section:wrans";
        } elseif (preg_match('#^(\d+)WH$#', $column, $m)) {
            $searchstring .= " column:$m[1] section:whall";
        } elseif (preg_match('#^(\d+)WS$#', $column, $m)) {
            $searchstring .= " column:$m[1] section:wms";
        } elseif (preg_match('#^\d+$#', $column)) {
            $searchstring .= " column:$column";
        }
    }

    $advsection = get_http_var('section');
    if (!$advsection)
        $advsection = get_http_var('maj'); # Old URLs had this
    if (is_array($advsection)) {
        $searchstring .= ' section:' . join(' section:', $advsection);
    } elseif ($advsection) {
        $searchstring .= " section:$advsection";
    }

    if ($searchgroupby = trim(get_http_var('groupby'))) {
        $searchstring .= " groupby:$searchgroupby";
    }

    # Searching from MP pages
	if ($searchspeaker = trim(get_http_var('pid'))) {
		$searchstring .= " speaker:$searchspeaker";
    }

    # Searching from MP pages
	if ($searchspeaker = trim(get_http_var('person'))) {
        $q = search_member_db_lookup($searchspeaker);
        $pids = array();
        for ($i=0; $i<$q->rows(); $i++) {
            $pids[$q->field($i, 'person_id')] = true;
        }
        $pids = array_keys($pids);
        if ($pids)
            $searchstring .= ' speaker:' . join(' speaker:', $pids);
    }

    return trim($searchstring);
}
예제 #6
0
function construct_search_string()
{
    // If q has a value (other than the default empty string) use that over s.
    if (get_http_var('q') != '') {
        $search_main = trim(get_http_var('q'));
    } else {
        $search_main = trim(get_http_var('s'));
    }
    $searchstring = '';
    # Stuff from advanced search form
    if ($advphrase = get_http_var('phrase')) {
        $searchstring .= ' "' . $advphrase . '"';
    }
    if ($advexclude = get_http_var('exclude')) {
        $searchstring .= ' -' . join(' -', preg_split('/\\s+/', $advexclude));
    }
    if (get_http_var('from') || get_http_var('to')) {
        $from = parse_date(get_http_var('from'));
        if ($from) {
            $from = $from['iso'];
        } else {
            $from = '1935-10-01';
        }
        $to = parse_date(get_http_var('to'));
        if ($to) {
            $to = $to['iso'];
        } else {
            $to = date('Y-m-d');
        }
        $searchstring .= " {$from}..{$to}";
    }
    if ($advdept = get_http_var('department')) {
        $searchstring .= ' department:' . preg_replace('#[^a-z]#i', '', $advdept);
    }
    if ($advparty = get_http_var('party')) {
        $searchstring .= ' party:' . join(' party:', explode(',', $advparty));
    }
    if ($column = trim(get_http_var('column'))) {
        if (preg_match('#^(\\d+)W$#', $column, $m)) {
            $searchstring .= " column:{$m['1']} section:wrans";
        } elseif (preg_match('#^(\\d+)WH$#', $column, $m)) {
            $searchstring .= " column:{$m['1']} section:whall";
        } elseif (preg_match('#^(\\d+)WS$#', $column, $m)) {
            $searchstring .= " column:{$m['1']} section:wms";
        } elseif (preg_match('#^\\d+$#', $column)) {
            $searchstring .= " column:{$column}";
        }
    }
    $advsection = get_http_var('section');
    if (!$advsection) {
        $advsection = get_http_var('maj');
    }
    # Old URLs had this
    if (is_array($advsection)) {
        $searchstring .= ' section:' . join(' section:', $advsection);
    } elseif ($advsection) {
        $searchstring .= " section:{$advsection}";
    }
    if ($searchgroupby = trim(get_http_var('groupby'))) {
        $searchstring .= " groupby:{$searchgroupby}";
    }
    # Searching from MP pages
    if ($searchspeaker = trim(get_http_var('pid'))) {
        $searchstring .= " speaker:{$searchspeaker}";
    }
    # Searching from MP pages
    if ($searchspeaker = trim(get_http_var('person'))) {
        $q = search_member_db_lookup($searchspeaker);
        $pids = array();
        for ($i = 0; $i < $q->rows(); $i++) {
            $pids[$q->field($i, 'person_id')] = true;
        }
        $pids = array_keys($pids);
        if ($pids) {
            $searchstring .= ' speaker:' . join(' speaker:', $pids);
        }
    }
    $searchstring = trim($searchstring);
    if ($search_main && $searchstring) {
        if (strpos($search_main, 'OR') !== false) {
            $search_main = "({$search_main})";
        }
        $searchstring = "{$search_main} {$searchstring}";
    } elseif ($search_main) {
        $searchstring = $search_main;
    }
    $searchstring_conv = @iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $searchstring);
    if (!$searchstring_conv) {
        $searchstring_conv = @iconv('Windows-1252', 'ISO-8859-1//TRANSLIT', $searchstring);
    }
    if ($searchstring_conv) {
        $searchstring = $searchstring_conv;
    }
    return $searchstring;
}
예제 #7
0
} elseif ($alert) {
    $details['email'] = $alert['email'];
    $details['email_verified'] = true;
} else {
    $details["email"] = trim(get_http_var("email"));
    $details['email_verified'] = false;
}
$details['keyword'] = trim(get_http_var("keyword"));
$details['pid'] = trim(get_http_var("pid"));
$details['alertsearch'] = trim(get_http_var("alertsearch"));
$details['pc'] = get_http_var('pc');
$details['submitted'] = get_http_var('submitted') || $details['pid'] || $details['keyword'];
$errors = check_input($details);
// Do the search
if ($details['alertsearch']) {
    $details['members'] = search_member_db_lookup($details['alertsearch'], true);
    list($details['constituencies'], $details['valid_postcode']) = search_constituencies_by_query($details['alertsearch']);
}
# If the above search returned one result for member or constituency search,
# use it immediately
if (isset($details['members']) && $details['members']->rows() == 1) {
    $details['pid'] = $details['members']->field(0, 'person_id');
    unset($details['members']);
    $details['alertsearch'] = '';
}
if (isset($details['constituencies']) && count($details['constituencies']) == 1 && $details['valid_postcode']) {
    $MEMBER = new MEMBER(array('constituency' => $details['constituencies'][0], 'house' => 1));
    $details['pid'] = $MEMBER->person_id();
    $details['pc'] = $details['alertsearch'];
    unset($details['constituencies']);
    $details['alertsearch'] = '';