4 SGN::Controller::AJAX::People - a REST controller class to provide the
5 backend for the sgn_people schema
9 REST interface for searching people, getting user data, etc.
13 Naama Menda <nm249@cornell.edu>
18 package SGN
::Controller
::AJAX
::People
;
23 use List
::MoreUtils qw
/any /;
25 use CXGN
::People
::Schema
;
28 BEGIN { extends
'Catalyst::Controller::REST' }
31 default => 'application/json',
33 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
40 Public Path: /ajax/people/autocomplete
42 Autocomplete a person name. Takes a single GET param,
43 C<person>, responds with a JSON array of completions for that term.
47 sub autocomplete
: Local
: ActionClass
('REST') { }
49 sub autocomplete_GET
:Args
(1) {
50 my ( $self, $c , $print_id ) = @_;
52 my $person = $c->req->param('term');
53 # trim and regularize whitespace
54 $person =~ s/(^\s+|\s+)$//g;
56 my $q = "SELECT sp_person_id, first_name, last_name FROM sgn_people.sp_person
57 WHERE lower(first_name) like ? OR lower(last_name) like ?
60 my $sth = $c->dbc->dbh->prepare($q);
61 $sth->execute( lc "$person\%" , lc "$person\%" );
63 while (my ($sp_person_id, $first_name, $last_name) = $sth->fetchrow_array ) {
64 $sp_person_id = $print_id ?
"," . $sp_person_id : undef;
65 push @results , "$first_name, $last_name $sp_person_id";
67 $c->{stash
}->{rest
} = \
@results;