X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FClassSource.pm;h=245f9589c64e8accf934b3345a7d2d4765b5450b;hb=3ee3cf10e61aaad8a47881fdc6cc565e74c847af;hp=8d8478d10d928f8f78f10b5af88824a9f1de5f5f;hpb=43d3efe39175488ee81e8c6dd4cddaefb1f3f9e3;p=koha.git diff --git a/C4/ClassSource.pm b/C4/ClassSource.pm index 8d8478d10d..245f9589c6 100644 --- a/C4/ClassSource.pm +++ b/C4/ClassSource.pm @@ -4,28 +4,28 @@ package C4::ClassSource; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; +use warnings; + require Exporter; use C4::Context; -use C4::Koha; +use C4::ClassSortRoutine; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); +use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); -# set the version for version checking -$VERSION = 3.00; =head1 NAME @@ -47,18 +47,20 @@ sources and sorting rules. @ISA = qw(Exporter); @EXPORT = qw( - &GetClassSources - &AddClassSource - &GetClassSource - &ModClassSource - &DelClassSource - &GetClassSortRules - &AddClassSortRule - &GetClassSortRule - &ModClassSortRule - &DelClassSortRule + &GetClassSources + &AddClassSource + &GetClassSource + &ModClassSource + &DelClassSource + &GetClassSortRules + &AddClassSortRule + &GetClassSortRule + &ModClassSortRule + &DelClassSortRule - &GetSourcesForSortRule + &GetSourcesForSortRule + &GetClassSort + ); =head2 GetClassSources @@ -89,12 +91,11 @@ sub GetClassSources { my %class_sources = (); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources`"); + my $sth = $dbh->prepare("SELECT * FROM `class_sources`"); $sth->execute(); while (my $source = $sth->fetchrow_hashref) { $class_sources{ $source->{'cn_source'} } = $source; } - $sth->finish(); return \%class_sources; @@ -111,13 +112,16 @@ sub GetClassSources { sub AddClassSource { my ($cn_source, $description, $used, $class_sort_rule) = @_; + my $exists = GetClassSource($cn_source); + if ($exists) { + return 0; + } my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("INSERT INTO `class_sources` + my $sth = $dbh->prepare("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES (?, ?, ?, ?)"); $sth->execute($cn_source, $description, $used, $class_sort_rule); - $sth->finish(); - + return 1; } =head2 GetClassSource @@ -132,10 +136,9 @@ sub GetClassSource { my ($cn_source) = (@_); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources` WHERE cn_source = ?"); + my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?"); $sth->execute($cn_source); my $row = $sth->fetchrow_hashref(); - $sth->finish(); return $row; } @@ -151,13 +154,12 @@ sub ModClassSource { my ($cn_source, $description, $used, $class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("UPDATE `class_sources` + my $sth = $dbh->prepare("UPDATE `class_sources` SET `description` = ?, `used` = ?, `class_sort_rule` = ? WHERE `cn_source` = ?"); $sth->execute($description, $used, $class_sort_rule, $cn_source); - $sth->finish(); } @@ -173,9 +175,8 @@ sub DelClassSource { my ($cn_source) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("DELETE FROM `class_sources` WHERE `cn_source` = ?"); + my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?"); $sth->execute($cn_source); - $sth->finish(); } @@ -183,22 +184,22 @@ sub DelClassSource { my $sort_rules = GetClassSortRules(); - Returns reference to hash of references to - the class sorting rules, keyed on class_sort_rule - +Returns reference to hash of references to +the class sorting rules, keyed on class_sort_rule + =head3 Example -my $sort_rules = GetClassSortRules(); -my @sort_rules = (); -foreach my $sort_rule (sort keys %$sort_rules) { - my $sort_rule = $sort_rules->{$sort_rule}; - push @sort_rules, - { - rule => $sort_rule->{'class_sort_rule'}, - description => $sort_rule->{'description'}, - sort_routine => $sort_rule->{'sort_routine'} + my $sort_rules = GetClassSortRules(); + my @sort_rules = (); + foreach my $sort_rule (sort keys %$sort_rules) { + my $sort_rule = $sort_rules->{$sort_rule}; + push @sort_rules, + { + rule => $sort_rule->{'class_sort_rule'}, + description => $sort_rule->{'description'}, + sort_routine => $sort_rule->{'sort_routine'} } -} + } =cut @@ -206,12 +207,11 @@ sub GetClassSortRules { my %class_sort_rules = (); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules`"); + my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`"); $sth->execute(); while (my $sort_rule = $sth->fetchrow_hashref) { $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule; } - $sth->finish(); return \%class_sort_rules; @@ -228,13 +228,16 @@ sub GetClassSortRules { sub AddClassSortRule { my ($class_sort_rule, $description, $sort_routine) = @_; + my $exists = GetClassSortRule($class_sort_rule); + if ($exists) { + return 0; + } my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("INSERT INTO `class_sort_rules` + my $sth = $dbh->prepare("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES (?, ?, ?)"); $sth->execute($class_sort_rule, $description, $sort_routine); - $sth->finish(); - + return 1; } =head2 GetClassSortRule @@ -249,10 +252,9 @@ sub GetClassSortRule { my ($class_sort_rule) = (@_); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); + my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); $sth->execute($class_sort_rule); my $row = $sth->fetchrow_hashref(); - $sth->finish(); return $row; } @@ -268,12 +270,11 @@ sub ModClassSortRule { my ($class_sort_rule, $description, $sort_routine) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("UPDATE `class_sort_rules` + my $sth = $dbh->prepare("UPDATE `class_sort_rules` SET `description` = ?, `sort_routine` = ? WHERE `class_sort_rule` = ?"); $sth->execute($description, $sort_routine, $class_sort_rule); - $sth->finish(); } @@ -289,9 +290,8 @@ sub DelClassSortRule { my ($class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); + my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); $sth->execute($class_sort_rule); - $sth->finish(); } @@ -309,21 +309,49 @@ sub GetSourcesForSortRule { my ($class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?"); + my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?"); $sth->execute($class_sort_rule); my @sources = (); while (my ($source) = $sth->fetchrow_array()) { push @sources, $source; } - $sth->finish(); return @sources; } +=head2 GetClassSort + + my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item); + +Get the sort key corresponding to the classification part and item part +and the defined call number source. + +=cut + +sub GetClassSort { + + my ($cn_source, $cn_class, $cn_item) = @_; + + my $source_ref = GetClassSource($cn_source); + unless (defined $source_ref) { + $source_ref = GetClassSource(C4::Context->preference("DefaultClassificationSource")); + } + my $routine = ""; + if (defined $source_ref) { + my $rule_ref = GetClassSortRule($source_ref->{'class_sort_rule'}); + if (defined $rule_ref) { + $routine = $rule_ref->{'sort_routine'}; + } + } + + return GetClassSortKey($routine, $cn_class, $cn_item); + +} + 1; =head1 AUTHOR -Koha Developement team +Koha Development Team =cut