Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / SGN / Controller / Cvterm.pm
blobb690ba5468256969506b7eb400fe30ca3b852279
2 package SGN::Controller::Cvterm;
4 #use CXGN::Chado::Cvterm; #DEPRECATE this !!
5 use CXGN::Cvterm;
7 use Moose;
9 BEGIN { extends 'Catalyst::Controller' };
10 with 'Catalyst::Component::ApplicationAttribute';
12 has 'schema' => (
13 is => 'rw',
14 isa => 'DBIx::Class::Schema',
15 lazy_build => 1,
17 sub _build_schema {
18 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
22 =head2 view_cvterm
24 Public path: /cvterm/<cvterm_id>/view
26 View a cvterm detail page.
28 Chained off of L</get_cvterm> below.
30 =cut
32 sub view_cvterm : Chained('get_cvterm') PathPart('view') Args(0) {
33 my ( $self, $c, $action) = @_;
34 my $cvterm = $c->stash->{cvterm};
35 my $cvterm_id = $cvterm ? $cvterm->cvterm_id : undef ;
37 my $bcs_cvterm = $cvterm->cvterm;
39 my ($person_id, $user_role, $curator, $submitter, $sequencer);
40 my $logged_user = $c->user;
41 $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
42 $user_role = 1 if $logged_user;
43 $curator = $logged_user->check_roles('curator') if $logged_user;
44 $submitter = $logged_user->check_roles('submitter') if $logged_user;
45 $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
46 my $props = $self->_cvtermprops($cvterm);
47 my $editable_cvterm_props = "trait_format,trait_default_value,trait_minimum,trait_maximum,trait_details,trait_categories";
50 $c->stash(
51 template => '/chado/cvterm.mas',
52 cvterm => $cvterm, #deprecate this maybe?
53 cvtermref => {
54 cvterm => $bcs_cvterm,
55 curator => $curator,
56 submitter => $submitter,
57 sequencer => $sequencer,
58 person_id => $person_id,
59 props => $props,
60 editable_cvterm_props => $editable_cvterm_props,
67 =head2 get_cvterm
69 Chain root for fetching a cvterm object to operate on.
71 Path part: /cvterm/<cvterm_id>
73 =cut
75 sub get_cvterm : Chained('/') PathPart('cvterm') CaptureArgs(1) {
76 my ($self, $c, $cvterm_id) = @_;
78 my $identifier_type = $c->stash->{identifier_type}
79 || $cvterm_id =~ /[^-\d]/ ? 'accession' : 'cvterm_id';
81 my $cvterm;
82 if( $identifier_type eq 'cvterm_id' ) {
83 $cvterm = CXGN::Cvterm->new({ schema=>$self->schema, cvterm_id => $cvterm_id } );
84 } elsif ( $identifier_type eq 'accession' ) {
85 $cvterm = CXGN::Cvterm->new({ schema=>$self->schema, accession=>$cvterm_id } ) ;
87 my $found_cvterm = $cvterm->cvterm
88 or $c->throw_404( "Cvterm $cvterm_id not found" );
90 $c->stash->{cvterm} = $cvterm;
92 return 1;
97 sub _cvtermprops {
98 my ($self,$cvterm) = @_;
100 my $properties ;
101 if ($cvterm) {
102 my $bcs_cvterm = $cvterm->cvterm;
103 if (!$bcs_cvterm) { return; }
104 my $cvtermprops = $bcs_cvterm->search_related("cvtermprops");
105 while ( my $prop = $cvtermprops->next ) {
106 push @{ $properties->{$prop->type->name} } , $prop->value ;
109 return $properties;
111 ####
112 1;##
113 ####