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
24 use C4
::ClassSortRoutine
;
26 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
28 # set the version for version checking
33 C4::ClassSources - handle classification sources in Koha
41 This module deals with manipulating classification
42 sources and sorting rules.
62 &GetSourcesForSortRule
67 =head2 GetClassSources
69 my $sources = GetClassSources();
71 Returns reference to hash of references to
72 the class sources, keyed on cn_source.
76 my $sources = GetClassSources();
78 foreach my $cn_source (sort keys %$sources) {
79 my $source = $sources->{$cn_source};
82 code => $source->{'cn_source'},
83 description => $source->{'description'},
84 used => $source->{'used'},
85 sortrule => $source->{'class_sort_rule'}
93 my %class_sources = ();
94 my $dbh = C4
::Context
->dbh;
95 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources`");
97 while (my $source = $sth->fetchrow_hashref) {
98 $class_sources{ $source->{'cn_source'} } = $source;
102 return \
%class_sources;
106 =head2 AddClassSource
108 AddClassSource($cn_source, $description, $used, $class_sort_rule);
110 Adds a class_sources row.
116 my ($cn_source, $description, $used, $class_sort_rule) = @_;
117 my $dbh = C4
::Context
->dbh;
118 my $sth = $dbh->prepare_cached("INSERT INTO `class_sources`
119 (`cn_source`, `description`, `used`, `class_sort_rule`)
120 VALUES (?, ?, ?, ?)");
121 $sth->execute($cn_source, $description, $used, $class_sort_rule);
126 =head2 GetClassSource
128 my $hashref = GetClassSource($cn_source);
130 Retrieves a class_sources row by cn_source.
136 my ($cn_source) = (@_);
137 my $dbh = C4
::Context
->dbh;
138 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources` WHERE cn_source = ?");
139 $sth->execute($cn_source);
140 my $row = $sth->fetchrow_hashref();
145 =head2 ModClassSource
147 ModClassSource($cn_source, $description, $used, $class_sort_rule);
149 Updates a class_sources row.
155 my ($cn_source, $description, $used, $class_sort_rule) = @_;
156 my $dbh = C4
::Context
->dbh;
157 my $sth = $dbh->prepare_cached("UPDATE `class_sources`
158 SET `description` = ?,
160 `class_sort_rule` = ?
161 WHERE `cn_source` = ?");
162 $sth->execute($description, $used, $class_sort_rule, $cn_source);
167 =head2 DelClassSource
169 DelClassSource($cn_source);
171 Deletes class_sources row.
177 my ($cn_source) = @_;
178 my $dbh = C4
::Context
->dbh;
179 my $sth = $dbh->prepare_cached("DELETE FROM `class_sources` WHERE `cn_source` = ?");
180 $sth->execute($cn_source);
185 =head2 GetClassSortRules
187 my $sort_rules = GetClassSortRules();
189 Returns reference to hash of references to
190 the class sorting rules, keyed on class_sort_rule
194 my $sort_rules = GetClassSortRules();
196 foreach my $sort_rule (sort keys %$sort_rules) {
197 my $sort_rule = $sort_rules->{$sort_rule};
200 rule => $sort_rule->{'class_sort_rule'},
201 description => $sort_rule->{'description'},
202 sort_routine => $sort_rule->{'sort_routine'}
208 sub GetClassSortRules
{
210 my %class_sort_rules = ();
211 my $dbh = C4
::Context
->dbh;
212 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules`");
214 while (my $sort_rule = $sth->fetchrow_hashref) {
215 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
219 return \
%class_sort_rules;
223 =head2 AddClassSortRule
225 AddClassSortRule($class_sort_rule, $description, $sort_routine);
227 Adds a class_sort_rules row.
231 sub AddClassSortRule
{
233 my ($class_sort_rule, $description, $sort_routine) = @_;
234 my $dbh = C4
::Context
->dbh;
235 my $sth = $dbh->prepare_cached("INSERT INTO `class_sort_rules`
236 (`class_sort_rule`, `description`, `sort_routine`)
238 $sth->execute($class_sort_rule, $description, $sort_routine);
243 =head2 GetClassSortRule
245 my $hashref = GetClassSortRule($class_sort_rule);
247 Retrieves a class_sort_rules row by class_sort_rule.
251 sub GetClassSortRule
{
253 my ($class_sort_rule) = (@_);
254 my $dbh = C4
::Context
->dbh;
255 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
256 $sth->execute($class_sort_rule);
257 my $row = $sth->fetchrow_hashref();
262 =head2 ModClassSortRule
264 ModClassSortRule($class_sort_rule, $description, $sort_routine);
266 Updates a class_sort_rules row.
270 sub ModClassSortRule
{
272 my ($class_sort_rule, $description, $sort_routine) = @_;
273 my $dbh = C4
::Context
->dbh;
274 my $sth = $dbh->prepare_cached("UPDATE `class_sort_rules`
275 SET `description` = ?,
277 WHERE `class_sort_rule` = ?");
278 $sth->execute($description, $sort_routine, $class_sort_rule);
283 =head2 DelClassSortRule
285 DelClassSortRule($class_sort_rule);
287 Deletes class_sort_rules row.
291 sub DelClassSortRule
{
293 my ($class_sort_rule) = @_;
294 my $dbh = C4
::Context
->dbh;
295 my $sth = $dbh->prepare_cached("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
296 $sth->execute($class_sort_rule);
301 =head2 GetSourcesForSortRule
303 my @source = GetSourcesForSortRule($class_sort_rule);
305 Retrieves an array class_source.cn_rule for each source
306 that uses the supplied $class_sort_rule.
310 sub GetSourcesForSortRule
{
312 my ($class_sort_rule) = @_;
314 my $dbh = C4
::Context
->dbh;
315 my $sth = $dbh->prepare_cached("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
316 $sth->execute($class_sort_rule);
318 while (my ($source) = $sth->fetchrow_array()) {
319 push @sources, $source;
328 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
330 Get the sort key corresponding to the classification part and item part
331 and the defined call number source.
337 my ($cn_source, $cn_class, $cn_item) = @_;
339 my $source_ref = GetClassSource
($cn_source);
340 unless (defined $source_ref) {
341 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
344 if (defined $source_ref) {
345 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
346 if (defined $rule_ref) {
347 $routine = $rule_ref->{'sort_routine'};
351 return GetClassSortKey
($routine, $cn_class, $cn_item);
359 Koha Developement team <info@koha.org>