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
30 $VERSION = 3.07.00.049;
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("SELECT * FROM `class_sources`");
98 while (my $source = $sth->fetchrow_hashref) {
99 $class_sources{ $source->{'cn_source'} } = $source;
102 return \
%class_sources;
106 =head2 AddClassSource
108 AddClassSource($cn_source, $description, $used, $class_sort_rule);
110 Adds a class_sources row.
116 my ($cn_source, $description, $used, $class_sort_rule) = @_;
117 my $dbh = C4
::Context
->dbh;
118 my $sth = $dbh->prepare("INSERT INTO `class_sources`
119 (`cn_source`, `description`, `used`, `class_sort_rule`)
120 VALUES (?, ?, ?, ?)");
121 $sth->execute($cn_source, $description, $used, $class_sort_rule);
125 =head2 GetClassSource
127 my $hashref = GetClassSource($cn_source);
129 Retrieves a class_sources row by cn_source.
135 my ($cn_source) = (@_);
136 my $dbh = C4
::Context
->dbh;
137 my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?");
138 $sth->execute($cn_source);
139 my $row = $sth->fetchrow_hashref();
143 =head2 ModClassSource
145 ModClassSource($cn_source, $description, $used, $class_sort_rule);
147 Updates a class_sources row.
153 my ($cn_source, $description, $used, $class_sort_rule) = @_;
154 my $dbh = C4
::Context
->dbh;
155 my $sth = $dbh->prepare("UPDATE `class_sources`
156 SET `description` = ?,
158 `class_sort_rule` = ?
159 WHERE `cn_source` = ?");
160 $sth->execute($description, $used, $class_sort_rule, $cn_source);
164 =head2 DelClassSource
166 DelClassSource($cn_source);
168 Deletes class_sources row.
174 my ($cn_source) = @_;
175 my $dbh = C4
::Context
->dbh;
176 my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?");
177 $sth->execute($cn_source);
181 =head2 GetClassSortRules
183 my $sort_rules = GetClassSortRules();
185 Returns reference to hash of references to
186 the class sorting rules, keyed on class_sort_rule
190 my $sort_rules = GetClassSortRules();
192 foreach my $sort_rule (sort keys %$sort_rules) {
193 my $sort_rule = $sort_rules->{$sort_rule};
196 rule => $sort_rule->{'class_sort_rule'},
197 description => $sort_rule->{'description'},
198 sort_routine => $sort_rule->{'sort_routine'}
204 sub GetClassSortRules
{
206 my %class_sort_rules = ();
207 my $dbh = C4
::Context
->dbh;
208 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`");
210 while (my $sort_rule = $sth->fetchrow_hashref) {
211 $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule;
214 return \
%class_sort_rules;
218 =head2 AddClassSortRule
220 AddClassSortRule($class_sort_rule, $description, $sort_routine);
222 Adds a class_sort_rules row.
226 sub AddClassSortRule
{
228 my ($class_sort_rule, $description, $sort_routine) = @_;
229 my $dbh = C4
::Context
->dbh;
230 my $sth = $dbh->prepare("INSERT INTO `class_sort_rules`
231 (`class_sort_rule`, `description`, `sort_routine`)
233 $sth->execute($class_sort_rule, $description, $sort_routine);
237 =head2 GetClassSortRule
239 my $hashref = GetClassSortRule($class_sort_rule);
241 Retrieves a class_sort_rules row by class_sort_rule.
245 sub GetClassSortRule
{
247 my ($class_sort_rule) = (@_);
248 my $dbh = C4
::Context
->dbh;
249 my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
250 $sth->execute($class_sort_rule);
251 my $row = $sth->fetchrow_hashref();
255 =head2 ModClassSortRule
257 ModClassSortRule($class_sort_rule, $description, $sort_routine);
259 Updates a class_sort_rules row.
263 sub ModClassSortRule
{
265 my ($class_sort_rule, $description, $sort_routine) = @_;
266 my $dbh = C4
::Context
->dbh;
267 my $sth = $dbh->prepare("UPDATE `class_sort_rules`
268 SET `description` = ?,
270 WHERE `class_sort_rule` = ?");
271 $sth->execute($description, $sort_routine, $class_sort_rule);
275 =head2 DelClassSortRule
277 DelClassSortRule($class_sort_rule);
279 Deletes class_sort_rules row.
283 sub DelClassSortRule
{
285 my ($class_sort_rule) = @_;
286 my $dbh = C4
::Context
->dbh;
287 my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?");
288 $sth->execute($class_sort_rule);
292 =head2 GetSourcesForSortRule
294 my @source = GetSourcesForSortRule($class_sort_rule);
296 Retrieves an array class_source.cn_rule for each source
297 that uses the supplied $class_sort_rule.
301 sub GetSourcesForSortRule
{
303 my ($class_sort_rule) = @_;
305 my $dbh = C4
::Context
->dbh;
306 my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?");
307 $sth->execute($class_sort_rule);
309 while (my ($source) = $sth->fetchrow_array()) {
310 push @sources, $source;
318 my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item);
320 Get the sort key corresponding to the classification part and item part
321 and the defined call number source.
327 my ($cn_source, $cn_class, $cn_item) = @_;
329 my $source_ref = GetClassSource
($cn_source);
330 unless (defined $source_ref) {
331 $source_ref = GetClassSource
(C4
::Context
->preference("DefaultClassificationSource"));
334 if (defined $source_ref) {
335 my $rule_ref = GetClassSortRule
($source_ref->{'class_sort_rule'});
336 if (defined $rule_ref) {
337 $routine = $rule_ref->{'sort_routine'};
341 return GetClassSortKey
($routine, $cn_class, $cn_item);
349 Koha Development Team <http://koha-community.org/>