adapted how the individual overview is instantiated
[sgn.git] / cgi-bin / gem / template.pl
blob935ff267930cca1b49d9193dbd97b3b328fc92d3
1 #!/usr/bin/perl
3 =head1 NAME
5 template.pl
6 Controller to show the web_page for template using MASON.
8 =cut
10 =head1 SYNOPSIS
13 =head1 DESCRIPTION
15 This is the script controller to show the template web_page using MASON
17 =cut
19 =head1 AUTHORS
21 Aureliano Bombarely Gomez
22 (ab782@cornell.edu)
24 =cut
27 use strict;
28 use warnings;
30 use CXGN::MasonFactory;
31 use CXGN::Page;
33 use CXGN::DB::Connection;
34 use CXGN::DB::DBICFactory;
35 use CXGN::GEM::Schema;
36 use CXGN::GEM::Template;
39 ## Create the mason object
41 my $m = CXGN::MasonFactory->new();
44 ## Create the schema object
46 my $psqlv = `psql --version`;
47 chomp($psqlv);
49 my @schema_list = ('gem', 'biosource', 'metadata', 'public');
50 if ($psqlv =~ /8\.1/) {
51 push @schema_list, 'tsearch2';
54 my $schema = CXGN::DB::DBICFactory->open_schema( 'CXGN::GEM::Schema', search_path => \@schema_list, );
56 ## Another schema to create is a schema that use sgn as schema
58 my $sgn_schema = CXGN::DB::DBICFactory->open_schema( 'SGN::Schema', search_path => ['sgn'], );
61 ## Also it will create a dbi-connection object ($dbh) for all the methods that do not use schemas
62 ## (as CXGN::People::Person) to not interfiere with them
64 my $dbh = CXGN::DB::Connection->new();
67 ## Use of CXGN::Page to take the arguments from the URL
70 my $page = CXGN::Page->new();
72 my %args = $page->get_all_encoded_arguments();
75 ## Get template object (by default it will create an empty template object)
77 my $template = CXGN::GEM::Template->new($schema);
79 if (exists $args{'id'}) {
80 $template = CXGN::GEM::Template->new($schema, $args{'id'});
81 } elsif (exists $args{'name'}) {
82 $template = CXGN::GEM::Template->new_by_name($schema, $args{'name'});
85 ## Get the unigene list associated with this template to use with the annotations
87 my @unigene_ids = ();
88 if (defined $template->get_template_id) {
89 @unigene_ids = $template->get_internal_accessions('unigene');
93 ## There are two ways to access to the page, using id=int or name=something. If use other combinations give an error message
95 if (defined $template->get_template_id() or defined $template->get_template_name() ) {
96 $m->exec( '/gem/template_detail.mas',
97 dbh => $dbh,
98 schema => $schema,
99 sgn_schema => $sgn_schema,
100 template => $template,
101 unigene_list => \@unigene_ids
103 } else {
104 $m->exec('/gem/gem_page_error.mas',
105 schema => $schema,
106 object => $template );