Main Koha release repository https://koha-community.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

132 lines
3.6 KiB

  1. package Koha::Template::Plugin::AuthorisedValues;
  2. # Copyright 2012 ByWater Solutions
  3. # Copyright 2013-2014 BibLibre
  4. #
  5. # Koha is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Koha is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Koha; if not, see <http://www.gnu.org/licenses>.
  17. use Modern::Perl;
  18. use Template::Plugin;
  19. use base qw( Template::Plugin );
  20. use C4::Koha;
  21. use Koha::AuthorisedValues;
  22. sub GetByCode {
  23. my ( $self, $category, $code, $opac ) = @_;
  24. my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
  25. return $av->count
  26. ? $opac
  27. ? $av->next->opac_description
  28. : $av->next->lib
  29. : $code;
  30. }
  31. sub Get {
  32. my ( $self, $category, $selected, $opac ) = @_;
  33. return GetAuthorisedValues( $category, $selected, $opac );
  34. }
  35. sub GetAuthValueDropbox {
  36. my ( $self, $category ) = @_;
  37. my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
  38. return Koha::AuthorisedValues->search(
  39. {
  40. branchcode => $branch_limit,
  41. category => $category,
  42. },
  43. {
  44. order_by => [ 'category', 'lib', 'lib_opac' ],
  45. }
  46. );
  47. }
  48. sub GetCategories {
  49. my ( $self, $params ) = @_;
  50. my $selected = $params->{selected};
  51. my @categories = Koha::AuthorisedValues->new->categories;
  52. return [
  53. map {
  54. {
  55. category => $_,
  56. ( ( $selected and $selected eq $_ ) ? ( selected => 1 ) : () ),
  57. }
  58. } @categories
  59. ];
  60. }
  61. sub GetDescriptionsByKohaField {
  62. my ( $self, $params ) = @_;
  63. return Koha::AuthorisedValues->get_descriptions_by_koha_field(
  64. { kohafield => $params->{kohafield} } );
  65. }
  66. sub GetDescriptionByKohaField {
  67. my ( $self, $params ) = @_;
  68. my $av = Koha::AuthorisedValues->get_description_by_koha_field(
  69. {
  70. kohafield => $params->{kohafield},
  71. authorised_value => $params->{authorised_value},
  72. }
  73. );
  74. my $description = $av->{lib} || $params->{authorised_value} || '';
  75. return $params->{opac}
  76. ? $av->{opac_description} || $description
  77. : $description;
  78. }
  79. 1;
  80. =head1 NAME
  81. Koha::Template::Plugin::AuthorisedValues - TT Plugin for authorised values
  82. =head1 SYNOPSIS
  83. [% USE AuthorisedValues %]
  84. [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
  85. [% AuthorisedValues.GetAuthValueDropbox( $category, $default ) %]
  86. =head1 ROUTINES
  87. =head2 GetByCode
  88. In a template, you can get the description for an authorised value with
  89. the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
  90. =head2 GetAuthValueDropbox
  91. The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
  92. =head2 GetDescriptionsByKohaField
  93. The parameters are identical to those used by the subroutine Koha::AuthorisedValues->get_descriptions_by_koha_field
  94. =head2 GetDescriptionByKohaField
  95. The parameters are identical to those used by the subroutine Koha::AuthorisedValues->get_description_by_koha_field
  96. =head1 AUTHOR
  97. Kyle M Hall <kyle@bywatersolutions.com>
  98. Jonathan Druart <jonathan.druart@biblibre.com>
  99. =cut