Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / lib / SGN / Controller / People.pm
blob2354d9aa86f0b53af9ddbd5961f3776c4fb708a6
2 package SGN::Controller::People;
4 use Moose;
6 use URI::FromHash 'uri';
7 use CXGN::Login;
8 use CXGN::People::Person;
9 use Data::Dumper;
10 use CXGN::Phenome::Population;
11 use SGN::Controller::solGS::AnalysisQueue;
12 use CXGN::Page::FormattingHelpers qw/info_section_html page_title_html info_table_html simple_selectbox_html html_optional_show columnar_table_html/;
13 use CXGN::Phenome::Locus;
15 BEGIN { extends 'Catalyst::Controller' };
17 sub people_search : Path('/search/people') Args(0) {
18 my $self = shift;
19 my $c = shift;
20 $c->stash->{template} = '/search/people.mas';
25 #Code migrated from /cgi-bin/solpeople/top-level.pl
26 sub people_top_level : Path('/solpeople/profile') Args(1) {
27 my $self = shift;
28 my $c = shift;
29 my $person_id = shift;
30 my $dbh = $c->dbc->dbh;
32 #will redirect user to login page if they are not logged in.
33 my $user_id=CXGN::Login->new($dbh)->verify_session();
34 if (!$user_id) {
36 $c->res->redirect(uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
37 $c->detach();
39 my $users_profile;
40 if ($person_id == $user_id) {
41 $users_profile = 1;
43 my @roles = $c->user->get_roles;
44 my %roles_hash;
45 foreach (@roles) {
46 $roles_hash{$_} = 1;
49 my $p = CXGN::People::Person->new($dbh, $person_id);
50 my $user_type = $p->get_user_type;
52 if ($users_profile) {
54 # User's populations sections
55 my @pops = CXGN::Phenome::Population->my_populations($person_id);
56 my $pops_list;
57 foreach my $pop (@pops) {
58 my $pop_name = $pop->get_name();
59 my $pop_id = $pop->get_population_id();
60 my $is_public = $pop->get_privacy_status();
61 if ($is_public) { $is_public = 'is publicly available'; }
62 if ( !$is_public ) { $is_public = 'is not publicly available yet'; }
63 $pops_list .= qq |<a href="/qtl/population/$pop_id">$pop_name</a> <i>($is_public)</i><br/>|;
65 if (!$pops_list) {
66 $pops_list = '<h4>You have no populations.</h4>';
68 $c->stash->{populations_list} = $pops_list;
70 #User Loci section
71 my @loci = CXGN::Phenome::Locus::get_locus_ids_by_editor( $dbh, $person_id );
72 my $top = 50;
73 my $more = 0;
74 my $max = @loci;
75 if ( @loci > 24 ) {
76 $more = @loci - 24;
77 $max = 24;
79 my $locus_editor_info = "<h4>You have no loci to edit.</h4>";
80 if ( @loci > 0 ) {
81 $locus_editor_info = "";
83 for ( my $i = 0 ; $i < ($max) ; $i++ ) {
84 my $locus = CXGN::Phenome::Locus->new( $dbh, $loci[$i] );
85 my $symbol = $locus->get_locus_symbol();
86 my $locus_id = $locus->get_locus_id();
87 $locus_editor_info .= qq { <a href="/phenome/locus_display.pl?locus_id=$locus_id&amp;action=view">$symbol</a> };
89 if ($more) {
90 $locus_editor_info .= qq|<br><b>and <a href="/search/locus/>$more more</a></b><br />|;
92 $c->stash->{loci_editor_privileges} = $locus_editor_info;
94 my @annotated_loci = CXGN::Phenome::Locus::get_locus_ids_by_annotator( $dbh, $person_id );
95 $more = 0;
96 $max = @annotated_loci;
97 if ( @annotated_loci > 24 ) {
98 $more = @annotated_loci - 24;
99 $max = 24;
101 my ( $locus_annotations, $more_annotations );
102 for ( my $i = 0 ; $i < $top ; $i++ ) {
103 my $locus = CXGN::Phenome::Locus->new( $dbh, $annotated_loci[$i] );
104 my $symbol = $locus->get_locus_symbol() ? $locus->get_locus_symbol() : '';
105 my $locus_id = $locus->get_locus_id() ? $locus->get_locus_id() : '';
107 if ( $i < $max ) {
108 $locus_annotations .= qq | <a href="/locus/$locus_id/view">$symbol</a> |;
109 } else {
110 $more_annotations .= qq { <a href="/locus/$locus_id/view">$symbol</a> };
113 if ($more) {
114 $locus_annotations .= " and $more more, not shown.<br />";
116 $locus_annotations .= html_optional_show( 'locus_annotations', 'Show more', qq|<div class="minorbox">$more_annotations</div> | );
118 $locus_annotations .= qq| <a href="../phenome/recent_annotated_loci.pl">[View annotated loci by date]</a> |;
119 $c->stash->{loci_annotations} = $locus_annotations;
121 #User status section
122 my $user_info = {
123 user => qq{ Your current user status is <b>$user_type</b>. Please contact <a href="mailto:sgn-feedback\@sgn.cornell.edu">SGN</a> to upgrade to a <b>submitter</b> account with more privileges. Submitters can upload user maps, EST data, and become locus editors. },
124 submitter => qq{ Your current user status is <b>$user_type</b>. You have the maximum user privileges on SGN. Please contact <a href="mailto:sgn-feedback\@sgn.cornell.edu">SGN</a> if you would like to change your user status.},
125 curator => qq{ Your current user status is <b>$user_type</b>. },
126 sequencer => qq{ Your current user status is <b>$user_type</b>. You have maximum user privileges on SGN. },
127 genefamily_editor => qq{ Your current user status is <b>$user_type</b>. },
129 $c->stash->{user_status} = $user_info->{$user_type};
132 $c->stash->{site_name} = $c->config->{project_name};
133 $c->stash->{user_roles} = \%roles_hash;
134 $c->stash->{sp_person_id} = $p->get_sp_person_id;
135 $c->stash->{username} = $c->user->get_object->get_username;
136 $c->stash->{first_name} = $p->get_first_name;
137 $c->stash->{last_name} = $p->get_last_name;
138 $c->stash->{is_users_profile} = $users_profile;
139 $c->stash->{template} = '/people/profile.mas';