Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / SGN / View / Cvterm.pm
blob0af0d731c97a6c5e6d9653cd1f73ef84c038761d
1 package SGN::View::Cvterm;
2 use base 'Exporter';
3 use strict;
4 use warnings;
6 our @EXPORT_OK = qw/
7 cvterm_link
8 sort_onto_tree
9 /;
10 our @EXPORT = ();
12 sub cvterm_link {
13 my ($cvterm) = @_;
14 my $name = $cvterm->name;
15 my $id = $cvterm->cvterm_id;
16 return qq{<a href="/cvterm/$id/view">$name</a>};
20 sub sort_onto_tree {
21 my $cvterm = shift;
22 my $sorted_tree = shift;
23 my @direct_children = $cvterm->children->all;
25 my %children_hash = map { $_->subject->name , $_->subject } @direct_children;
26 foreach my $term_name (sort keys %children_hash ) {
27 push @$sorted_tree , $term_name if !grep (/^$term_name$/ , @$sorted_tree);
28 sort_onto_tree( $children_hash{$term_name} , $sorted_tree)
30 return $sorted_tree;
34 ######
36 ######