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>.
25 use C4
::ClassSortRoutine
;
27 use vars
qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32 C4::ClassSources - handle classification sources in Koha
40 This module deals with manipulating classification
41 sources and sorting rules.
61 &GetSourcesForSortRule
66 =head2 GetClassSources
68 my $sources = GetClassSources();
70 Returns reference to hash of references to
71 the class sources, keyed on cn_source.
75 my $sources = GetClassSources();
77 foreach my $cn_source (sort keys %$sources) {
78 my $source = $sources->{$cn_source};
81 code => $source->{'cn_source'},
82 description => $source->{'description'},
83 used => $source->{'used'},
84 sortrule => $source->{'class_sort_rule'}
92 my %class_sources = ();
93 my $dbh = C4
::Context
->dbh;
94 my $sth = $dbh->prepare("SELECT * FROM `class_sources`");
96 while (my $source = $sth->fetchrow_hashref) {
97 $class_sources{ $source->{'cn_source'} } = $source;
100 return \
%class_sources;
104 =head2 AddClassSource
106 AddClassSource($cn_source, $description, $used, $class_sort_rule);
108 Adds a class_sources row.
114 my ($cn_source, $description, $used, $class_sort_rule) = @_;
115 my $dbh = C4
::Context
->dbh;
116 my $sth = $dbh->prepare("INSERT INTO `class_sources`
117 (`cn_source`, `description`, `used`, `class_sort_rule`)
118 VALUES (?, ?, ?, ?)");
119 $sth->execute($cn_source, $description, $used, $class_sort_rule);
123 =head2 GetClassSource
125 my $hashref = GetClassSource($cn_source);
127 Retrieves a class_sources row by cn_source.
133 my ($cn_source) = (@_);
134 my $dbh = C4
::Context
->dbh;
135 my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?");
136 $sth->execute($cn_source);
137 my $row = $sth->fetchrow_hashref();
141 =head2 ModClassSource
143 ModClassSource($cn_source, $description, $used, $class_sort_rule);
145 Updates a class_sources row.
151 my ($cn_source, $description, $used, $class_sort_rule) = @_;
152 my $dbh = C4
::Context
->dbh;
153 my $sth = $dbh->prepare("UPDATE `class_sources`
154 SET `description` = ?,
156 `class_sort_rule` = ?
157 WHERE `cn_source` = ?");
158 $sth->execute($description, $used, $class_sort_rule, $cn_source);
162 =head2 DelClassSource
164 DelClassSource($cn_source);
166 Deletes class_sources row.
172 my ($cn_source) = @_;
173 my $dbh = C4
::Context
->dbh;
174 my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?");
175 $sth->execute($cn_source);
179 =head2 GetClassSortRules
181 my $sort_rules = GetClassSortRules();
183 Returns reference to hash of references to
184 the class sorting rules, keyed on class_sort_rule
188 my $sort_rules = GetClassSortRules();
190 foreach my $sort_rule (sort keys %$sort_rules) {
191 my $sort_rule = $sort_rules->{$sort_rule};
194 rule => $sort_rule->{'class_sort_rule'},
195 description => $sort_rule->{'description'},
196 sort_routine => $sort_rule->{'sort_routine'}
202 sub GetClassSortRules
{
204 my %class_sort_rules = ();
205 my $dbh = C4
::Context
->dbh;
206 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`");
208 while (my $sort_rule = $sth->fetchrow_hashref) {
209 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
212 return \
%class_sort_rules;
216 =head2 AddClassSortRule
218 AddClassSortRule($class_sort_rule, $description, $sort_routine);
220 Adds a class_sort_rules row.
224 sub AddClassSortRule
{
226 my ($class_sort_rule, $description, $sort_routine) = @_;
227 my $dbh = C4
::Context
->dbh;
228 my $sth = $dbh->prepare("INSERT INTO `class_sort_rules`
229 (`class_sort_rule`, `description`, `sort_routine`)
231 $sth->execute($class_sort_rule, $description, $sort_routine);
235 =head2 GetClassSortRule
237 my $hashref = GetClassSortRule($class_sort_rule);
239 Retrieves a class_sort_rules row by class_sort_rule.
243 sub GetClassSortRule
{
245 my ($class_sort_rule) = (@_);
246 my $dbh = C4
::Context
->dbh;
247 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
248 $sth->execute($class_sort_rule);
249 my $row = $sth->fetchrow_hashref();
253 =head2 ModClassSortRule
255 ModClassSortRule($class_sort_rule, $description, $sort_routine);
257 Updates a class_sort_rules row.
261 sub ModClassSortRule
{
263 my ($class_sort_rule, $description, $sort_routine) = @_;
264 my $dbh = C4
::Context
->dbh;
265 my $sth = $dbh->prepare("UPDATE `class_sort_rules`
266 SET `description` = ?,
268 WHERE `class_sort_rule` = ?");
269 $sth->execute($description, $sort_routine, $class_sort_rule);
273 =head2 DelClassSortRule
275 DelClassSortRule($class_sort_rule);
277 Deletes class_sort_rules row.
281 sub DelClassSortRule
{
283 my ($class_sort_rule) = @_;
284 my $dbh = C4
::Context
->dbh;
285 my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
286 $sth->execute($class_sort_rule);
290 =head2 GetSourcesForSortRule
292 my @source = GetSourcesForSortRule($class_sort_rule);
294 Retrieves an array class_source.cn_rule for each source
295 that uses the supplied $class_sort_rule.
299 sub GetSourcesForSortRule
{
301 my ($class_sort_rule) = @_;
303 my $dbh = C4
::Context
->dbh;
304 my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
305 $sth->execute($class_sort_rule);
307 while (my ($source) = $sth->fetchrow_array()) {
308 push @sources, $source;
316 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
318 Get the sort key corresponding to the classification part and item part
319 and the defined call number source.
325 my ($cn_source, $cn_class, $cn_item) = @_;
327 my $source_ref = GetClassSource
($cn_source);
328 unless (defined $source_ref) {
329 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
332 if (defined $source_ref) {
333 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
334 if (defined $rule_ref) {
335 $routine = $rule_ref->{'sort_routine'};
339 return GetClassSortKey
($routine, $cn_class, $cn_item);
347 Koha Development Team <http://koha-community.org/>