More cleanup of location & ccode authval handling.
authorRyan Higgins <rch@liblime.com>
Sat, 5 Apr 2008 17:55:52 +0000 (12:55 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Mon, 7 Apr 2008 20:59:49 +0000 (15:59 -0500)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Koha.pm
C4/Search.pm
catalogue/detail.pl

index 1f3aa79..d68cc96 100644 (file)
@@ -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
index 3386e94..82951a6 100644 (file)
@@ -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};
                 }
             }
index 53d8303..3c2bbe8 100755 (executable)
@@ -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});