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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use C4::ClassSortRoutine qw( GetClassSortKey );
26 our (@ISA, @EXPORT_OK);
40 C4::ClassSources - handle classification sources in Koha
48 This module deals with manipulating classification
49 sources and sorting rules.
55 =head2 GetClassSources
57 my $sources = GetClassSources();
59 Returns reference to hash of references to
60 the class sources, keyed on cn_source.
64 my $sources = GetClassSources();
66 foreach my $cn_source (sort keys %$sources) {
67 my $source = $sources->{$cn_source};
70 code => $source->{'cn_source'},
71 description => $source->{'description'},
72 used => $source->{'used'},
73 sortrule => $source->{'class_sort_rule'}
81 my %class_sources = ();
82 my $dbh = C4::Context->dbh;
83 my $sth = $dbh->prepare("SELECT * FROM `class_sources`");
85 while (my $source = $sth->fetchrow_hashref) {
86 $class_sources{ $source->{'cn_source'} } = $source;
89 return \%class_sources;
95 my $hashref = GetClassSource($cn_source);
97 Retrieves a class_sources row by cn_source.
103 my ($cn_source) = (@_);
104 my $dbh = C4::Context->dbh;
105 my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?");
106 $sth->execute($cn_source);
107 my $row = $sth->fetchrow_hashref();
111 =head2 GetClassSortRule
113 my $hashref = GetClassSortRule($class_sort_rule);
115 Retrieves a class_sort_rules row by class_sort_rule.
119 sub GetClassSortRule {
121 my ($class_sort_rule) = (@_);
122 my $dbh = C4::Context->dbh;
123 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
124 $sth->execute($class_sort_rule);
125 my $row = $sth->fetchrow_hashref();
131 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
133 Get the sort key corresponding to the classification part and item part
134 and the defined call number source.
140 my ($cn_source, $cn_class, $cn_item) = @_;
142 my $source_ref = GetClassSource($cn_source);
143 unless (defined $source_ref) {
144 $source_ref = GetClassSource(C4::Context->preference("DefaultClassificationSource"));
147 if (defined $source_ref) {
148 my $rule_ref = GetClassSortRule($source_ref->{'class_sort_rule'});
149 if (defined $rule_ref) {
150 $routine = $rule_ref->{'sort_routine'};
154 return GetClassSortKey($routine, $cn_class, $cn_item);
162 Koha Development Team <http://koha-community.org/>