|
Lines 486-517
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 parameter to ignore library 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 |
my @where_args; |
| 505 |
if ($branch_limit && $no_limit) { |
| 506 |
$select_clause .= ', IF (branchcode = ? OR branchcode IS NULL, 0, 1) as restricted'; |
| 507 |
push @where_args, $branch_limit; |
| 508 |
} |
| 501 |
my $query = qq{ |
509 |
my $query = qq{ |
| 502 |
SELECT DISTINCT av.* |
510 |
$select_clause |
| 503 |
FROM authorised_values av |
511 |
FROM authorised_values av |
| 504 |
}; |
512 |
}; |
| 505 |
$query .= qq{ |
513 |
$query .= qq{ |
| 506 |
LEFT JOIN authorised_values_branches ON ( id = av_id ) |
514 |
LEFT JOIN authorised_values_branches ON ( id = av_id ) |
| 507 |
} if $branch_limit; |
515 |
} if $branch_limit; |
| 508 |
my @where_strings; |
516 |
my @where_strings; |
| 509 |
my @where_args; |
|
|
| 510 |
if($category) { |
517 |
if($category) { |
| 511 |
push @where_strings, "category = ?"; |
518 |
push @where_strings, "category = ?"; |
| 512 |
push @where_args, $category; |
519 |
push @where_args, $category; |
| 513 |
} |
520 |
} |
| 514 |
if($branch_limit) { |
521 |
if($branch_limit && !defined $no_limit) { |
| 515 |
push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; |
522 |
push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; |
| 516 |
push @where_args, $branch_limit; |
523 |
push @where_args, $branch_limit; |
| 517 |
} |
524 |
} |