X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FClassSource.pm;h=245f9589c64e8accf934b3345a7d2d4765b5450b;hb=e1f943b9992ea1a3c5d4659ca6fa787834d66376;hp=4a161ae6a26bd27c700e82819687f09dfb900c73;hpb=fc8b44a96737af916c0dc1c2424c345c42f78a99;p=koha.git diff --git a/C4/ClassSource.pm b/C4/ClassSource.pm index 4a161ae6a2..245f9589c6 100644 --- a/C4/ClassSource.pm +++ b/C4/ClassSource.pm @@ -4,29 +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 @@ -92,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; @@ -114,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 @@ -135,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; } @@ -154,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(); } @@ -176,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(); } @@ -186,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 @@ -209,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; @@ -231,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 @@ -252,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; } @@ -271,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(); } @@ -292,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(); } @@ -312,13 +309,12 @@ 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; } @@ -356,6 +352,6 @@ sub GetClassSort { =head1 AUTHOR -Koha Developement team +Koha Development Team =cut