[Koha-patches] [PATCH] More cleanup of location & ccode authval handling.

Ryan Higgins rch at liblime.com
Sat Apr 5 19:55:52 CEST 2008


---
 C4/Koha.pm          |   27 +++++++++------------------
 C4/Search.pm        |   30 ++++++++++--------------------
 catalogue/detail.pl |    9 ++++-----
 3 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index 1f3aa79..d68cc96 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -852,12 +852,10 @@ sub GetAuthorisedValues {
 
 =head2 GetKohaAuthorisedValues
 	
-	Takes $kohafield, $fwcode, $value as parameters.
-	If C<$codedvalue> is supplied, returns scalar authorised value description.
-	If C<$codedvalue> is undefined, returns hashref of Code => description
+	Takes $kohafield, $fwcode as parameters.
+	Returns hashref of Code => description
 	Returns undef 
 	  if no authorised value category is defined for the kohafield.
-      or no authorised value is defined for C<$codedvalue> .
 
 =cut
 
@@ -868,22 +866,15 @@ sub GetKohaAuthorisedValues {
   my $dbh = C4::Context->dbh;
   my $avcode = GetAuthValCode($kohafield,$fwcode);
   if ($avcode) {  
-	if($codedvalue || ($codedvalue==0)) {
-		my $sth = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=? ");
-    	$sth->execute($avcode,$codedvalue);
-		my ($avdesc) = $sth->fetchrow_array;
-		return $avdesc;
-	} else {
-		my $sth = $dbh->prepare("select authorised_value, lib from authorised_values where category=? ");
-    	$sth->execute($avcode);
-		while ( my ($val, $lib) = $sth->fetchrow_array ) { 
-   			$values{$val}= $lib;
-   		}
-    	return \%values;
-  	}
+	my $sth = $dbh->prepare("select authorised_value, lib from authorised_values where category=? ");
+   	$sth->execute($avcode);
+	while ( my ($val, $lib) = $sth->fetchrow_array ) { 
+   		$values{$val}= $lib;
+   	}
+   	return \%values;
   } else {
   	return undef;
-}
+  }
 }
 
 =head2 GetManagedTagSubfields
diff --git a/C4/Search.pm b/C4/Search.pm
index 3386e94..82951a6 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1203,15 +1203,13 @@ sub searchResults {
     while ( my $bdata = $bsth->fetchrow_hashref ) {
         $branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
     }
-    my %locations;
-    my $lsch =
-      $dbh->prepare(
-"SELECT authorised_value,lib FROM authorised_values WHERE category = 'LOC'"
-      );
-    $lsch->execute();
-    while ( my $ldata = $lsch->fetchrow_hashref ) {
-        $locations{ $ldata->{'authorised_value'} } = $ldata->{'lib'};
-    }
+# FIXME - We build an authorised values hash here, using the default framework
+# though it is possible to have different authvals for different fws.
+
+    my $shelflocations =GetKohaAuthorisedValues('items.location','');
+
+    # get notforloan authorised value list (see $shelflocations  FIXME)
+    my $notforloan_authorised_value = GetAuthValCode('items.notforloan','');
 
     #Build itemtype hash
     #find itemtype & itemtype image
@@ -1238,14 +1236,6 @@ sub searchResults {
     $sth->execute;
     my ($itemtag) = $sth->fetchrow;
 
-    # get notforloan authorised value list
-    $sth =
-      $dbh->prepare(
-"SELECT authorised_value FROM `marc_subfield_structure` WHERE kohafield = 'items.notforloan' AND frameworkcode=''"
-      );
-    $sth->execute;
-    my ($notforloan_authorised_value) = $sth->fetchrow;
-
     ## find column names of items related to MARC
     my $sth2 = $dbh->prepare("SHOW COLUMNS FROM items");
     $sth2->execute;
@@ -1424,7 +1414,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
 				$onloan_items->{$key}->{due_date} = format_date($item->{onloan});
 				$onloan_items->{$key}->{count}++ if $item->{homebranch};
 				$onloan_items->{$key}->{branchname} = $item->{branchname};
-				$onloan_items->{$key}->{location} = $locations{ $item->{location} };
+				$onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} };
 				$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
 				$onloan_items->{$key}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
                 # if something's checked out and lost, mark it as 'long overdue'
@@ -1462,7 +1452,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
 					}
 					$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
 					$other_items->{$key}->{count}++ if $item->{homebranch};
-					$other_items->{$key}->{location} = $locations{ $item->{location} };
+					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
 					$other_items->{$key}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
                 }
                 # item is available
@@ -1473,7 +1463,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
 					foreach (qw(branchname itemcallnumber)) {
                     	$available_items->{$prefix}->{$_} = $item->{$_};
 					}
-					$available_items->{$prefix}->{location} = $locations{ $item->{location} };
+					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
 					$available_items->{$prefix}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
                 }
             }
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 53d8303..3c2bbe8 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -112,11 +112,10 @@ foreach my $item (@items) {
         $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
     }
     #get shelf location and collection code description if they are authorised value.
-	my $itemlocation = GetKohaAuthorisedValues('items.location',$fw, $item->{location} );
-	$item->{location} = $itemlocation if($itemlocation);
-	my $itemccode = $item->{ccode} ;
-    $itemccode =  GetKohaAuthorisedValues('items.ccode',$fw, $itemccode );
-	$item->{'ccode'} = $itemccode if($itemccode); 
+	my $shelflocations = GetKohaAuthorisedValues('items.location',$fw );
+	$item->{'location'} = $shelflocations->{$item->{'location'}} if($shelflocations->{$item->{'location'}}); 
+    my $collections =  GetKohaAuthorisedValues('items.ccode',$fw );
+	$item->{'ccode'} = $collections->{$item->{'ccode'}} if($collections->{$item->{'ccode'}}); 
 
     # checking for holds
     my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
-- 
1.5.2.1




More information about the Koha-patches mailing list