1 package C4
::ClassSource
;
3 # Copyright (C) 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
26 use C4
::ClassSortRoutine
;
28 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30 # set the version for version checking
35 C4::ClassSources - handle classification sources in Koha
43 This module deals with manipulating classification
44 sources and sorting rules.
64 &GetSourcesForSortRule
69 =head2 GetClassSources
71 my $sources = GetClassSources();
73 Returns reference to hash of references to
74 the class sources, keyed on cn_source.
78 my $sources = GetClassSources();
80 foreach my $cn_source (sort keys %$sources) {
81 my $source = $sources->{$cn_source};
84 code => $source->{'cn_source'},
85 description => $source->{'description'},
86 used => $source->{'used'},
87 sortrule => $source->{'class_sort_rule'}
95 my %class_sources = ();
96 my $dbh = C4
::Context
->dbh;
97 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources`");
99 while (my $source = $sth->fetchrow_hashref) {
100 $class_sources{ $source->{'cn_source'} } = $source;
104 return \
%class_sources;
108 =head2 AddClassSource
110 AddClassSource($cn_source, $description, $used, $class_sort_rule);
112 Adds a class_sources row.
118 my ($cn_source, $description, $used, $class_sort_rule) = @_;
119 my $dbh = C4
::Context
->dbh;
120 my $sth = $dbh->prepare_cached("INSERT INTO `class_sources`
121 (`cn_source`, `description`, `used`, `class_sort_rule`)
122 VALUES (?, ?, ?, ?)");
123 $sth->execute($cn_source, $description, $used, $class_sort_rule);
128 =head2 GetClassSource
130 my $hashref = GetClassSource($cn_source);
132 Retrieves a class_sources row by cn_source.
138 my ($cn_source) = (@_);
139 my $dbh = C4
::Context
->dbh;
140 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources` WHERE cn_source = ?");
141 $sth->execute($cn_source);
142 my $row = $sth->fetchrow_hashref();
147 =head2 ModClassSource
149 ModClassSource($cn_source, $description, $used, $class_sort_rule);
151 Updates a class_sources row.
157 my ($cn_source, $description, $used, $class_sort_rule) = @_;
158 my $dbh = C4
::Context
->dbh;
159 my $sth = $dbh->prepare_cached("UPDATE `class_sources`
160 SET `description` = ?,
162 `class_sort_rule` = ?
163 WHERE `cn_source` = ?");
164 $sth->execute($description, $used, $class_sort_rule, $cn_source);
169 =head2 DelClassSource
171 DelClassSource($cn_source);
173 Deletes class_sources row.
179 my ($cn_source) = @_;
180 my $dbh = C4
::Context
->dbh;
181 my $sth = $dbh->prepare_cached("DELETE FROM `class_sources` WHERE `cn_source` = ?");
182 $sth->execute($cn_source);
187 =head2 GetClassSortRules
189 my $sort_rules = GetClassSortRules();
191 Returns reference to hash of references to
192 the class sorting rules, keyed on class_sort_rule
196 my $sort_rules = GetClassSortRules();
198 foreach my $sort_rule (sort keys %$sort_rules) {
199 my $sort_rule = $sort_rules->{$sort_rule};
202 rule => $sort_rule->{'class_sort_rule'},
203 description => $sort_rule->{'description'},
204 sort_routine => $sort_rule->{'sort_routine'}
210 sub GetClassSortRules
{
212 my %class_sort_rules = ();
213 my $dbh = C4
::Context
->dbh;
214 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules`");
216 while (my $sort_rule = $sth->fetchrow_hashref) {
217 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
221 return \
%class_sort_rules;
225 =head2 AddClassSortRule
227 AddClassSortRule($class_sort_rule, $description, $sort_routine);
229 Adds a class_sort_rules row.
233 sub AddClassSortRule
{
235 my ($class_sort_rule, $description, $sort_routine) = @_;
236 my $dbh = C4
::Context
->dbh;
237 my $sth = $dbh->prepare_cached("INSERT INTO `class_sort_rules`
238 (`class_sort_rule`, `description`, `sort_routine`)
240 $sth->execute($class_sort_rule, $description, $sort_routine);
245 =head2 GetClassSortRule
247 my $hashref = GetClassSortRule($class_sort_rule);
249 Retrieves a class_sort_rules row by class_sort_rule.
253 sub GetClassSortRule
{
255 my ($class_sort_rule) = (@_);
256 my $dbh = C4
::Context
->dbh;
257 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
258 $sth->execute($class_sort_rule);
259 my $row = $sth->fetchrow_hashref();
264 =head2 ModClassSortRule
266 ModClassSortRule($class_sort_rule, $description, $sort_routine);
268 Updates a class_sort_rules row.
272 sub ModClassSortRule
{
274 my ($class_sort_rule, $description, $sort_routine) = @_;
275 my $dbh = C4
::Context
->dbh;
276 my $sth = $dbh->prepare_cached("UPDATE `class_sort_rules`
277 SET `description` = ?,
279 WHERE `class_sort_rule` = ?");
280 $sth->execute($description, $sort_routine, $class_sort_rule);
285 =head2 DelClassSortRule
287 DelClassSortRule($class_sort_rule);
289 Deletes class_sort_rules row.
293 sub DelClassSortRule
{
295 my ($class_sort_rule) = @_;
296 my $dbh = C4
::Context
->dbh;
297 my $sth = $dbh->prepare_cached("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
298 $sth->execute($class_sort_rule);
303 =head2 GetSourcesForSortRule
305 my @source = GetSourcesForSortRule($class_sort_rule);
307 Retrieves an array class_source.cn_rule for each source
308 that uses the supplied $class_sort_rule.
312 sub GetSourcesForSortRule
{
314 my ($class_sort_rule) = @_;
316 my $dbh = C4
::Context
->dbh;
317 my $sth = $dbh->prepare_cached("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
318 $sth->execute($class_sort_rule);
320 while (my ($source) = $sth->fetchrow_array()) {
321 push @sources, $source;
330 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
332 Get the sort key corresponding to the classification part and item part
333 and the defined call number source.
339 my ($cn_source, $cn_class, $cn_item) = @_;
341 my $source_ref = GetClassSource
($cn_source);
342 unless (defined $source_ref) {
343 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
346 if (defined $source_ref) {
347 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
348 if (defined $rule_ref) {
349 $routine = $rule_ref->{'sort_routine'};
353 return GetClassSortKey
($routine, $cn_class, $cn_item);
361 Koha Developement team <info@koha.org>