add function for retrieving treatment info by observation unit ids
[sgn.git] / lib / SGN / Controller / BreedingProgram.pm
blob5906e54c8a247126cfeee1685cb81dd9ff06e50e
1 =head1 NAME
3 SGN::Controller::BreedingProgram - Catalyst controller for the Breeding Program page
6 =cut
8 package SGN::Controller::BreedingProgram;
10 use Moose;
12 use Data::Dumper;
13 use CXGN::BreedingProgram ; # the BP object
14 use SGN::Model::Cvterm; # maybe need this for the projectprop.type_id breeding_program
15 use URI::FromHash 'uri';
16 use JSON;
18 ##use CXGN::People::Roles;
21 BEGIN { extends 'Catalyst::Controller' }
22 with 'Catalyst::Component::ApplicationAttribute';
24 has 'schema' => (
25 is => 'rw',
26 isa => 'DBIx::Class::Schema',
27 lazy_build => 1,
29 sub _build_schema {
30 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
33 sub get_breeding_program : Chained('/') PathPart('breeders/program') CaptureArgs(1) {
34 my ($self, $c, $program_id) = @_;
36 my $schema = $self->schema;
38 my $program;
39 eval {
40 $program = CXGN::BreedingProgram->new( { schema=> $schema , program_id => $program_id } );
42 if ($@) {
43 $c->stash->{template} = 'system_message.txt';
44 $c->stash->{message} = "The requested breeding program ($program_id) does not exist";
45 return;
47 $c->stash->{user} = $c->user();
48 $c->stash->{program} = $program;
52 sub program_info : Chained('get_breeding_program') PathPart('') Args(0) {
53 my $self = shift;
54 my $c = shift;
55 #my $user = $c->user();
57 #$c->stash->{user_can_modify} = ($user->check_roles("submitter") || $user->check_roles("curator")) ;
59 my $program = $c->stash->{program};
61 if (!$program) {
62 $c->stash->{message} = "The requested breeding program does not exist or has been deleted.";
63 $c->stash->{template} = 'generic_message.mas';
64 return;
66 $c->stash->{template} = '/breeders_toolbox/breeding_program.mas';
71 sub profile_detail : Path('/profile') Args(1) {
72 my $self = shift;
73 my $c = shift;
74 my $profile_id = shift;
75 my $schema = $self->schema;
76 my $profile_json_type_id = SGN::Model::Cvterm->get_cvterm_row($c->dbic_schema("Bio::Chado::Schema"), 'product_profile_json', 'project_property')->cvterm_id();
77 my $profile_rs = $schema->resultset("Project::Projectprop")->search({ projectprop_id => $profile_id, type_id => $profile_json_type_id });
79 if (!$profile_rs) {
80 $c->stash->{message} = 'The requested profile does not exist.';
83 my $profile_row = $profile_rs->next();
84 my $profile_detail_string = $profile_row->value();
86 my $profile_detail_hash = decode_json $profile_detail_string;
87 my $profile_name = $profile_detail_hash->{'product_profile_name'};
89 $c->stash->{profile_name} = $profile_name;
90 $c->stash->{user_id} = $c->user ? $c->user->get_object()->get_sp_person_id() : undef;
91 $c->stash->{profile_id} = $profile_id;
92 $c->stash->{template} = '/breeders_toolbox/program/profile_detail.mas';
98 __PACKAGE__->meta->make_immutable;