Lines 486-505
C<$opac> If set to a true value, displays OPAC descriptions rather than normal o
Link Here
|
486 |
sub GetAuthorisedValues { |
486 |
sub GetAuthorisedValues { |
487 |
my $category = shift // ''; # optional parameter |
487 |
my $category = shift // ''; # optional parameter |
488 |
my $opac = shift ? 1 : 0; # normalise to be safe |
488 |
my $opac = shift ? 1 : 0; # normalise to be safe |
|
|
489 |
my $options = shift // ''; |
490 |
my $no_limit = $options->{'no_limit'} if $options; #optional paramater to ignore branch limitation |
489 |
|
491 |
|
490 |
# Is this cached already? |
492 |
# Is this cached already? |
491 |
my $branch_limit = |
493 |
my $branch_limit = |
492 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
494 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
493 |
my $cache_key = |
495 |
my $cache_key = |
494 |
"AuthorisedValues-$category-$opac-$branch_limit"; |
496 |
"AuthorisedValues-$category-$opac-$branch_limit-$no_limit"; |
495 |
my $cache = Koha::Caches->get_instance(); |
497 |
my $cache = Koha::Caches->get_instance(); |
496 |
my $result = $cache->get_from_cache($cache_key); |
498 |
my $result = $cache->get_from_cache($cache_key); |
497 |
return $result if $result; |
499 |
return $result if $result; |
498 |
|
500 |
|
499 |
my @results; |
501 |
my @results; |
500 |
my $dbh = C4::Context->dbh; |
502 |
my $dbh = C4::Context->dbh; |
|
|
503 |
my $select_clause = 'SELECT av.*'; |
504 |
$select_clause .= ", GROUP_CONCAT( authorised_values_branches.branchcode SEPARATOR '-' ) as restricted_to" if $no_limit; |
501 |
my $query = qq{ |
505 |
my $query = qq{ |
502 |
SELECT DISTINCT av.* |
506 |
$select_clause |
503 |
FROM authorised_values av |
507 |
FROM authorised_values av |
504 |
}; |
508 |
}; |
505 |
$query .= qq{ |
509 |
$query .= qq{ |
Lines 511-523
sub GetAuthorisedValues {
Link Here
|
511 |
push @where_strings, "category = ?"; |
515 |
push @where_strings, "category = ?"; |
512 |
push @where_args, $category; |
516 |
push @where_args, $category; |
513 |
} |
517 |
} |
514 |
if($branch_limit) { |
518 |
if($branch_limit && !defined $no_limit) { |
515 |
push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; |
519 |
push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; |
516 |
push @where_args, $branch_limit; |
520 |
push @where_args, $branch_limit; |
517 |
} |
521 |
} |
518 |
if(@where_strings > 0) { |
522 |
if(@where_strings > 0) { |
519 |
$query .= " WHERE " . join(" AND ", @where_strings); |
523 |
$query .= " WHERE " . join(" AND ", @where_strings); |
520 |
} |
524 |
} |
|
|
525 |
$query .= ' GROUP BY av.id '; |
521 |
$query .= ' ORDER BY category, ' . ( |
526 |
$query .= ' ORDER BY category, ' . ( |
522 |
$opac ? 'COALESCE(lib_opac, lib)' |
527 |
$opac ? 'COALESCE(lib_opac, lib)' |
523 |
: 'lib, lib_opac' |
528 |
: 'lib, lib_opac' |