1 package C4::ClassSource;
3 # Copyright 2022 Koha Development Team
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use C4::ClassSortRoutine qw( GetClassSortKey );
24 our (@ISA, @EXPORT_OK);
38 C4::ClassSources - handle classification sources in Koha
46 This module deals with manipulating classification
47 sources and sorting rules.
53 =head2 GetClassSources
55 my $sources = GetClassSources();
57 Returns reference to hash of references to
58 the class sources, keyed on cn_source.
62 my $sources = GetClassSources();
64 foreach my $cn_source (sort keys %$sources) {
65 my $source = $sources->{$cn_source};
68 code => $source->{'cn_source'},
69 description => $source->{'description'},
70 used => $source->{'used'},
71 sortrule => $source->{'class_sort_rule'}
79 my %class_sources = ();
80 my $dbh = C4::Context->dbh;
81 my $sth = $dbh->prepare("SELECT * FROM `class_sources`");
83 while (my $source = $sth->fetchrow_hashref) {
84 $class_sources{ $source->{'cn_source'} } = $source;
87 return \%class_sources;
93 my $hashref = GetClassSource($cn_source);
95 Retrieves a class_sources row by cn_source.
101 my ($cn_source) = (@_);
102 my $dbh = C4::Context->dbh;
103 my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?");
104 $sth->execute($cn_source);
105 my $row = $sth->fetchrow_hashref();
109 =head2 GetClassSortRule
111 my $hashref = GetClassSortRule($class_sort_rule);
113 Retrieves a class_sort_rules row by class_sort_rule.
117 sub GetClassSortRule {
119 my ($class_sort_rule) = (@_);
120 my $dbh = C4::Context->dbh;
121 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
122 $sth->execute($class_sort_rule);
123 my $row = $sth->fetchrow_hashref();
129 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
131 Get the sort key corresponding to the classification part and item part
132 and the defined call number source.
138 my ($cn_source, $cn_class, $cn_item) = @_;
140 my $source_ref = GetClassSource($cn_source);
141 unless (defined $source_ref) {
142 $source_ref = GetClassSource(C4::Context->preference("DefaultClassificationSource"));
145 if (defined $source_ref) {
146 my $rule_ref = GetClassSortRule($source_ref->{'class_sort_rule'});
147 if (defined $rule_ref) {
148 $routine = $rule_ref->{'sort_routine'};
152 return GetClassSortKey($routine, $cn_class, $cn_item);
160 Koha Development Team <http://koha-community.org/>