&FindDuplicate
&SimpleSearch
&searchResults
+ &SearchAcquisitions
&getRecords
&buildQuery
&NZgetRecords
unless ( $index =~ /(st-|phr|ext)/ ) {
#FIXME only valid with LTR scripts
$operand=join(" ",map{
- "$_*"
+ (index($_,"*")>0?"$_":"$_*")
}split (/\s+/,$operand));
warn $operand if $DEBUG;
}
my $group_OR_limits;
my $availability_limit;
foreach my $this_limit (@limits) {
- if ( $this_limit =~ /available/ ) {
-
-# 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
-# In English:
-# all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
- $availability_limit .=
-"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
- $limit_cgi .= "&limit=available";
- $limit_desc .= "";
- }
-
+# if ( $this_limit =~ /available/ ) {
+#
+## 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
+## In English:
+## all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
+# $availability_limit .=
+#"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
+# $limit_cgi .= "&limit=available";
+# $limit_desc .= "";
+# }
+#
# group_OR_limits, prefixed by mc-
# OR every member of the group
- elsif ( $this_limit =~ /mc/ ) {
+# elsif ( $this_limit =~ /mc/ ) {
+ if ( $this_limit =~ /mc/ ) {
$group_OR_limits .= " or " if $group_OR_limits;
$limit_desc .= " or " if $group_OR_limits;
$group_OR_limits .= "$this_limit";
# IMO this subroutine is pretty messy still -- it's responsible for
# building the HTML output for the template
sub searchResults {
- my ( $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults ) = @_;
+ my ( $searchdesc, $hits, $results_per_page, $offset, $scan,
+ $limit_available, $hidelostitems, @marcresults) = @_;
+
my $dbh = C4::Context->dbh;
my @newresults;
if ( $itemtypes{ $oldbiblio->{itemtype} }->{summary} ) {
my $summary = $itemtypes{ $oldbiblio->{itemtype} }->{summary};
my @fields = $marcrecord->fields();
- foreach my $field (@fields) {
- my $tag = $field->tag();
- my $tagvalue = $field->as_string();
- if (! utf8::is_utf8($tagvalue)) {
- utf8::decode($tagvalue);
+
+ my $newsummary;
+ foreach my $line ( "$summary\n" =~ /(.*)\n/g ){
+ my $tags = {};
+ foreach my $tag ( $line =~ /\[(\d{3}[\w|\d])\]/ ) {
+ $tag =~ /(.{3})(.)/;
+ if($marcrecord->field($1)){
+ my @abc = $marcrecord->field($1)->subfield($2);
+ $tags->{$tag} = $#abc + 1 ;
+ }
}
-
- $summary =~
- s/\[(.?.?.?.?)$tag\*(.*?)]/$1$tagvalue$2\[$1$tag$2]/g;
- unless ( $tag < 10 ) {
- my @subf = $field->subfields;
- for my $i ( 0 .. $#subf ) {
- my $subfieldcode = $subf[$i][0];
- my $subfieldvalue = $subf[$i][1];
- if (! utf8::is_utf8($subfieldvalue)) {
- utf8::decode($subfieldvalue);
+
+ # We catch how many times to repeat this line
+ my $max = 0;
+ foreach my $tag (keys(%$tags)){
+ $max = $tags->{$tag} if($tags->{$tag} > $max);
+ }
+
+ # we replace, and repeat each line
+ for (my $i = 0 ; $i < $max ; $i++){
+ my $newline = $line;
+
+ foreach my $tag ( $newline =~ /\[(\d{3}[\w|\d])\]/g ) {
+ $tag =~ /(.{3})(.)/;
+
+ if($marcrecord->field($1)){
+ my @repl = $marcrecord->field($1)->subfield($2);
+ my $subfieldvalue = $repl[$i];
+
+ if (! utf8::is_utf8($subfieldvalue)) {
+ utf8::decode($subfieldvalue);
+ }
+
+ $newline =~ s/\[$tag\]/$subfieldvalue/g;
}
- my $tagsubf = $tag . $subfieldcode;
- $summary =~
-s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
}
+ $newsummary .= "$newline\n";
}
}
- # FIXME: yuk
- $summary =~ s/\[(.*?)]//g;
- $summary =~ s/\n/<br\/>/g;
- $oldbiblio->{summary} = $summary;
+
+ $newsummary =~ s/\[(.*?)]//g;
+ $newsummary =~ s/\n/<br\/>/g;
+ $oldbiblio->{summary} = $newsummary;
}
# Pull out the items fields
foreach my $code ( keys %subfieldstosearch ) {
$item->{$code} = $field->subfield( $subfieldstosearch{$code} );
}
+
my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch';
my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
# set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one
my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
- if ( $item->{onloan} or $item->{reserved} ) {
+ if ( ($item->{onloan} or $item->{reserved} ) and not $limit_available) {
$onloan_count++;
my $key = $prefix . $item->{onloan} . $item->{barcode};
$onloan_items->{$key}->{due_date} = format_date($item->{onloan});
$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
$onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
$onloan_items->{$key}->{barcode} = $item->{barcode};
+ $onloan_items->{$key}->{reserved} = $item->{reserved};
# if something's checked out and lost, mark it as 'long overdue'
if ( $item->{itemlost} ) {
$onloan_items->{$prefix}->{longoverdue}++;
# item is withdrawn, lost or damaged
if ( $item->{wthdrawn}
- || $item->{itemlost}
+ || ($item->{itemlost} and not $hidelostitems)
|| $item->{damaged}
|| $item->{notforloan}
|| $item->{reserved}
( C4::Context->preference('maxItemsinSearchResults') )
? C4::Context->preference('maxItemsinSearchResults') - 1
: 1;
- for my $key ( sort keys %$onloan_items ) {
- (++$onloanitemscount > $maxitems) and last;
- push @onloan_items_loop, $onloan_items->{$key};
- }
- for my $key ( sort keys %$other_items ) {
- (++$otheritemscount > $maxitems) and last;
- push @other_items_loop, $other_items->{$key};
+
+ if(! $limit_available){
+ for my $key ( sort keys %$onloan_items) {
+ (++$onloanitemscount > $maxitems) and last;
+ push @onloan_items_loop, $onloan_items->{$key};
+ }
+
+ for my $key ( sort keys %$other_items ) {
+ (++$otheritemscount > $maxitems) and last;
+ push @other_items_loop, $other_items->{$key};
+ }
}
for my $key ( sort keys %$notforloan_items ) {
(++$notforloanitemscount > $maxitems) and last;
(++$availableitemscount > $maxitems) and last;
push @available_items_loop, $available_items->{$key}
}
-
# XSLT processing of some stuff
if (C4::Context->preference("XSLTResultsDisplay") && !$scan) {
$oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
$oldbiblio->{orderedcount} = $ordered_count;
$oldbiblio->{isbn} =~
s/-//g; # deleting - in isbn to enable amazon content
- push( @newresults, $oldbiblio );
+ push( @newresults, $oldbiblio ) if ((not $limit_available and ($items_count))
+ or ($limit_available and $available_count));
+
+ #if((not $hidelostitems and not $limit_available )
+ #or ($items_count > $itemlost_count and $available_count ));
+ #($items_count > $itemlost_count) )
+ #or (or ($available_count and $limit_available))
+ #);
+ #+ $onloan_count ) )
+ # && ( $hidelostitems or $limit_available ))
+ # );
+
}
+
return @newresults;
}
+=head2 SearchAcquisitions
+ Search for acquisitions
+=cut
+
+sub SearchAcquisitions{
+ my ($datebegin, $dateend, $itemtypes,$criteria, $orderby) = @_;
+
+ my $dbh=C4::Context->dbh;
+ # Variable initialization
+ my $str=qq|
+ SELECT marcxml
+ FROM biblio
+ LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
+ LEFT JOIN items ON items.biblionumber=biblio.biblionumber
+ WHERE dateaccessioned BETWEEN ? AND ?
+ |;
+
+ my (@params,@loopcriteria);
+
+ push @params, $datebegin->output("iso");
+ push @params, $dateend->output("iso");
+
+ if (scalar(@$itemtypes)>0 and $criteria ne "itemtype" ){
+ if(C4::Context->preference("item-level_itypes")){
+ $str .= "AND items.itype IN (?".( ',?' x scalar @$itemtypes - 1 ).") ";
+ }else{
+ $str .= "AND biblioitems.itemtype IN (?".( ',?' x scalar @$itemtypes - 1 ).") ";
+ }
+ push @params, @$itemtypes;
+ }
+
+ if ($criteria =~/itemtype/){
+ if(C4::Context->preference("item-level_itypes")){
+ $str .= "AND items.itype=? ";
+ }else{
+ $str .= "AND biblioitems.itemtype=? ";
+ }
+
+ if(scalar(@$itemtypes) == 0){
+ my $itypes = GetItemTypes();
+ for my $key (keys %$itypes){
+ push @$itemtypes, $key;
+ }
+ }
+
+ @loopcriteria= @$itemtypes;
+ }elsif ($criteria=~/itemcallnumber/){
+ $str .= "AND (items.itemcallnumber LIKE CONCAT(?,'%')
+ OR items.itemcallnumber is NULL
+ OR items.itemcallnumber = '')";
+
+ @loopcriteria = ("AA".."ZZ", "") unless (scalar(@loopcriteria)>0);
+ }else {
+ $str .= "AND biblio.title LIKE CONCAT(?,'%') ";
+ @loopcriteria = ("A".."z") unless (scalar(@loopcriteria)>0);
+ }
+
+ if ($orderby =~ /date_desc/){
+ $str.=" ORDER BY dateaccessioned DESC";
+ } else {
+ $str.=" ORDER BY title";
+ }
+
+ my $qdataacquisitions=$dbh->prepare($str);
+
+ my @loopacquisitions;
+ foreach my $value(@loopcriteria){
+ push @params,$value;
+ my %cell;
+ $cell{"title"}=$value;
+ $cell{"titlecode"}=$value;
+
+ eval{$qdataacquisitions->execute(@params);};
+
+ if ($@){ warn "recentacquisitions Error :$@";}
+ else {
+ my @loopdata;
+ while (my $data=$qdataacquisitions->fetchrow_hashref){
+ push @loopdata, {"summary"=>GetBiblioSummary( $data->{'marcxml'} ) };
+ }
+ $cell{"loopdata"}=\@loopdata;
+ }
+ push @loopacquisitions,\%cell if (scalar(@{$cell{loopdata}})>0);
+ pop @params;
+ }
+ $qdataacquisitions->finish;
+ return \@loopacquisitions;
+}
+
#----------------------------------------------------------------------
#
# Non-Zebra GetRecords#
);
# split each word, query the DB and build the biblionumbers result
- foreach ( split / /, $string ) {
+ foreach ( split (/ /, $string )) {
next if C4::Context->stopwords->{ uc($_) }; # skip if stopword
warn "search on all indexes on $_" if $DEBUG;
my $biblionumbers;
sub NZoperatorAND{
my ($rightresult, $leftresult)=@_;
- my @leftresult = split /;/, $leftresult;
+ my @leftresult = split (/;/, $leftresult);
warn " @leftresult / $rightresult \n" if $DEBUG;
# my @rightresult = split /;/,$leftresult;
# popularity is not in MARC record, it's builded from a specific query
my $sth =
$dbh->prepare("select sum(issues) from items where biblionumber=?");
- foreach ( split /;/, $biblionumbers ) {
- my ( $biblionumber, $title ) = split /,/, $_;
+ foreach ( split (/;/, $biblionumbers )) {
+ my ( $biblionumber, $title ) = split (/,/, $_);
$result{$biblionumber} = GetMarcBiblio($biblionumber);
$sth->execute($biblionumber);
my $popularity = $sth->fetchrow || 0;
}
elsif ( $ordering =~ /author/ ) {
my %result;
- foreach ( split /;/, $biblionumbers ) {
- my ( $biblionumber, $title ) = split /,/, $_;
+ foreach ( split (/;/, $biblionumbers )) {
+ my ( $biblionumber, $title ) = split (/,/, $_);
my $record = GetMarcBiblio($biblionumber);
my $author;
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
}
elsif ( $ordering =~ /callnumber/ ) {
my %result;
- foreach ( split /;/, $biblionumbers ) {
- my ( $biblionumber, $title ) = split /,/, $_;
+ foreach ( split (/;/, $biblionumbers )) {
+ my ( $biblionumber, $title ) = split (/,/, $_);
my $record = GetMarcBiblio($biblionumber);
my $callnumber;
my ( $callnumber_tag, $callnumber_subfield ) =
}
elsif ( $ordering =~ /pubdate/ ) { #pub year
my %result;
- foreach ( split /;/, $biblionumbers ) {
- my ( $biblionumber, $title ) = split /,/, $_;
+ foreach ( split (/;/, $biblionumbers )) {
+ my ( $biblionumber, $title ) = split (/,/, $_);
my $record = GetMarcBiblio($biblionumber);
my ( $publicationyear_tag, $publicationyear_subfield ) =
GetMarcFromKohaField( 'biblioitems.publicationyear', '' );
# the title is in the biblionumbers string, so we just need to build a hash, sort it and return
my %result;
- foreach ( split /;/, $biblionumbers ) {
- my ( $biblionumber, $title ) = split /,/, $_;
+ foreach ( split (/;/, $biblionumbers )) {
+ my ( $biblionumber, $title ) = split (/,/, $_);
# hint : the result is sorted by title.biblionumber because we can have X biblios with the same title
# and we don't want to get only 1 result for each of them !!!