Merge pull request #42 from solgenomics/topic/duplicate_image_warning
[cxgn-corelibs.git] / lib / CXGN / Publication.pm
blob33ed30fd1dbc4a670e0baf06f4bcef621670811a
1 use strict;
3 ####################
5 package CXGN::Publication;
6 use base qw/CXGN::Search::DBI::Simple CXGN::Search::WWWSearch/;
8 __PACKAGE__->creates_result('CXGN::Publication::Result');
9 __PACKAGE__->uses_query('CXGN::Publication::Query');
11 #####################
13 package CXGN::Publication::Result;
14 use base qw/CXGN::Search::BasicResult/;
16 #####################
18 package CXGN::Publication::Query;
19 use CXGN::Page::FormattingHelpers
20 qw(
21 simple_selectbox_html
22 info_table_html
23 hierarchical_selectboxes_html
24 conditional_like_input_html
25 html_optional_show
28 use base qw/CXGN::Search::DBI::Simple::WWWQuery/;
29 our %pname;
31 sub _cached_dbh() { our $_cached_dbc ||= CXGN::DB::Connection->new('public') }
32 my $public = 'public';
33 my $sgn_people= 'sgn_people';
34 my $phenome= 'phenome';
35 __PACKAGE__->selects_data("$public.pub.pub_id","$public.pub.title","$public.pub.series_name", "$public.pub.pyear","$phenome.pub_curator.assigned_to","$phenome.pub_curator.date_curated", "$phenome.pub_curator.curated_by", "$phenome.pub_curator.status", "$phenome.pub_curator.date_stored" );
38 __PACKAGE__->join_root("$public.pub");
40 __PACKAGE__->uses_joinpath('authorpath',
41 ["$public.pubauthor", "$public.pubauthor.pub_id = $public.pub.pub_id"],
44 __PACKAGE__->uses_joinpath('curatorpath',
45 [ "$phenome.pub_curator", "$phenome.pub_curator.pub_id=$public.pub.pub_id" ],
46 [ "$sgn_people.sp_person", "$phenome.pub_curator.assigned_to = $sgn_people.sp_person.sp_person_id" ],
50 __PACKAGE__->has_parameter(name =>'author',
51 columns=>["$public.pubauthor.surname",
52 "$public.pubauthor.givennames"],
53 sqlexpr=>"$public.pubauthor.surname || $public.pubauthor.givennames",
56 __PACKAGE__->has_parameter(name =>'title',
57 columns=>"$public.pub.title",
59 __PACKAGE__->has_parameter(name =>'pyear',
60 columns=>"$public.pub.pyear",
62 __PACKAGE__->has_parameter(name =>'series',
63 columns=>"$public.pub.series_name",
66 __PACKAGE__->has_parameter(name =>'assigned_to',
67 columns=>["$sgn_people.sp_person.first_name",
68 "$sgn_people.sp_person.last_name",
69 "$sgn_people.sp_person.sp_person_id"],
70 sqlexpr=>"$sgn_people.sp_person.last_name || $sgn_people.sp_person.first_name
71 || $sgn_people.sp_person.sp_person_id",
74 __PACKAGE__->has_parameter(name =>'status',
75 columns=>"$phenome.pub_curator.status",
77 __PACKAGE__->has_parameter(name =>'is_curated',
78 columns=>"$phenome.pub_curator.curated_by",
79 #sqlexpr=>"(count pub_curator.curated_by)",
80 # group =>1,
81 # aggregate=>1,
83 __PACKAGE__->has_parameter(name =>'date_stored',
84 columns=>["$phenome.pub_curator.date_stored"],
88 __PACKAGE__->has_complex_parameter( name => 'any_name',
89 uses => [qw/ title series /],
90 setter => sub {
91 my ($self, @args) = @_;
92 $self->title(@args);
93 $self->series(@args);
95 $self->compound('&t OR &t' ,'title', 'series');
99 ###### NOW WWW STUFF ###
101 sub request_to_params {
102 my($self, %params) = @_;
104 #sanitize all the parameters
105 foreach my $key (keys %params) {
106 if( $params{$key} ) {
107 $params{$key} =~ s/[;\'\",]//g;
111 if($params{any_name}) {
112 $self->any_name('ILIKE ?',"%$params{any_name}%");
115 #if ($params{editor} =~ m/^\d/) {
116 # $self->editor('= ?', "$params{editor}");
117 if ($params{assigned_to}) {
118 $self->assigned_to('ILIKE ?', "%$params{assigned_to}%");
121 if ($params{is_curated}) {
122 $self->is_curated('IS NOT NULL');
125 if ($params{author}) {
126 $self->author('ILIKE ?', "%$params{author}%");
128 if ($params{date_stored}) {
129 $self->date_stored('> ?', "$params{date_stored}");
131 if($params{status}) {
132 $self->status('ILIKE ?', "$params{status}");
135 #page number
136 if( defined($params{page}) ) {
137 $self->page($params{page});
141 sub _to_scalars {
142 my $self= shift;
143 my $search= shift;
144 my %params;
146 no warnings 'uninitialized';
148 #this part defines the mapping from get/post data to search params
150 ($params{any_name}) = $self->param_bindvalues('any_name');
151 $params{any_name} =~ s/%//g;
153 ($params{author}) = $self->param_bindvalues('author');
154 $params{author} =~ s/%//g;
156 ($params{assigned_to}) = $self->param_bindvalues('assigned_to');
157 $params{assigned_to} =~ s/%//g;
159 ($params{date_stored}) = $self->param_bindvalues('date_stored');
160 $params{date_stored} =~ s/%//g;
162 ($params{status}) = $self->param_bindvalues('status');
164 $params{is_curated} = $self->pattern_match_parameter('is_curated', /IS NOT NULL/);
166 return %params;
169 sub to_html {
170 my $self = shift;
171 my $search = 'advanced';
172 my %scalars = $self->_to_scalars($search);
174 #make %pname, a tied hash that uniqifies names the make_pname
175 # function is in CXGN::Page::WebForm, which is a parent of
176 # CXGN::Search::DBI::Simple::WWWQuery
177 $self->make_pname;
178 our %pname;
180 my $dbh=_cached_dbh();
182 my @stat_list= ("", "pending", "curated", "rejected", "no gene");
183 my $stats = simple_selectbox_html( choices => \@stat_list,
184 name => $pname{status},
185 selected => $scalars{status},
188 my $is_curated= $self->uniqify_name('is_curated');
189 my $any_name = $self->uniqify_name('any_name');
190 my $author = $self->uniqify_name('author');
191 my $assigned_to = $self->uniqify_name('assigned_to');
192 my $date_stored = $self->uniqify_name('date_stored');
195 #check boxes
196 @scalars{qw/ is_curated is_assigned /} =
197 map {$_ ? 'checked="checked" ' : undef} @scalars{qw/ is_curated is_assigned /};
199 my $a_search=
200 info_table_html(
201 'Title'=>qq|<input name="$pname{any_name}" value="$scalars{any_name}" size="60" />|,
202 __border =>0,) .
203 info_table_html (
204 'Author' => qq|<input name = "$pname{author}" value="$scalars{author}" size="20" />|,
205 'Date stored' =>qq|<input name="$pname{date_stored}" value="$scalars{date_stored}" size="10"/>|,
206 'SGN curator'=> qq|<input name="$pname{assigned_to}" value="$scalars{assigned_to}" size="20" />|,
207 'Status' => $stats,
208 'Curated' => qq|<input type="checkbox" name="$is_curated" $scalars{is_curated} /><br />|,
209 __border =>0,
210 __multicol =>2,
211 __tableattrs => 'width="100%"',
214 #$scalars{is_curated} ||= '';
216 my $html_ret = <<EOHTML;
217 <table><tr></tr>
218 <tr><td>$a_search</td></tr>
219 <tr><td><a href="/chado/publication.pl?action=new">[Submit new publication]</a> </td>
220 </tr></table>
221 <br />
222 <div align="center"><input type="submit" value="Search"/></div>
223 EOHTML
226 sub quick_search {
227 my ($self,$term) = @_;
228 $self->any_name('ILIKE ?', "%$term%");
229 return $self;
233 1;#do not remove