[Koha-patches] [PATCH 4/6] Bug 5453 Move declarations out of conditionals in opac
Colin Campbell
colin.campbell at ptfs-europe.com
Mon Nov 29 18:58:26 CET 2010
---
opac/opac-ISBDdetail.pl | 5 +++-
opac/opac-authorities-home.pl | 26 +++++++++++---------
opac/opac-authoritiesdetail.pl | 16 +++++-------
opac/opac-detail.pl | 17 +++++++++-----
opac/opac-search.pl | 49 ++++++++++++++++++++++++++++-----------
opac/opac-topissues.pl | 17 ++++++++-----
opac/opac-user.pl | 14 +++++++----
7 files changed, 90 insertions(+), 54 deletions(-)
diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl
index 88904da..aea48ff 100755
--- a/opac/opac-ISBDdetail.pl
+++ b/opac/opac-ISBDdetail.pl
@@ -84,7 +84,10 @@ my $upc = GetNormalizedUPC($record,$marcflavour);
my $ean = GetNormalizedEAN($record,$marcflavour);
my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
-my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
+my $content_identifier_exists;
+if ( $isbn or $ean or $oclc or $upc ) {
+ $content_identifier_exists = 1;
+}
$template->param(
normalized_upc => $upc,
normalized_ean => $ean,
diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl
index 104dff2..45d18b4 100755
--- a/opac/opac-authorities-home.pl
+++ b/opac/opac-authorities-home.pl
@@ -41,18 +41,20 @@ $startfrom = 0 if ( !defined $startfrom );
my ( $template, $loggedinuser, $cookie );
my $resultsperpage;
-my $authtypes = getauthtypes;
-my @authtypesloop;
-foreach my $thisauthtype ( sort { $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} }
- keys %$authtypes )
-{
- my $selected = 1 if $thisauthtype eq $authtypecode;
- my %row = (
- value => $thisauthtype,
- selected => $selected,
- authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
- );
- push @authtypesloop, \%row;
+my $authtypes = getauthtypes();
+my @authtypesloop = ();
+foreach my $thisauthtype (
+ sort {
+ $authtypes->{$a}->{'authtypetext'}
+ cmp $authtypes->{$b}->{'authtypetext'}
+ }
+ keys %{$authtypes}
+ ) {
+ push @authtypesloop,
+ { value => $thisauthtype,
+ selected => $thisauthtype eq $authtypecode,
+ authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
+ };
}
if ( $op eq "do_search" ) {
diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl
index 71f746e..ead3e75 100755
--- a/opac/opac-authoritiesdetail.pl
+++ b/opac/opac-authoritiesdetail.pl
@@ -165,16 +165,14 @@ foreach my $field (@fields) {
}
$template->param( "0XX" => \@loop_data );
-my $authtypes = getauthtypes;
-my @authtypesloop;
-foreach my $thisauthtype ( keys %$authtypes ) {
- my $selected = 1 if $thisauthtype eq $authtypecode;
- my %row = (
- value => $thisauthtype,
- selected => $selected,
+my $authtypes = getauthtypes();
+my @authtypesloop = ();
+foreach my $thisauthtype ( keys %{$authtypes} ) {
+ push @authtypesloop,
+ { value => $thisauthtype,
+ selected => $thisauthtype eq $authtypecode,
authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
- );
- push @authtypesloop, \%row;
+ };
}
$template->param(
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 2de8ec8..047c95d 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -232,7 +232,10 @@ my $upc = GetNormalizedUPC($record,$marcflavour);
my $ean = GetNormalizedEAN($record,$marcflavour);
my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
-my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
+my $content_identifier_exists;
+if ( $isbn or $ean or $oclc or $upc ) {
+ $content_identifier_exists = 1;
+}
$template->param(
normalized_upc => $upc,
normalized_ean => $ean,
@@ -534,11 +537,13 @@ if (C4::Context->preference("OPACShelfBrowser")) {
}
push @next_items, $this_item;
}
-
- # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
- my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
- my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
-
+
+ my ( $shelfbrowser_next_itemnumber, $shelfbrowser_next_biblionumber );
+ if (@next_items) {
+ $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber};
+ $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber};
+ }
+
$template->param(
starting_homebranch => $starting_homebranch->{description},
starting_location => $starting_location->{description},
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 2bfcb6d..4058a08 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -203,9 +203,13 @@ if ( $template_type && $template_type eq 'advsearch' ) {
$template->param(outer_sup_servers_loop => $secondary_servers_loop,);
# set the default sorting
- my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder')
- if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
- $template->param($default_sort_by => 1);
+ if ( C4::Context->preference('OPACdefaultSortField')
+ && C4::Context->preference('OPACdefaultSortOrder') ) {
+ my $default_sort_by =
+ C4::Context->preference('OPACdefaultSortField') . '_'
+ . C4::Context->preference('OPACdefaultSortOrder');
+ $template->param( $default_sort_by => 1 );
+ }
# determine what to display next to the search boxes (ie, boolean option
# shouldn't appear on the first one, scan indexes should, adding a new
@@ -269,8 +273,13 @@ $tag = $params->{tag} if $params->{tag};
# sort by is used to sort the query
# in theory can have more than one but generally there's just one
my @sort_by;
-my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder')
- if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
+my $default_sort_by;
+if ( C4::Context->preference('OPACdefaultSortField')
+ && C4::Context->preference('OPACdefaultSortOrder') ) {
+ $default_sort_by =
+ C4::Context->preference('OPACdefaultSortField') . '_'
+ . C4::Context->preference('OPACdefaultSortOrder');
+}
@sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
$sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
@@ -551,8 +560,13 @@ for (my $i=0;$i<@servers;$i++) {
my $pages = ceil($hits / $results_per_page);
# default page number
my $current_page_number = 1;
- $current_page_number = ($offset / $results_per_page + 1) if $offset;
- my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0);
+ if ($offset) {
+ $current_page_number = ( $offset / $results_per_page + 1 );
+ }
+ my $previous_page_offset;
+ if ( $offset >= $results_per_page ) {
+ $previous_page_offset = $offset - $results_per_page;
+ }
my $next_page_offset = $offset + $results_per_page;
# If we're within the first 10 pages, keep it simple
#warn "current page:".$current_page_number;
@@ -566,11 +580,14 @@ for (my $i=0;$i<@servers;$i++) {
my $this_offset = (($i*$results_per_page)-$results_per_page);
# the page number for this page
my $this_page_number = $i;
- # it should only be highlighted if it's the current page
- my $highlight = 1 if ($this_page_number == $current_page_number);
# put it in the array
- push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ", at sort_by };
-
+ push @page_numbers,
+ { offset => $this_offset,
+ pg => $this_page_number,
+ highlight => $this_page_number == $current_page_number,
+ sort_by => join ' ', @sort_by
+ };
+
}
}
@@ -579,9 +596,13 @@ for (my $i=0;$i<@servers;$i++) {
for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
my $this_page_number = $i-9;
- my $highlight = 1 if ($this_page_number == $current_page_number);
- if ($this_page_number <= $pages) {
- push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ", at sort_by };
+ if ( $this_page_number <= $pages ) {
+ push @page_numbers,
+ { offset => $this_offset,
+ pg => $this_page_number,
+ highlight => $this_page_number == $current_page_number,
+ sort_by => join ' ', @sort_by
+ };
}
}
diff --git a/opac/opac-topissues.pl b/opac/opac-topissues.pl
index 70b712e..a89823e 100755
--- a/opac/opac-topissues.pl
+++ b/opac/opac-topissues.pl
@@ -101,13 +101,16 @@ $template->param( branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}
#doctype
$itemtypes = GetItemTypes;
my @itemtypeloop;
-foreach my $thisitemtype (sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'}} keys %$itemtypes) {
- my $selected = 1 if $thisitemtype eq $itemtype;
- my %row =(value => $thisitemtype,
- description => $itemtypes->{$thisitemtype}->{'description'},
- selected => $selected,
- );
- push @itemtypeloop, \%row;
+foreach my $thisitemtype (
+ sort {
+ $itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'}
+ } keys %{$itemtypes}
+ ) {
+ push @itemtypeloop,
+ { value => $thisitemtype,
+ description => $itemtypes->{$thisitemtype}->{'description'},
+ selected => $thisitemtype eq $itemtype,
+ };
}
$template->param(
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 634b77a..7b4684c 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -169,13 +169,17 @@ $template->param( overdues_count => $overdues_count );
# load the branches
my $branches = GetBranches();
my @branch_loop;
-for my $branch_hash (sort keys %$branches ) {
- my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
+for my $branch_hash ( sort keys %{$branches} ) {
+ my $selected;
+ if ( C4::Context->preference('SearchMyLibraryFirst') ) {
+ $selected =
+ ( C4::Context->userenv
+ && ( $branch_hash eq C4::Context->userenv->{branch} ) );
+ }
push @branch_loop,
- {
- value => "branch: $branch_hash",
+ { value => "branch: $branch_hash",
branchname => $branches->{$branch_hash}->{'branchname'},
- selected => $selected
+ selected => $selected,
};
}
$template->param( branchloop => \@branch_loop );
--
1.7.3.2
More information about the Koha-patches
mailing list