Lines 21-26
use C4::ClassSource qw( GetClassSources );
Link Here
|
21 |
use Koha::DateUtils qw( dt_from_string ); |
21 |
use Koha::DateUtils qw( dt_from_string ); |
22 |
use Koha::ItemTypes; |
22 |
use Koha::ItemTypes; |
23 |
use Koha::Libraries; |
23 |
use Koha::Libraries; |
|
|
24 |
use Koha::AuthorisedValueCategories; |
24 |
|
25 |
|
25 |
=head1 NAME |
26 |
=head1 NAME |
26 |
|
27 |
|
Lines 298-313
sub build_authorized_values_list {
Link Here
|
298 |
|
299 |
|
299 |
my @authorised_values; |
300 |
my @authorised_values; |
300 |
my %authorised_lib; |
301 |
my %authorised_lib; |
|
|
302 |
my %authorised_category; |
301 |
|
303 |
|
302 |
# builds list, depending on authorised value... |
304 |
# builds list, depending on authorised value... |
303 |
|
305 |
|
304 |
#---- branch |
306 |
#---- branch |
305 |
my $category = $tagslib->{$tag}->{$subfield}->{authorised_value}; |
307 |
my $category = $tagslib->{$tag}->{$subfield}->{authorised_value}; |
|
|
308 |
my $avc = Koha::AuthorisedValueCategories->find( $category ); |
306 |
if ( $category eq "branches" ) { |
309 |
if ( $category eq "branches" ) { |
307 |
my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); |
310 |
my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); |
308 |
while ( my $l = $libraries->next ) { |
311 |
while ( my $l = $libraries->next ) { |
309 |
push @authorised_values, $l->branchcode; |
312 |
push @authorised_values, $l->branchcode; |
310 |
$authorised_lib{$l->branchcode} = $l->branchname; |
313 |
$authorised_lib{$l->branchcode} = $l->branchname; |
|
|
314 |
$authorised_category{$l->branchcode} = $category; |
311 |
} |
315 |
} |
312 |
} |
316 |
} |
313 |
elsif ( $category eq "itemtypes" ) { |
317 |
elsif ( $category eq "itemtypes" ) { |
Lines 318-323
sub build_authorized_values_list {
Link Here
|
318 |
while ( $itemtype = $itemtypes->next ) { |
322 |
while ( $itemtype = $itemtypes->next ) { |
319 |
push @authorised_values, $itemtype->itemtype; |
323 |
push @authorised_values, $itemtype->itemtype; |
320 |
$authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; |
324 |
$authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; |
|
|
325 |
$authorised_category{$itemtype->itemtype} = $category; |
321 |
} |
326 |
} |
322 |
$value = $itemtype unless ($value); |
327 |
$value = $itemtype unless ($value); |
323 |
} |
328 |
} |
Lines 334-361
sub build_authorized_values_list {
Link Here
|
334 |
($class_source eq $default_source); |
339 |
($class_source eq $default_source); |
335 |
push @authorised_values, $class_source; |
340 |
push @authorised_values, $class_source; |
336 |
$authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; |
341 |
$authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; |
|
|
342 |
$authorised_category{$class_source} = $category; |
337 |
} |
343 |
} |
338 |
$value = $default_source unless $value; |
344 |
$value = $default_source unless $value; |
339 |
} |
345 |
} |
340 |
else { |
346 |
else { |
341 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{branch} : ''; |
347 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{branch} : ''; |
342 |
my $query = 'SELECT authorised_value, lib FROM authorised_values'; |
348 |
my $query = 'SELECT authorised_value, lib, category FROM authorised_values'; |
343 |
$query .= ' LEFT JOIN authorised_values_branches ON ( id = av_id )' if $branch_limit; |
349 |
$query .= ' LEFT JOIN authorised_values_branches ON ( id = av_id )' if $branch_limit; |
344 |
$query .= ' WHERE category = ?'; |
350 |
$query .= ' WHERE category = ?'; |
345 |
$query .= ' AND ( branchcode = ? OR branchcode IS NULL )' if $branch_limit; |
351 |
$query .= ' AND ( branchcode = ? OR branchcode IS NULL )' if $branch_limit; |
346 |
$query .= ' GROUP BY authorised_value,lib ORDER BY lib, lib_opac'; |
352 |
$query .= ' OR category = ?' if $avc->parent; |
|
|
353 |
$query .= ' GROUP BY authorised_value,lib, category ORDER BY lib, lib_opac'; |
347 |
my $authorised_values_sth = C4::Context->dbh->prepare($query); |
354 |
my $authorised_values_sth = C4::Context->dbh->prepare($query); |
348 |
|
355 |
|
349 |
$authorised_values_sth->execute( |
356 |
$authorised_values_sth->execute( |
350 |
$tagslib->{$tag}->{$subfield}->{authorised_value}, |
357 |
$tagslib->{$tag}->{$subfield}->{authorised_value}, |
351 |
$branch_limit ? $branch_limit : (), |
358 |
$branch_limit ? $branch_limit : (), |
|
|
359 |
$avc->parent ? $avc->parent : (), |
352 |
); |
360 |
); |
353 |
|
361 |
|
354 |
push @authorised_values, ""; |
362 |
push @authorised_values, ""; |
355 |
|
363 |
|
356 |
while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { |
364 |
while ( my ( $value, $lib, $this_category ) = $authorised_values_sth->fetchrow_array ) { |
357 |
push @authorised_values, $value; |
365 |
push @authorised_values, $value; |
358 |
$authorised_lib{$value} = $lib; |
366 |
$authorised_lib{$value} = $lib; |
|
|
367 |
$authorised_category{$value} = $this_category; |
359 |
} |
368 |
} |
360 |
} |
369 |
} |
361 |
|
370 |
|
Lines 366-372
sub build_authorized_values_list {
Link Here
|
366 |
default => $value, |
375 |
default => $value, |
367 |
values => \@authorised_values, |
376 |
values => \@authorised_values, |
368 |
labels => \%authorised_lib, |
377 |
labels => \%authorised_lib, |
|
|
378 |
avcs => \%authorised_category, |
369 |
( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ), |
379 |
( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ), |
|
|
380 |
avc => $avc, |
370 |
}; |
381 |
}; |
371 |
|
382 |
|
372 |
} |
383 |
} |