koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 Search.pm [dev_week]


From: Chris Cormack
Subject: [Koha-cvs] koha/C4 Search.pm [dev_week]
Date: Mon, 18 Jun 2007 21:49:18 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Chris Cormack <rangi>   07/06/18 21:49:18

Modified files:
        C4             : Search.pm 

Log message:
        MySQL 5 problem fix plus item_type_level code for stow

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.99.2.11.2.42&r2=1.99.2.11.2.43

Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.42
retrieving revision 1.99.2.11.2.43
diff -u -b -r1.99.2.11.2.42 -r1.99.2.11.2.43
--- Search.pm   17 May 2007 17:54:40 -0000      1.99.2.11.2.42
+++ Search.pm   18 Jun 2007 21:49:18 -0000      1.99.2.11.2.43
@@ -40,7 +40,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.99.2.11.2.42 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.43 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -63,8 +63,7 @@
 @ISA = qw(Exporter);
 @EXPORT = qw(
 
-&CatSearch 
-&catalogsearch
+&CatSearch &catalogsearch
 
 &BornameSearch &ItemInfo &KeywordSearch 
 
@@ -263,6 +262,7 @@
     my $counter = $offset;
     # HINT : biblionumber as bn is important. The hash is fills biblionumber 
with items.biblionumber.
     # so if you dont' has an item, you get a not nice empty value.
+       #item-level_itypes - this is going to get us biblioitem level. but we 
check item-level itemtypes.notforloan later (is this enough?)
     my $sth = $dbh->prepare("SELECT biblio.biblionumber as 
bn,biblioitems.*,biblio.*, itemtypes.notforloan,itemtypes.description
                             FROM biblio
                             LEFT JOIN biblioitems on biblio.biblionumber = 
biblioitems.biblionumber
@@ -317,6 +317,13 @@
                     $date_due = $loan->{date_due};
                 }
             }
+           if ( C4::Context->preference("item-level_itypes") && 
!($item->{'notforloan'}) ) {
+               my $itype_sth = $dbh->prepare("SELECT notforloan FROM itemtypes 
WHERE itemtype=?");
+               $itype_sth->execute($item->{itype});
+               my ($itype_noloan) = $itype_sth->fetchrow_array;
+               $item->{notforloan} = $itype_noloan;
+           }
+                                               
             # store this item
             my %lineCN;
             $lineCN{holdingbranch} = $item->{holdingbranch};
@@ -328,7 +335,7 @@
             $notforloan=0 unless ($item->{notforloan} or $item->{wthdrawn} or 
$item->{itemlost});
             push @CNresults,\%lineCN;
             $totalitems++;
-        }
+        } #done with item-level.
         # save the biblio in the final array, with item and item issue status
         my %newline;
         %newline = %$line;
@@ -429,6 +436,8 @@
        my ($record)address@hidden;
        my $dbh=C4::Context->dbh;
        my $result = MARCmarc2koha($dbh,$record,'');
+use Data::Dumper;
+warn Dumper($result);
        my $sth;
        my $query;
        my $search;
@@ -444,7 +453,8 @@
                $result->{title}=~s /\)//g;
                $query = "ti,ext=$result->{title}";
        }
