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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use C4
::ClassSortRoutine
;
27 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
29 # set the version for version checking
34 C4::ClassSources - handle classification sources in Koha
42 This module deals with manipulating classification
43 sources and sorting rules.
63 &GetSourcesForSortRule
68 =head2 GetClassSources
70 my $sources = GetClassSources();
72 Returns reference to hash of references to
73 the class sources, keyed on cn_source.
77 my $sources = GetClassSources();
79 foreach my $cn_source (sort keys %$sources) {
80 my $source = $sources->{$cn_source};
83 code => $source->{'cn_source'},
84 description => $source->{'description'},
85 used => $source->{'used'},
86 sortrule => $source->{'class_sort_rule'}
94 my %class_sources = ();
95 my $dbh = C4
::Context
->dbh;
96 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources`");
98 while (my $source = $sth->fetchrow_hashref) {
99 $class_sources{ $source->{'cn_source'} } = $source;
103 return \
%class_sources;
107 =head2 AddClassSource
109 AddClassSource($cn_source, $description, $used, $class_sort_rule);
111 Adds a class_sources row.
117 my ($cn_source, $description, $used, $class_sort_rule) = @_;
118 my $dbh = C4
::Context
->dbh;
119 my $sth = $dbh->prepare_cached("INSERT INTO `class_sources`
120 (`cn_source`, `description`, `used`, `class_sort_rule`)
121 VALUES (?, ?, ?, ?)");
122 $sth->execute($cn_source, $description, $used, $class_sort_rule);
127 =head2 GetClassSource
129 my $hashref = GetClassSource($cn_source);
131 Retrieves a class_sources row by cn_source.
137 my ($cn_source) = (@_);
138 my $dbh = C4
::Context
->dbh;
139 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources` WHERE cn_source = ?");
140 $sth->execute($cn_source);
141 my $row = $sth->fetchrow_hashref();
146 =head2 ModClassSource
148 ModClassSource($cn_source, $description, $used, $class_sort_rule);
150 Updates a class_sources row.
156 my ($cn_source, $description, $used, $class_sort_rule) = @_;
157 my $dbh = C4
::Context
->dbh;
158 my $sth = $dbh->prepare_cached("UPDATE `class_sources`
159 SET `description` = ?,
161 `class_sort_rule` = ?
162 WHERE `cn_source` = ?");
163 $sth->execute($description, $used, $class_sort_rule, $cn_source);
168 =head2 DelClassSource
170 DelClassSource($cn_source);
172 Deletes class_sources row.
178 my ($cn_source) = @_;
179 my $dbh = C4
::Context
->dbh;
180 my $sth = $dbh->prepare_cached("DELETE FROM `class_sources` WHERE `cn_source` = ?");
181 $sth->execute($cn_source);
186 =head2 GetClassSortRules
188 my $sort_rules = GetClassSortRules();
190 Returns reference to hash of references to
191 the class sorting rules, keyed on class_sort_rule
195 my $sort_rules = GetClassSortRules();
197 foreach my $sort_rule (sort keys %$sort_rules) {
198 my $sort_rule = $sort_rules->{$sort_rule};
201 rule => $sort_rule->{'class_sort_rule'},
202 description => $sort_rule->{'description'},
203 sort_routine => $sort_rule->{'sort_routine'}
209 sub GetClassSortRules
{
211 my %class_sort_rules = ();
212 my $dbh = C4
::Context
->dbh;
213 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules`");
215 while (my $sort_rule = $sth->fetchrow_hashref) {
216 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
220 return \
%class_sort_rules;
224 =head2 AddClassSortRule
226 AddClassSortRule($class_sort_rule, $description, $sort_routine);
228 Adds a class_sort_rules row.
232 sub AddClassSortRule
{
234 my ($class_sort_rule, $description, $sort_routine) = @_;
235 my $dbh = C4
::Context
->dbh;
236 my $sth = $dbh->prepare_cached("INSERT INTO `class_sort_rules`
237 (`class_sort_rule`, `description`, `sort_routine`)
239 $sth->execute($class_sort_rule, $description, $sort_routine);
244 =head2 GetClassSortRule
246 my $hashref = GetClassSortRule($class_sort_rule);
248 Retrieves a class_sort_rules row by class_sort_rule.
252 sub GetClassSortRule
{
254 my ($class_sort_rule) = (@_);
255 my $dbh = C4
::Context
->dbh;
256 my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
257 $sth->execute($class_sort_rule);
258 my $row = $sth->fetchrow_hashref();
263 =head2 ModClassSortRule
265 ModClassSortRule($class_sort_rule, $description, $sort_routine);
267 Updates a class_sort_rules row.
271 sub ModClassSortRule
{
273 my ($class_sort_rule, $description, $sort_routine) = @_;
274 my $dbh = C4
::Context
->dbh;
275 my $sth = $dbh->prepare_cached("UPDATE `class_sort_rules`
276 SET `description` = ?,
278 WHERE `class_sort_rule` = ?");
279 $sth->execute($description, $sort_routine, $class_sort_rule);
284 =head2 DelClassSortRule
286 DelClassSortRule($class_sort_rule);
288 Deletes class_sort_rules row.
292 sub DelClassSortRule
{
294 my ($class_sort_rule) = @_;
295 my $dbh = C4
::Context
->dbh;
296 my $sth = $dbh->prepare_cached("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
297 $sth->execute($class_sort_rule);
302 =head2 GetSourcesForSortRule
304 my @source = GetSourcesForSortRule($class_sort_rule);
306 Retrieves an array class_source.cn_rule for each source
307 that uses the supplied $class_sort_rule.
311 sub GetSourcesForSortRule
{
313 my ($class_sort_rule) = @_;
315 my $dbh = C4
::Context
->dbh;
316 my $sth = $dbh->prepare_cached("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
317 $sth->execute($class_sort_rule);
319 while (my ($source) = $sth->fetchrow_array()) {
320 push @sources, $source;
329 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
331 Get the sort key corresponding to the classification part and item part
332 and the defined call number source.
338 my ($cn_source, $cn_class, $cn_item) = @_;
340 my $source_ref = GetClassSource
($cn_source);
341 unless (defined $source_ref) {
342 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
345 if (defined $source_ref) {
346 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
347 if (defined $rule_ref) {
348 $routine = $rule_ref->{'sort_routine'};
352 return GetClassSortKey
($routine, $cn_class, $cn_item);
360 Koha Development Team <http://koha-community.org/>