package JCRRelated; # -------------------------------------------------------------------- # 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. # -------------------------------------------------------------------- use strict; use Data::Dumper; use ISIBench; use JCR::Journal; use JCR::Category; use Log::Log4perl qw(get_logger); use PageComponents; use VCRControl; use base qq(JCRPage); sub build_page { ISIBench::start(); my $logger = get_logger("JCRRelated"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; #Get session object my $session = $self->{session}; #Get rq parameter my $request = $self->{'request'}; my $rqparam = $request->{'RQ'}; my $category_name = $request->{'category'}; my $j20 = $request->{'journal'}; my($cat,$journal,$toolbar,$category_enc,$j20_enc,$cathash); my($details,$journal_count,$mode_box,$url_params,$vcr,$jtitle,%modes,$count); # Save required query params $self->_save_params(); $logger->debug("RQ param is : $rqparam"); #Get the year and edition from Session my $edition = $session->get('value' => 'edition'); my $year = $session->get('value' => 'year'); if ( $j20 ) { $url_params = qq|RQ=$request->{RQ}&journal=$self->{j20_enc}&rank=$self->{rank}|; # Build the 'mode' select box tie %modes, "Tie::IxHash"; %modes = ( 'rmax' => 'R max', 'i_journal' => 'Related journal', 'i_j_result' => 'R journal to j', 'j_i_result' => 'R j to journal', ); } elsif ( $category_name ) { $url_params = qq|RQ=$request->{RQ}&category=$self->{category_enc}&rank=$self->{rank}|; # Build the 'mode' select box tie %modes, "Tie::IxHash"; %modes = ( 'rmax' => 'R max', 'i_journal' => 'Related journal', 'i_j_result' => 'R subject category to j', 'j_i_result' => 'R j to subject category', ); } $mode_box = PageComponents::build_select_box( 'type' => 'single', 'data' => \%modes, 'name' => 'sort_by', 'selected' => $self->{relatedness_sort} || 'rmax', ); $logger->debug("Select box html : ", sub{Dumper($mode_box->{html})}); if ( $category_name ) { #Create a category object $cat = JCR::Category->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($cat) && (ref($cat) =~ /category/i)) { $logger->error("Could not create category object (#$cat)!"); ISIBench::stop(); return $cat; } # Get category subject by name $cathash = $cat->get_category_by_name( 'name' => $category_name, 'order_by' => 'name', ); $logger->debug("Cat Hash : ", sub{Dumper($cathash)}); # Get related journal count $count = $cat->get_related_journals_count( 'subject' => $cathash, ); $logger->debug("Related Journal Count : ", sub{Dumper(\$count)}); # Get related journal info $details = $cat->get_related_journals( 'subject' => $cathash, 'order_by' => $self->{relatedness_sort}, 'limit' => $CF::recs_per_related_journal, 'start' => ($self->{related_journal_cursor}-1), ); $logger->debug("Related Journal Info : ", sub{Dumper(\$details)}); # Add the toolbar $toolbar = $self->build_toolbar( 'help' => '2.16' ); #Add the return to category button $toolbar->add( 'button' => 'TB_RET2CATEGORY', 'URI' => "$CF::base_path/JCR?RQ=RECORD&category=$self->{category_enc}&rank=$self->{rank}" ); $self->set( 'name' => 'subject_category', 'value' => $category_name, ); $self->set( 'name' => 'category_enc', 'value' => $self->{category_enc}, ); $self->set( 'name' => 'sort_rmax', 'value' => ($self->{relatedness_sort} eq 'rmax') ? 'class=sortedcat' : '', ); $self->set( 'name' => 'sort_journal', 'value' => ($self->{relatedness_sort} eq 'i_journal') ? 'class=sortedcat' : '', ); $self->set( 'name' => 'sort_i_j_result', 'value' => ($self->{relatedness_sort} eq 'i_j_result') ? 'class=sortedcat' : '', ); $self->set( 'name' => 'sort_j_i_result', 'value' => ($self->{relatedness_sort} eq 'j_i_result') ? 'class=sortedcat' : '', ); } elsif ( $j20 ) { #Create a journal object $journal = JCR::Journal->new( 'db' => $self->{'db'}, 'year' => $year->{year}, 'edition' => $edition->{edition}, ); unless (defined($journal) && (ref($journal) =~ /journal/i)) { $logger->error("Could not create journal object (#$journal)!"); ISIBench::stop(); return $journal; } # Get related journal info $count = $journal->get_related_journals_count( 'j20' => $j20, ); $logger->debug("Related Journal Count : ", sub{Dumper(\$count)}); # Get related journal info $details = $journal->get_related_journals( 'j20' => $j20, 'order_by' => $self->{relatedness_sort}, 'limit' => $CF::recs_per_related_journal, 'start' => ($self->{related_journal_cursor}-1), ); $logger->debug("Related Journal Info : ", sub{Dumper(\$details)}); # Add the toolbar $toolbar = $self->build_toolbar( 'help' => '2.15' ); #Add the return to category button $toolbar->add( 'button' => 'TB_RET2JOURNAL', 'URI' => "$CF::base_path/JCR?RQ=RECORD&journal=$self->{j20_enc}&rank=$self->{rank}" ); # get the journal title for displaying full title on the page. $jtitle = $journal->get_journal_title('j20' => $j20); unless (defined($jtitle) && (ref($jtitle) =~ /hash/i)) { $logger->error("Could not retrieve journal Title! (#$jtitle)"); ISIBench::stop(); return $jtitle; } $logger->debug("Journal Title: ", sub{Dumper($jtitle);}); $self->set( 'name' => 'jtitle', 'value' => $jtitle->{title}, ); $self->set( 'name' => 'j20_display', 'value' => $j20, ); $self->set( 'name' => 'j20_enc', 'value' => $self->{j20_enc}, ); $self->set( 'name' => 'sort_rmax', 'value' => ($self->{relatedness_sort} eq 'rmax') ? 'class=sorted' : '', ); $self->set( 'name' => 'sort_journal', 'value' => ($self->{relatedness_sort} eq 'i_journal') ? 'class=sorted' : '', ); $self->set( 'name' => 'sort_i_j_result', 'value' => ($self->{relatedness_sort} eq 'i_j_result') ? 'class=sorted' : '', ); $self->set( 'name' => 'sort_j_i_result', 'value' => ($self->{relatedness_sort} eq 'j_i_result') ? 'class=sorted' : '', ); } if ((ref($details) =~ /hash/i) && ($count->{count}>=0)) { # Build the JCRCite page template $vcr = VCRControl->new( 'lines_per_page' => $CF::recs_per_related_journal, 'num_page_links' => 10, 'total_lines' => $count->{count}, 'url_target' => $CF::app_path, 'url_params' => $url_params, 'images_url' => $CF::image_path, 'cursor' => $self->{related_journal_cursor}, ); unless (defined($vcr) && (ref($vcr) =~ /vcrcontrol/i)) { $logger->error("Could not create VCRControl Object! (#$vcr)"); ISIBench::stop(); return $vcr; } # Get the journal start and end count $journal_count = $vcr->range(); # Vars for the VCR control $self->set( 'name' => 'rank', 'value' => $self->{rank}, ); $self->set( 'name' => 'record_start', 'value' => $self->{related_journal_cursor}, ); $self->set( 'name' => 'vcr_control', 'value' => $vcr->draw(), ); $self->set( 'name' => 'journal_start', 'value' => $journal_count->{start}, ); $self->set( 'name' => 'journal_end', 'value' => $journal_count->{end}, ); $self->set( 'name' => 'journal_total', 'value' => $count->{count}, ); $self->set( 'name' => 'page_current', 'value' => $vcr->get_page(), ); $self->set( 'name' => 'page_total', 'value' => $vcr->{_total_pages}, ); # End VCR Control vars $self->set( 'name' => 'sort_select_box', 'value' => $mode_box->{html}, ); $self->set( 'name' => 'records', 'value' => $details->{results}, ); } ISIBench::stop(); return 0; } sub _save_params { ISIBench::start(); my $logger = get_logger("JCRRelated"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my $j20 = $request->{journal}; my $category_name = $request->{category}; my $rank = $request->{rank}; my $sort_by = $request->{sort_by}; # If this is a new search, wipe out the old search values if ($request->{query_new} eq 'true') { $logger->debug("Erasing old search parameters..."); $session->remove( 'name' => 'relatedness_sort', ); $session->remove( 'name' => 'related_journal_cursor', ); } $self->{rank} = $rank; my $sort = $session->get( 'value' => 'relatedness_sort' ); $self->{relatedness_sort} = $sort_by || $sort->{relatedness_sort} || 'rmax'; if ($self->{relatedness_sort} ne $sort->{relatedness_sort}) { $session->set( 'name' => 'relatedness_sort', 'value' => $self->{relatedness_sort}, ); } if ( $j20 ) { # Build the Related Journals page template $logger->debug("Loading jcr_related_journal_list.html template"); my $ret = $self->set_template( 'template' => "jcr_related_journal_list.html" ); if ($ret) { ISIBench::stop(); return $ret; } # Set the page title $self->set_title( 'title' => 'Related Journals' ); $self->{j20_enc} = URL::encode($j20); } elsif ( $category_name ) { # Build the Journals Related to Subject Category page template $logger->debug("Loading jcr_related_journal_category_list.html template"); my $ret = $self->set_template( 'template' => "jcr_related_journal_category_list.html" ); if ($ret) { ISIBench::stop(); return $ret; } # Set the page title $self->set_title( 'title' => 'Journals Related to Subject Category' ); $self->{category_enc} = URL::encode($category_name); } # Get the current page number my $cursor = $session->get( 'value' => 'related_journal_cursor' ); $self->{related_journal_cursor} = $request->{cursor} || $cursor->{related_journal_cursor} || 1; if ($self->{related_journal_cursor} ne $cursor->{related_journal_cursor}) { $session->set( 'name' => 'related_journal_cursor', 'value' => $self->{related_journal_cursor}, ); } $logger->debug("Cursor is: ", $self->{related_journal_cursor}); ISIBench::stop(); return 0; } 1;