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);
29 # 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("SELECT * FROM `class_sources`");
97 while (my $source = $sth->fetchrow_hashref) {
98 $class_sources{ $source->{'cn_source'} } = $source;
101 return \
%class_sources;
105 =head2 AddClassSource
107 AddClassSource($cn_source, $description, $used, $class_sort_rule);
109 Adds a class_sources row.
115 my ($cn_source, $description, $used, $class_sort_rule) = @_;
116 my $dbh = C4
::Context
->dbh;
117 my $sth = $dbh->prepare("INSERT INTO `class_sources`
118 (`cn_source`, `description`, `used`, `class_sort_rule`)
119 VALUES (?, ?, ?, ?)");
120 $sth->execute($cn_source, $description, $used, $class_sort_rule);
124 =head2 GetClassSource
126 my $hashref = GetClassSource($cn_source);
128 Retrieves a class_sources row by cn_source.
134 my ($cn_source) = (@_);
135 my $dbh = C4
::Context
->dbh;
136 my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?");
137 $sth->execute($cn_source);
138 my $row = $sth->fetchrow_hashref();
142 =head2 ModClassSource
144 ModClassSource($cn_source, $description, $used, $class_sort_rule);
146 Updates a class_sources row.
152 my ($cn_source, $description, $used, $class_sort_rule) = @_;
153 my $dbh = C4
::Context
->dbh;
154 my $sth = $dbh->prepare("UPDATE `class_sources`
155 SET `description` = ?,
157 `class_sort_rule` = ?
158 WHERE `cn_source` = ?");
159 $sth->execute($description, $used, $class_sort_rule, $cn_source);
163 =head2 DelClassSource
165 DelClassSource($cn_source);
167 Deletes class_sources row.
173 my ($cn_source) = @_;
174 my $dbh = C4
::Context
->dbh;
175 my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?");
176 $sth->execute($cn_source);
180 =head2 GetClassSortRules
182 my $sort_rules = GetClassSortRules();
184 Returns reference to hash of references to
185 the class sorting rules, keyed on class_sort_rule
189 my $sort_rules = GetClassSortRules();
191 foreach my $sort_rule (sort keys %$sort_rules) {
192 my $sort_rule = $sort_rules->{$sort_rule};
195 rule => $sort_rule->{'class_sort_rule'},
196 description => $sort_rule->{'description'},
197 sort_routine => $sort_rule->{'sort_routine'}
203 sub GetClassSortRules
{
205 my %class_sort_rules = ();
206 my $dbh = C4
::Context
->dbh;
207 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`");
209 while (my $sort_rule = $sth->fetchrow_hashref) {
210 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
213 return \
%class_sort_rules;
217 =head2 AddClassSortRule
219 AddClassSortRule($class_sort_rule, $description, $sort_routine);
221 Adds a class_sort_rules row.
225 sub AddClassSortRule
{
227 my ($class_sort_rule, $description, $sort_routine) = @_;
228 my $dbh = C4
::Context
->dbh;
229 my $sth = $dbh->prepare("INSERT INTO `class_sort_rules`
230 (`class_sort_rule`, `description`, `sort_routine`)
232 $sth->execute($class_sort_rule, $description, $sort_routine);
236 =head2 GetClassSortRule
238 my $hashref = GetClassSortRule($class_sort_rule);
240 Retrieves a class_sort_rules row by class_sort_rule.
244 sub GetClassSortRule
{
246 my ($class_sort_rule) = (@_);
247 my $dbh = C4
::Context
->dbh;
248 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
249 $sth->execute($class_sort_rule);
250 my $row = $sth->fetchrow_hashref();
254 =head2 ModClassSortRule
256 ModClassSortRule($class_sort_rule, $description, $sort_routine);
258 Updates a class_sort_rules row.
262 sub ModClassSortRule
{
264 my ($class_sort_rule, $description, $sort_routine) = @_;
265 my $dbh = C4
::Context
->dbh;
266 my $sth = $dbh->prepare("UPDATE `class_sort_rules`
267 SET `description` = ?,
269 WHERE `class_sort_rule` = ?");
270 $sth->execute($description, $sort_routine, $class_sort_rule);
274 =head2 DelClassSortRule
276 DelClassSortRule($class_sort_rule);
278 Deletes class_sort_rules row.
282 sub DelClassSortRule
{
284 my ($class_sort_rule) = @_;
285 my $dbh = C4
::Context
->dbh;
286 my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
287 $sth->execute($class_sort_rule);
291 =head2 GetSourcesForSortRule
293 my @source = GetSourcesForSortRule($class_sort_rule);
295 Retrieves an array class_source.cn_rule for each source
296 that uses the supplied $class_sort_rule.
300 sub GetSourcesForSortRule
{
302 my ($class_sort_rule) = @_;
304 my $dbh = C4
::Context
->dbh;
305 my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
306 $sth->execute($class_sort_rule);
308 while (my ($source) = $sth->fetchrow_array()) {
309 push @sources, $source;
317 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
319 Get the sort key corresponding to the classification part and item part
320 and the defined call number source.
326 my ($cn_source, $cn_class, $cn_item) = @_;
328 my $source_ref = GetClassSource
($cn_source);
329 unless (defined $source_ref) {
330 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
333 if (defined $source_ref) {
334 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
335 if (defined $rule_ref) {
336 $routine = $rule_ref->{'sort_routine'};
340 return GetClassSortKey
($routine, $cn_class, $cn_item);
348 Koha Development Team <http://koha-community.org/>