-       my 
($possible_duplicate_record)=C4::Biblio::getRecord("biblioserver",$query,"usmarc");
+       warn "FindDuplicate Query: $query";
+       my ($possible_duplicate_record);# = 
C4::Biblio::getRecord("biblioserver",$query,"usmarc");
        if ($possible_duplicate_record) {
                my $marcrecord = 
MARC::Record->new_from_usmarc($possible_duplicate_record);
                my $result = MARCmarc2koha($dbh,$marcrecord,'');
@@ -1132,7 +1142,7 @@
        my $i=0;
        my $limit= $num+$offset;
        while (my $data=$sth->fetchrow_hashref){
-               my $query="select classification,dewey,subclass,publishercode 
from biblioitems where biblionumber=?";
+               my $query="select 
classification,dewey,subclass,publishercode,isbn from biblioitems where 
biblionumber=?";
                my @bind=($data->{'biblionumber'});
                if ($search->{'class'} ne ''){
                        my @temp=split(/\|/,$search->{'class'});
@@ -1164,6 +1174,7 @@
                my $subclass;
                my $true=0;
                my $publishercode;
+               my $isbn;
                my $bibitemdata;
                if ($bibitemdata = $sti->fetchrow_hashref()){
                        $true=1;
@@ -1171,6 +1182,7 @@
                        $dewey=$bibitemdata->{'dewey'};
                        $subclass=$bibitemdata->{'subclass'};
                        $publishercode=$bibitemdata->{'publishercode'};
+                       $isbn=$bibitemdata->{'isbn'};
                }
                #  print STDERR "$dewey $subclass $publishercode\n";
                # FIXME - The Dewey code is a string, not a number.
@@ -1180,6 +1192,7 @@
                $data->{'classification'}=$classification;
                $data->{'dewey'}=$dewey;
                $data->{'publishercode'}=$publishercode;
+               $data->{'isbn'}=$isbn;
                $sti->finish;
                if ($true == 1){
                        if ($count > $offset && $count <= $limit){
@@ -1245,12 +1258,20 @@
 sub ItemInfo {
        my ($env,$biblionumber,$type) = @_;
        my $dbh   = C4::Context->dbh;
-       my $query = "SELECT *,items.notforloan AS notforloan, 
itemtypes.notforloan AS itemnotforloan FROM items, biblio, biblioitems 
+       my $query = ( C4::Context->preference('item-level_itypes') ) ? 
+                       "SELECT *,items.notforloan AS notforloan, 
itemtypes.notforloan AS itemnotforloan, itemtypes.description AS itemtypedesc 
FROM  biblio, biblioitems, items
+                               LEFT JOIN itemtypes ON items.itype = 
itemtypes.itemtype
+                               WHERE items.biblionumber = ?
+                               AND biblioitems.biblioitemnumber = 
items.biblioitemnumber
+                               AND biblio.biblionumber = items.biblionumber"
+               :       "SELECT *,items.notforloan AS notforloan, 
itemtypes.notforloan AS itemnotforloan FROM items, biblio, biblioitems 
                                        LEFT JOIN itemtypes ON 
biblioitems.itemtype = itemtypes.itemtype
                                        WHERE items.biblionumber = ?
                                        AND biblioitems.biblioitemnumber = 
items.biblioitemnumber
                                        AND biblio.biblionumber = 
items.biblionumber";
+       
        $query .= " ORDER BY items.dateaccessioned DESC";
+
        my $sth=$dbh->prepare($query);
        $sth->execute($biblionumber);
        my $i=0;
@@ -1301,6 +1322,8 @@
                $data->{'datedue'}=$datedue;
                $data->{'count_reserves'} = $count_reserves;
 
+#FIXME These should use frameworks.  Or at least be refactored.  Or at least 
use api.
+
                # get notforloan complete status if applicable
                my $sthnflstatus = $dbh->prepare('select authorised_value from 
marc_subfield_structure where kohafield="items.notforloan"');
                $sthnflstatus->execute;
@@ -1329,6 +1352,21 @@
             $data->{itemlosttext} = $lib;
         }
 
+               # get itemlocation auth value if applicable
+       
+           $sthnflstatus = $dbh->prepare('select authorised_value from 
marc_subfield_structure where kohafield="items.location"');
+        $sthnflstatus->execute;
+        $authorised_valuecode = $sthnflstatus->fetchrow;
+        if ($authorised_valuecode) {
+            #warn "authorised valuecode: $authorised_valuecode";
+                       #warn "location: ".$data->{location};
+            $sthnflstatus = $dbh->prepare("select lib from authorised_values 
where category=? and authorised_value=?");
+            $sthnflstatus->execute($authorised_valuecode,$data->{location});
+            my ($lib) = $sthnflstatus->fetchrow;
+            #warn "lib: $lib from $authorised_valuecode,$data->{location}";
+            $data->{location} = $lib;
+        }
+
                # my stack procedures
                my $stackstatus = $dbh->prepare('select authorised_value from 
marc_subfield_structure where kohafield="items.stack"');
                $stackstatus->execute;
@@ -1424,11 +1462,13 @@
 sub itemdata {
   my ($barcode)address@hidden;
   my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
-  and items.biblioitemnumber=biblioitems.biblioitemnumber");
+  my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?  and 
items.biblioitemnumber=biblioitems.biblioitemnumber");
   $sth->execute($barcode);
   my $data=$sth->fetchrow_hashref;
   $sth->finish;
+  if ( $data && (C4::Context->preference("item-level_itypes")) ) {
+       $data->{'itemtype'} = $data->{'itype'};
+  }
   return($data);
 }
 
@@ -1456,10 +1496,11 @@
        my ($bibnum, $type) = @_;
        my $dbh   = C4::Context->dbh;
        my $sth   = $dbh->prepare("Select *, biblioitems.notes AS bnotes, 
biblio.notes
-                                                               from (biblio, 
biblioitems)
+                                                               from biblio
                                                                left join 
bibliosubtitle on
-                                                               
biblio.biblionumber = bibliosubtitle.biblionumber
-                                                               left join 
itemtypes on biblioitems.itemtype=itemtypes.itemtype
+                                                               
(biblio.biblionumber = bibliosubtitle.biblionumber)
+                                left join biblioitems on biblio.biblionumber = 
biblioitems.biblionumber
+                                                               left join 
itemtypes on (biblioitems.itemtype=itemtypes.itemtype)
                                                                where 
biblio.biblionumber = ?
                                                                and 
biblioitems.biblionumber = biblio.biblionumber");
        $sth->execute($bibnum);
@@ -1470,11 +1511,11 @@
        $sth   = $dbh->prepare("Select * from bibliosubtitle where biblionumber 
= ?");
        $sth->execute($bibnum);
        my @subtitles;
-       while (my $dat = $sth->fetchrow_hashref){
-               my %line;
-               $line{subtitle} = $dat->{subtitle};
-               push @subtitles, \%line;
-       } # while
+#      while (my $dat = $sth->fetchrow_hashref){
+#              my %line;
+#              $line{subtitle} = $dat->{subtitle};
+#              push @subtitles, \%line;
+#      } # while
        $data->{subtitles} = address@hidden;
        $sth->finish;
        $sth   = $dbh->prepare("Select * from bibliosubject where biblionumber 
= ?");
@@ -1703,11 +1744,6 @@
                 $data->{"timestamp$i2"} = $data2->{'timestamp'};
                 $data->{"card$i2"}      = $data2->{'cardnumber'};
                 $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
-                $data->{"date_due$i2"} = $data2->{'date_due'};
-                $data->{"returndate$i2"} = $data2->{"returndate"};
-                $data->{"issue_date$i2"} = $data2->{"issue_date"};
-                $data->{"surname$i2"} = $data2->{"surname"};
-                $data->{"firstname$i2"} = $data2->{"firstname"};
             } # if
         } # for
 
@@ -1880,6 +1916,13 @@
   my $data=$sth->fetchrow_hashref;
   $sth->finish;
   if ($data) {
+       my $sth=$dbh->prepare("select ( -1 * sum(amountoutstanding)) from 
accountlines where borrowernumber=?  ");
+       $sth->execute($data->{'borrowernumber'});
+       ($data->{'finestillowed'}) = $sth->fetchrow_array;
+       $sth=$dbh->prepare("select ( -1 * sum(amount)) from accountlines where 
borrowernumber=? and date = curdate() and accounttype in ( 'Pay','C','FOR')");
+       $sth->execute($data->{'borrowernumber'});
+       ($data->{'finepaidtoday'}) = $sth->fetchrow_array;
+
        return($data);
        } else { # try with firstname
                if ($cardnumber) {
@@ -1910,7 +1953,7 @@
 sub borrissues {
   my ($bornum)address@hidden;
   my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from issues,biblio,items where 
borrowernumber=?
+  my $sth=$dbh->prepare("Select *, issues.issue_date as date_issued from 
issues,biblio,items where borrowernumber=?
    and items.itemnumber=issues.itemnumber
        and items.biblionumber=biblio.biblionumber
        and issues.returndate is NULL order by date_due");
@@ -2659,7 +2702,8 @@
                #warn "subfields:".join " ", @$subfields;
                my $counter = 0;
                my @link_loop;
-               for my $subject_subfield (@subfields ) {
+               foreach my $subject_subfield (@subfields ) {
+                       next if ($subject_subfield->[0] == 9 ); # FIXME we're 
hardcoding this....
                my $code = $subject_subfield->[0];
                my $value = $subject_subfield->[1];
                        my $linkvalue = $value;
@@ -2705,13 +2749,6 @@
         my $counter = 0;
         my @link_loop;
         for my $series_subfield (@subfields ) {
-                       my $volume_number;
-                       undef $volume_number;
-                       # see if this is an instance of a volume
-                       if ($series_subfield->[0] eq 'v') {
-                               $volume_number=1;
-                       }
-
             my $code = $series_subfield->[0];
             my $value = $series_subfield->[1];
             my $linkvalue = $value;
@@ -2719,12 +2756,7 @@
             my $operator = " and " unless $counter==0;
             push @link_loop, {link => $linkvalue, operator => $operator };
             my $separator = C4::Context->preference("authoritysep") unless 
$counter==0;
-                       if ($volume_number) {
-                       push @subfields_loop, {volumenum => $value};
-                       }
-                       else {
-            push @subfields_loop, {code => $code, value => $value, link_loop 
=> address@hidden, separator => $separator, volumenum => $volume_number};
-                       }
+            push @subfields_loop, {code => $code, value => $value, link_loop 
=> address@hidden, separator => $separator};
             $counter++;
         }
         push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => address@hidden };
@@ -2740,24 +2772,26 @@
 
 sub getMARCurls {
     my ($dbh, $bibid, $marcflavour) = @_;
-       my ($mintag, $maxtag);
-       if ($marcflavour eq "MARC21") {
-               $mintag = "856";
-               $maxtag = "856";
-       } else {           # assume unimarc if not marc21
-               $mintag = "600";
-               $maxtag = "619";
-       }
+#      my ($mintag, $maxtag);
+#      if ($marcflavour eq "MARC21") {
+#              $mintag = "856";
+#              $maxtag = "856";
+#      } else {           # assume unimarc if not marc21
+#              $mintag = "600";
+#              $maxtag = "619";
+#      }
 
-       my $record=MARCgetbiblio($dbh,$bibid);
+       my $record=MARCgetbiblio($dbh,$bibid); # unless $record;
        my @marcurls;
        my $url = "";
        my $subfil = "";
        my $marcurl;
        foreach my $field ($record->field('856')) {
                my $value = $field->subfield('u');
+               my $linktext = $field->subfield('y');
                if ( $value ne $url) {
-                   $marcurl = {MARCURL => $value,};
+                   $marcurl = {MARCURL => $value, LINKTEXT => $linktext};
+       #               warn $linktext . " - " .  $value;
                        push @marcurls, $marcurl;
                        $url = $value;
                }
@@ -2853,8 +2887,8 @@
                {
         link_value => 'branch',
         label_value => 'Branches',
-        tags => ['952',],
-        subfield => 'b',
+        tags => ['959',],
+        subfield => 'n',
                expanded => '1',
         },
        ];
@@ -3162,7 +3196,7 @@
             #$limit_search_desc.=" and available";
         }
         # these queries are treated as OR
-        elsif (($limit_query) && ($limit =~/mc/)) {
+        elsif (  ($limit =~/w/ ) or ( ($limit_query) && ($limit =~/mc/) ) ) {
             $limit_query.=" or $limit" if $limit;
             $limit_search_desc.=" or $limit" if $limit;
         }
@@ -3244,7 +3278,6 @@
                        my $stemmed_operand;
 
                        if ($operands[$i]) {
-                               $operand =~ s/^(and |or |not )//i;
 
                                # STEMMING FIXME: need to refine the field 
weighting so stemmed operands don't disrupt the query ranking
                                if ($stemming) { 
@@ -3404,7 +3437,7 @@
        $human_search_desc =~ s/  / /g;
        $human_search_desc =~s/^ //g;   
        my $koha_query = $query;
-       #warn "QUERY:".$koha_query;
+       warn "QUERY:".$koha_query;
        #warn "SEARCHDESC:".$human_search_desc;
        #warn "FEDERATED QUERY:".$federated_query;
     return (undef,$human_search_desc,$koha_query,$federated_query);
@@ -3414,7 +3447,7 @@
 # building the HTML output for the template
 sub searchResults {
     my 
($searchdesc,$hits,$results_per_page,$offset,@marcresults)address@hidden;
-       #warn "HITS:$hits\n";
+       warn "HITS:$hits\n";
     my $dbh= C4::Context->dbh;
     my $toggle;
     my $even=1;
@@ -3520,25 +3553,29 @@
                                $onloan_count++;
                                $norequests = 0;
                        }
-                       # holdingbranch first, then homebranch
+                       # homebranch first, then holdingbranch:q
                        #
                        else {
                                $norequests = 0;
-                               if ($item->{'holdingbranch'}) {
-                                       
$items->{$item->{'holdingbranch'}}->{count}++;
+                               if ($item->{'homebranch'}) {
+                                       
$items->{$item->{'homebranch'}}->{count}++;
                                }
                                # Last resort
-                               elsif ($item->{'homebranch'}) {
+                               elsif ($item->{'holdingbranch'}) {
                                        
$items->{$item->{'homebranch'}}->{count}++;
                                }
                        }
-               } # notforloan, item level and biblioitem level
-
-               # Now check itemtype for not for loan info
                my $itemtype_sth = $dbh->prepare("SELECT notforloan FROM 
itemtypes WHERE itemtype=?");
+               if (C4::Context->preference("item-level_itypes")) {
+                       $itemtype_sth->execute($item->{itype});
+               } else {
                $itemtype_sth->execute($oldbiblio->{itemtype});
+               }
                my $itemtype_notforloan = $itemtype_sth->fetchrow();
                $norequests = 1 if $itemtype_notforloan;
+               } # notforloan, item level and biblioitem level
+
+               # Now check itemtype for not for loan info
 
                #my @koha_items = &ItemInfo(undef, $biblionumber, 'opac');
                #for my $koha_item (@koha_items) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]