package JCRSelection; # -------------------------------------------------------------------- # The copyright and all other proprietary rights in this Database # (including software - SEE LICENSING AGREEMENT) are the sole and # exclusive property of the Institute for Scientific Information # (ISI). This Database and source code, or any derivative works # thereof, are confidential and proprietary to ISI . Therefore, # duplication, reuse, redistribution, reverse assembling, reverse # compiling, or translation of the Database, source code, or any # portion thereof IS NOT PERMITTED. Consult Licensing Agreement. # -------------------------------------------------------------------- # $Id: JCRSelection.pm,v 1.32 2008/09/16 16:17:31 ssidanal Exp $ use strict; use URL; use JCR::Category; use JCR::Country; use Data::Dumper; use ISIBench; use JCRErrorList; use JCRUtil; use Log::Log4perl qw(get_logger); use PageComponents; use JCR::Publisher; use base qq(JCRPage); =head1 NAME Page - Parent class for all Page Generation modules =head2 METHODS =over 4 =cut =item build_page ( 'db' => $db, 'session' => $session, 'apache' => $r, 'request' => \%request, ); Builds the Category/Publisher/Country selection page. =cut sub build_page { ISIBench::start(); my $logger = get_logger("JCRSelection"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; # Snag our parameters my $db = $self->{db}; my $session = $self->{session}; my $request = $self->{request}; # Get the year and edition from Session my $edition = $session->get('value' => 'edition'); my $year = $session->get('value' => 'year'); # Have the limits been changed? if ($request->{change_limits} eq 'true') { JCRUtil::purge_marked_list( 'session' => $session, 'db' => $db, ); } # Determine the mode unless ($request->{view} =~ /(category|publisher|country)/i) { ISIBench::stop(); return 2; } my $mode = $1; $logger->debug("Selection mode is: $mode"); # Save the mode within the session - needed for returning to the HOME page $session->set( 'name' => 'HOME_mode', 'value' => $mode ); # Get our selection list my $func = '_get_' . $mode . '_hash'; my $selref = $self->$func( 'db' => $db, 'year' => $year->{year}, 'edition' => $edition->{edition}, ); $logger->debug("Selection reference is ", sub{Dumper($selref)}); unless (defined($selref) && (ref($selref) =~ /(?:hash|array)/i)) { ISIBench::stop(); return $selref; } # Build the select box my $selection = PageComponents::build_select_box( 'type' => 'multiple', 'size' => '9', 'data' => $selref, 'name' => 'query_data', ); # Load up the template my $ret = $self->set_template( 'template' => "jcr_selection-$mode.html"); if ($ret) { ISIBench::stop(); return $ret; } # Set our page title $self->set_title( 'title' => ucfirst($mode) . ' Selection' ); # Set our values in the template $self->set( 'name' => 'selection', 'value' => $selection->{html}, ); my $journal_sort_select_box = JCRUtil::build_sort_box( 'sort_box_type' => 'journal' , 'year' => $year->{year}, ); $self->set( 'name' => 'journal_sort_select_box', 'value' => $journal_sort_select_box->{html}, ); my $category_sort_select_box = JCRUtil::build_sort_box( 'sort_box_type' => 'category' ); $self->set( 'name' => 'category_sort_select_box', 'value' => $category_sort_select_box->{html}, ); $self->set( 'name' => 'scope_notes', 'value' => $self->_get_scope_notes_link( 'year' => $year->{year}, 'edition' => $edition->{edition}), ); $self->set( 'name' => 'show_subject_category_radio_button', 'value' => ($year->{year} >= $CF::data_subject_category_start) ? 1 : 0, ); # Add the toolbar my $help_context; if ($mode eq 'category') { $help_context = '2.2'; } elsif ($mode eq 'publisher') { $help_context = '2.3'; } elsif ($mode eq 'country') { $help_context = '2.4'; } my $toolbar = $self->build_toolbar( 'help' => $help_context ); unless (defined($toolbar) && (ref($toolbar) =~ /toolbar/i)) { ISIBench::stop(); return $toolbar; } my $log_edition = $edition->{'edition'}; my $data_string = qq{$log_edition}; # Log the Selection event if ($mode =~ /category|publisher|country/) { $session->log_event( 'event' => 'event_query', 'data' => { 'limits' => $data_string, }, ); } # error checking my $error_string = $session->getError(); if ( length($error_string) > 1 ) { $logger->error("WURS Event not logged: $error_string"); } ISIBench::stop(); return 0; } # # PRIVATE METHODS # # _get_category_hash( # 'db' => $db, # 'year' => $year, # 'edition' => $edition, # ); # Builds a hash of categories using JCR::Category.pm sub _get_category_hash { ISIBench::start(); my $logger = get_logger("JCRSelection"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; # Get the category list from the database my $cat = JCR::Category->new( 'db' => $args->{db}, 'edition' => $args->{edition}, 'year' => $args->{year}, ); unless (defined($cat) && (ref($cat) =~ /category/i)) { $logger->error("Could not create category object (#$cat)!"); ISIBench::stop(); return $cat; } # Get the category hash my $cathash = $cat->get_category_hash( 'order_by' => 'name' ); $logger->debug("cathash is $cathash) : ", ref($cathash)); ISIBench::stop(); return $cathash; } # _get_publisher_hash( # 'db' => $db, # 'year' => $year, # 'edition' => $edition, # ); # Builds a hash of publishers using Publisher.pm sub _get_publisher_hash { ISIBench::start(); my $logger = get_logger("JCRSelection"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; # Get the publisher list from the database my $pub = JCR::Publisher->new( 'db' => $args->{db}, 'edition' => $args->{edition}, 'year' => $args->{year}, ); unless (defined($pub) && (ref($pub) =~ /publisher/i)) { $logger->error("Could not create publisher object (#$pub)!"); ISIBench::stop(); return $pub; } # Get the publisher hash my $pubhash = $pub->get_publishers(); $logger->debug("pubhash is $pubhash) : ", ref($pubhash)); ISIBench::stop(); return $pubhash; } # _get_country_hash( # 'db' => $db, # 'year' => $year, # 'edition' => $edition, # ); # Builds an array of countries using Country.pm sub _get_country_hash { ISIBench::start(); my $logger = get_logger("JCRSelection"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; # Get the country list from the database my $con = JCR::Country->new( 'db' => $args->{db}, 'edition' => $args->{edition}, 'year' => $args->{year}, ); unless (defined($con) && (ref($con) =~ /country/i)) { $logger->error("Could not create country object (#$con)!"); ISIBench::stop(); return $con; } # Get the country hash my $conarray = $con->get_countries(); $logger->debug("conarray is $conarray) : ", ref($conarray)); ISIBench::stop(); return $conarray; } sub _get_scope_notes_link { ISIBench::start(); my $logger = get_logger("JCRSelection"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my ($sn_filename,$scope_notes_file,$scope_notes_url); if ( $args->{edition} eq 'science' ) { $sn_filename = "SCOPE_SCI.htm"; } else { $sn_filename = "SCOPE_SOC.htm"; } $scope_notes_file = "$CF::static_html_directory/scope_notes/".uc($args->{edition})."/".$args->{year}."/".$sn_filename; $logger->debug("Scope Notes file location: ", sub{Dumper($scope_notes_file);}); if( -f $scope_notes_file ) { $logger->debug("Scope Notes file for $args->{edition} / $args->{year} EXISTS!!"); $scope_notes_url = "$CF::base_path/static_html/scope_notes/".uc($args->{edition})."/".$args->{year}."/".$sn_filename; return $scope_notes_url; } else { $logger->debug("Scope Notes file for $args->{edition} / $args->{year} DOES NOT EXISTS!!"); return; } } 1;