* moving generic functions to Koha.pm
* improvement of SearchMarc.pm * bugfixes * code cleaning
This commit is contained in:
parent
05e5034932
commit
1b0620652e
4 changed files with 152 additions and 31 deletions
27
C4/Biblio.pm
27
C4/Biblio.pm
|
@ -1,6 +1,12 @@
|
|||
package C4::Biblio;
|
||||
# $Id$
|
||||
# $Log$
|
||||
# Revision 1.39 2003/03/07 16:35:42 tipaul
|
||||
# * moving generic functions to Koha.pm
|
||||
# * improvement of SearchMarc.pm
|
||||
# * bugfixes
|
||||
# * code cleaning
|
||||
#
|
||||
# Revision 1.38 2003/02/27 16:51:59 tipaul
|
||||
# * moving prepare / execute to ? form.
|
||||
# * some # cleaning
|
||||
|
@ -1279,16 +1285,11 @@ sub OLDmodbiblio {
|
|||
} # sub modbiblio
|
||||
|
||||
sub OLDmodsubtitle {
|
||||
my ($dbh,$bibnum, $subtitle) = @_;
|
||||
# my $dbh = C4Connect;
|
||||
my $query = "update bibliosubtitle set
|
||||
subtitle = '$subtitle'
|
||||
where biblionumber = $bibnum";
|
||||
my $sth = $dbh->prepare($query);
|
||||
|
||||
$sth->execute;
|
||||
$sth->finish;
|
||||
# $dbh->disconnect;
|
||||
my ($dbh,$bibnum, $subtitle) = @_;
|
||||
my $query = "update bibliosubtitle set subtitle = ? where biblionumber = ?";
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute($subtitle,$bibnum);
|
||||
$sth->finish;
|
||||
} # sub modsubtitle
|
||||
|
||||
|
||||
|
@ -1303,11 +1304,11 @@ sub OLDmodaddauthor {
|
|||
|
||||
if ($author ne '') {
|
||||
$query = "Insert into additionalauthors set
|
||||
author = '$author',
|
||||
biblionumber = '$bibnum'";
|
||||
author = ?,
|
||||
biblionumber = ?";
|
||||
$sth = $dbh->prepare($query);
|
||||
|
||||
$sth->execute;
|
||||
$sth->execute($author,$bibnum);
|
||||
|
||||
$sth->finish;
|
||||
} # if
|
||||
|
|
92
C4/Koha.pm
92
C4/Koha.pm
|
@ -55,6 +55,8 @@ Koha.pm provides many functions for Koha scripts.
|
|||
&borrowercategories
|
||||
ðnicitycategories
|
||||
&subfield_is_koha_internal_p
|
||||
&getbranches &getprinters
|
||||
&getbranch &getprinter
|
||||
$DEBUG);
|
||||
|
||||
use vars qw();
|
||||
|
@ -162,6 +164,96 @@ sub subfield_is_koha_internal_p ($) {
|
|||
return length $subfield != 1;
|
||||
}
|
||||
|
||||
=item getbranches
|
||||
|
||||
$branches = &getbranches();
|
||||
@branch_codes = keys %$branches;
|
||||
%main_branch_info = %{$branches->{"MAIN"}};
|
||||
|
||||
Returns information about existing library branches.
|
||||
|
||||
C<$branches> is a reference-to-hash. Its keys are the branch codes for
|
||||
all of the existing library branches, and its values are
|
||||
references-to-hash describing that particular branch.
|
||||
|
||||
In each branch description (C<%main_branch_info>, above), there is a
|
||||
key for each field in the branches table of the Koha database. In
|
||||
addition, there is a key for each branch category code to which the
|
||||
branch belongs (the category codes are taken from the branchrelations
|
||||
table).
|
||||
|
||||
=cut
|
||||
|
||||
sub getbranches {
|
||||
# returns a reference to a hash of references to branches...
|
||||
my %branches;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $sth=$dbh->prepare("select * from branches");
|
||||
$sth->execute;
|
||||
while (my $branch=$sth->fetchrow_hashref) {
|
||||
my $query = "select categorycode from branchrelations where branchcode = ?";
|
||||
my $nsth = $dbh->prepare($query);
|
||||
$nsth->execute($branch->{'branchcode'});
|
||||
while (my ($cat) = $nsth->fetchrow_array) {
|
||||
# FIXME - This seems wrong. It ought to be
|
||||
# $branch->{categorycodes}{$cat} = 1;
|
||||
# otherwise, there's a namespace collision if there's a
|
||||
# category with the same name as a field in the 'branches'
|
||||
# table (i.e., don't create a category called "issuing").
|
||||
# In addition, the current structure doesn't really allow
|
||||
# you to list the categories that a branch belongs to:
|
||||
# you'd have to list keys %$branch, and remove those keys
|
||||
# that aren't fields in the "branches" table.
|
||||
$branch->{$cat} = 1;
|
||||
}
|
||||
$branches{$branch->{'branchcode'}}=$branch;
|
||||
}
|
||||
return (\%branches);
|
||||
}
|
||||
|
||||
=item getprinters
|
||||
|
||||
$printers = &getprinters($env);
|
||||
@queues = keys %$printers;
|
||||
|
||||
Returns information about existing printer queues.
|
||||
|
||||
C<$env> is ignored.
|
||||
|
||||
C<$printers> is a reference-to-hash whose keys are the print queues
|
||||
defined in the printers table of the Koha database. The values are
|
||||
references-to-hash, whose keys are the fields in the printers table.
|
||||
|
||||
=cut
|
||||
|
||||
sub getprinters {
|
||||
my ($env) = @_;
|
||||
my %printers;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $sth=$dbh->prepare("select * from printers");
|
||||
$sth->execute;
|
||||
while (my $printer=$sth->fetchrow_hashref) {
|
||||
$printers{$printer->{'printqueue'}}=$printer;
|
||||
}
|
||||
return (\%printers);
|
||||
}
|
||||
sub getbranch ($$) {
|
||||
my($query, $branches) = @_; # get branch for this query from branches
|
||||
my $branch = $query->param('branch');
|
||||
($branch) || ($branch = $query->cookie('branch'));
|
||||
($branches->{$branch}) || ($branch=(keys %$branches)[0]);
|
||||
return $branch;
|
||||
}
|
||||
|
||||
sub getprinter ($$) {
|
||||
my($query, $printers) = @_; # get printer for this query from printers
|
||||
my $printer = $query->param('printer');
|
||||
($printer) || ($printer = $query->cookie('printer'));
|
||||
($printers->{$printer}) || ($printer = (keys %$printers)[0]);
|
||||
return $printer;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
|
16
C4/Search.pm
16
C4/Search.pm
|
@ -1443,18 +1443,16 @@ sub bibdata {
|
|||
from biblio, biblioitems
|
||||
left join bibliosubtitle on
|
||||
biblio.biblionumber = bibliosubtitle.biblionumber
|
||||
where biblio.biblionumber = $bibnum
|
||||
and biblioitems.biblionumber = $bibnum";
|
||||
where biblio.biblionumber = ?
|
||||
and biblioitems.biblionumber = biblio.biblionumber";
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute($bibnum);
|
||||
my $data;
|
||||
|
||||
$sth->execute;
|
||||
$data = $sth->fetchrow_hashref;
|
||||
$sth->finish;
|
||||
|
||||
$query = "Select * from bibliosubject where biblionumber = '$bibnum'";
|
||||
$query = "Select * from bibliosubject where biblionumber = ?";
|
||||
$sth = $dbh->prepare($query);
|
||||
$sth->execute;
|
||||
$sth->execute($bibnum);
|
||||
while (my $dat = $sth->fetchrow_hashref){
|
||||
$data->{'subject'} .= " , $dat->{'subject'}";
|
||||
} # while
|
||||
|
@ -1506,9 +1504,9 @@ elements in C<$subjects>.
|
|||
sub subject {
|
||||
my ($bibnum)=@_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $query="Select * from bibliosubject where biblionumber=$bibnum";
|
||||
my $query="Select * from bibliosubject where biblionumber=?";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
$sth->execute($bibnum);
|
||||
my @results;
|
||||
my $i=0;
|
||||
while (my $data=$sth->fetchrow_hashref){
|
||||
|
|
|
@ -70,27 +70,57 @@ sub catalogsearch {
|
|||
my $sql_where1; # will contain the "true" where
|
||||
my $sql_where2; # will contain m1.bibid=m2.bibid
|
||||
my $nb=1;
|
||||
for(my $i=0; $i<=@$tags;$i++) {
|
||||
if (@$tags[$i] && @$value[$i]) {
|
||||
$sql_tables .= "marc_subfield_table as m$nb,";
|
||||
warn "value : ".@$value;
|
||||
for(my $i=0; $i<=@$value;$i++) {
|
||||
if (@$value[$i]) {
|
||||
if ($nb==1) {
|
||||
if (@$operator[$i] eq "starts") {
|
||||
$sql_where1 .= "@$excluding[$i](m1.subfieldvalue like '@$value[$i] %' and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_subfield_table as m$nb,";
|
||||
$sql_where1 .= "@$excluding[$i](m1.subfieldvalue like '@$value[$i]%'";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]'";
|
||||
}
|
||||
$sql_where1.=")";
|
||||
} elsif (@$operator[$i] eq "contains") {
|
||||
$sql_where1 .= "@$excluding[$i](m1.subfieldvalue like '%@$value[$i]%' and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_word as m$nb,";
|
||||
$sql_where1 .= "@$excluding[$i](m1.word ='@$value[$i]'";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldid='@$subfields[$i]'";
|
||||
}
|
||||
$sql_where1.=")";
|
||||
} else {
|
||||
$sql_where1 .= "@$excluding[$i](m1.subfieldvalue @$operator[$i] '@$value[$i]' and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_subfield_table as m$nb,";
|
||||
$sql_where1 .= "@$excluding[$i](m1.subfieldvalue @$operator[$i] '@$value[$i]' ";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]'";
|
||||
}
|
||||
$sql_where1.=")";
|
||||
}
|
||||
} else {
|
||||
if (@$operator[$i] eq "starts") {
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue like '@$value[$i]%' and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_subfield_table as m$nb,";
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue like '@$value[$i]%'";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i])";
|
||||
}
|
||||
$sql_where1.=")";
|
||||
$sql_where2 .= "m1.bibid=m$nb.bibid";
|
||||
} elsif (@$operator[$i] eq "contains") {
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue like '%@$value[$i]%' and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_word as m$nb,";
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.word='@$value[$i]'";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldid='@$subfields[$i]'";
|
||||
}
|
||||
$sql_where1.=")";
|
||||
$sql_where2 .= "m1.bibid=m$nb.bibid";
|
||||
} else {
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue @$operator[$i] '@$value[$i]' and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i]')";
|
||||
$sql_tables .= "marc_subfield_table as m$nb,";
|
||||
$sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue @$operator[$i] '@$value[$i]'";
|
||||
if (@$tags[$i]) {
|
||||
$sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i]'";
|
||||
}
|
||||
$sql_where2 .= "m1.bibid=m$nb.bibid";
|
||||
$sql_where1.=")";
|
||||
}
|
||||
}
|
||||
$nb++;
|
||||
|
|
Loading…
Reference in a new issue