[Koha-patches] [PATCH] Remove hardcoded LOC AND CCODE authvals; fix no display of location on staff details page.

Ryan Higgins rch at liblime.com
Sat Apr 5 02:05:07 CEST 2008


---
 C4/Koha.pm                                         |   34 +++++++++++++------
 catalogue/detail.pl                                |   15 +++-----
 .../prog/en/modules/catalogue/detail.tmpl          |    2 +-
 3 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index f653271..1f3aa79 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -852,26 +852,38 @@ sub GetAuthorisedValues {
 
 =head2 GetKohaAuthorisedValues
 	
-	Takes $dbh , $kohafield as parameters.
-	returns hashref of authvalCode => liblibrarian
-	or undef if no authvals defined for kohafield.
+	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
+	Returns undef 
+	  if no authorised value category is defined for the kohafield.
+      or no authorised value is defined for C<$codedvalue> .
 
 =cut
 
 sub GetKohaAuthorisedValues {
-  my ($kohafield,$fwcode) = @_;
+  my ($kohafield,$fwcode,$codedvalue) = @_;
   $fwcode='' unless $fwcode;
   my %values;
   my $dbh = C4::Context->dbh;
   my $avcode = GetAuthValCode($kohafield,$fwcode);
   if ($avcode) {  
-    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;
+	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;
+  	}
+  } else {
+  	return undef;
+}
 }
 
 =head2 GetManagedTagSubfields
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index bc251a3..53d8303 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -62,14 +62,8 @@ my $marcseriesarray  = GetMarcSeries($record,$marcflavour);
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
 
-my %locations;
 # FIXME: move this to a pm, check waiting status for holds
 my $dbh = C4::Context->dbh;
-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'};
-}
 
 # change back when ive fixed request.pl
 my @items = &GetItemsInfo( $biblionumber, 'intra' );
@@ -112,14 +106,17 @@ foreach my $item (@items) {
     $item->{datedue} = format_date($item->{datedue});
     $item->{datelastseen} = format_date($item->{datelastseen});
     $item->{onloan} = format_date($item->{onloan});
-    $item->{locationname} = $locations{$item->{location}};
     # item damaged, lost, withdrawn loops
     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
     if ($item->{damaged}) {
         $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
     }
-    #get collection code description, too
-    $item->{'ccode'}  = GetAuthorisedValueDesc('','',   $item->{'ccode'} ,'','','ccode');
+    #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); 
 
     # checking for holds
     my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
index 32d98a4..5fd3c91 100755
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
@@ -158,7 +158,7 @@ function verify_images() {
             <!-- TMPL_LOOP NAME="itemloop" -->
                 <tr>
                     <!-- TMPL_IF NAME="item-level_itypes" --><td><!-- TMPL_IF NAME="noItemTypeImages" --><!-- TMPL_VAR NAME="description" --><!-- TMPL_ELSE --><img src="<!-- TMPL_VAR NAME="imageurl" -->" alt="<!-- TMPL_VAR NAME="description" -->" title="<!-- TMPL_VAR NAME="description" -->"><!-- /TMPL_IF --></td><!-- /TMPL_IF -->
-                    <td><!-- TMPL_VAR NAME="branchname" --></td>
+                    <td><!-- TMPL_UNLESS NAME="singlebranchmode" --><!-- TMPL_VAR NAME="branchname" --><!-- /TMPL_UNLESS --> <!-- TMPL_VAR NAME="location" --> </td>
                     <td><!-- TMPL_VAR name="ccode" --></td>
                     <td><!-- TMPL_IF NAME="itemcallnumber" --> <!-- TMPL_VAR NAME="itemcallnumber" --><!-- /TMPL_IF --></td>
                     <td>
-- 
1.5.2.1




More information about the Koha-patches mailing list