C4::Koha - Perl Module containing convenience functions for Koha scripts
use C4::Koha;
Koha.pm provides many functions for Koha scripts.
$itemtypename = &GetSupportName($codestring);
Returns a string with the name of the itemtype.
$itemtypes = &GetSupportList();
Returns an array ref containing informations about Support (since itemtype is rather a circulation code when item-level-itypes is used).
build a HTML select with the following code :
my $itemtypes = GetSupportList(); $template->param(itemtypeloop => $itemtypes);
<select name="itemtype" id="itemtype"> <option value=""></option> [% FOREACH itemtypeloo IN itemtypeloop %] [% IF ( itemtypeloo.selected ) %] <option value="[% itemtypeloo.itemtype %]" selected="selected">[% itemtypeloo.description %]</option> [% ELSE %] <option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.description %]</option> [% END %] [% END %] </select>
$itemtypes = &GetItemTypes( style => $style );
Returns information about existing itemtypes.
Params: style: either 'array' or 'hash', defaults to 'hash'. 'array' returns an arrayref, 'hash' return a hashref with the itemtype value as the key
build a HTML select with the following code :
my $itemtypes = GetItemTypes; my @itemtypesloop; foreach my $thisitemtype (sort keys %$itemtypes) { my $selected = 1 if $thisitemtype eq $itemtype; my %row =(value => $thisitemtype, selected => $selected, description => $itemtypes->{$thisitemtype}->{'description'}, ); push @itemtypesloop, \%row; } $template->param(itemtypeloop => \@itemtypesloop);
<form action='<!-- TMPL_VAR name="script_name" -->' method=post> <select name="itemtype"> <option value="">Default</option> <!-- TMPL_LOOP name="itemtypeloop" --> <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="description" --></option> <!-- /TMPL_LOOP --> </select> <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->"> <input type="submit" value="OK" class="button"> </form>
$categories = GetItemTypesCategorized();
Returns a hashref containing search categories. A search category will be put in the hash if at least one of its itemtypes is visible in OPAC. The categories must be part of Authorized Values (ITEMTYPECAT)
@results = GetItemTypesByCategory( $searchcategory );
Returns the itemtype code of all itemtypes included in a searchcategory.
$frameworks = &getframework();
Returns information about existing frameworks
build a HTML select with the following code :
my $frameworks = getframeworks(); my @frameworkloop; foreach my $thisframework (keys %$frameworks) { my $selected = 1 if $thisframework eq $frameworkcode; my %row =( value => $thisframework, selected => $selected, description => $frameworks->{$thisframework}->{'frameworktext'}, ); push @frameworksloop, \%row; } $template->param(frameworkloop => \@frameworksloop);
<form action="[% script_name %] method=post> <select name="frameworkcode"> <option value="">Default</option> [% FOREACH framework IN frameworkloop %] [% IF ( framework.selected ) %] <option value="[% framework.value %]" selected="selected">[% framework.description %]</option> [% ELSE %] <option value="[% framework.value %]">[% framework.description %]</option> [% END %] [% END %] </select> <input type=text name=searchfield value="[% searchfield %]"> <input type="submit" value="OK" class="button"> </form>
$frameworks = GetFrameworksLoop( $frameworkcode );
Returns the loop suggested on getframework(), but ordered by framework description.
build a HTML select with the following code :
$template->param( frameworkloop => GetFrameworksLoop( $frameworkcode ) );
Same as getframework() <form action="[% script_name %] method=post> <select name="frameworkcode"> <option value="">Default</option> [% FOREACH framework IN frameworkloop %] [% IF ( framework.selected ) %] <option value="[% framework.value %]" selected="selected">[% framework.description %]</option> [% ELSE %] <option value="[% framework.value %]">[% framework.description %]</option> [% END %] [% END %] </select> <input type=text name=searchfield value="[% searchfield %]"> <input type="submit" value="OK" class="button"> </form>
$frameworkinfo = &getframeworkinfo($frameworkcode);
Returns information about an frameworkcode.
$itemtype = &getitemtypeinfo($itemtype, [$interface]);
Returns information about an itemtype. The optional $interface argument sets which interface ('opac' or 'intranet') to return the imageurl for. Defaults to intranet.
my $directory = getitemtypeimagedir( 'opac' );
pass in 'opac' or 'intranet'. Defaults to 'opac'.
returns the full path to the appropriate directory containing images.
Find all of the image files in a directory in the filesystem
parameters: a directory name
returns: a list of images in that directory.
Notes: this does not traverse into subdirectories. See _getSubdirectoryNames for help with that. Images are assumed to be files with .gif or .png file extensions. The image names returned do not have the directory name on them.
Find all of the directories in a directory in the filesystem
parameters: a directory name
returns: a list of subdirectories in that directory.
Notes: this does not traverse into subdirectories. Only the first level of subdirectories are returned. The directory names returned don't have the parent directory name on them.
returns: a listref of hashrefs. Each hash represents another collection of images.
{ imagesetname => 'npl', # the name of the image set (npl is the original one) images => listref of image hashrefs }
each image is represented by a hashref like this:
{ KohaImage => 'npl/image.gif', StaffImageUrl => '/intranet-tmpl/prog/img/itemtypeimg/npl/image.gif', OpacImageURL => '/opac-tmpl/prog/itemtypeimg/npl/image.gif' checked => 0 or 1: was this the image passed to this method? Note: I'd like to remove this somehow. }
$printers = &GetPrinters(); @queues = keys %$printers;
Returns information about existing printer queues.
$printers
is a reference-to-hash whose keys are the print queues defined in the printers table of the Koha database. The values are references-to-hash, whose keys are the fields in the printers table.
$printer = GetPrinter( $query, $printers );
Returns the number of pages to display in a pagination bar, given the number of items and the number of items per page.
(@themes) = &getallthemes('opac'); (@themes) = &getallthemes('intranet');
Returns an array of all available themes.
Return a href where a key is associated to a href. You give a query, the name of the key among the fields returned by the query. If you also give as third argument the name of the value, the function returns a href of scalar. The optional 4th argument is an arrayref of items passed to the execute()
call. It is designed to bind parameters to any placeholders in your SQL.
my $query = ' SELECT itemnumber, notforloan, barcode FROM items '; # generic href of any information on the item, href of href. my $iteminfos_of = get_infos_of($query, 'itemnumber'); print $iteminfos_of->{$itemnumber}{barcode}; # specific information, href of scalar my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode'); print $barcode_of_item->{$itemnumber};
my $notforloan_label_of = get_notforloan_label_of();
Each authorised value of notforloan (information available in items and itemtypes) is link to a single label.
Returns a href where keys are authorised values and values are corresponding labels.
foreach my $authorised_value (keys %{$notforloan_label_of}) { printf( "authorised_value: %s => %s\n", $authorised_value, $notforloan_label_of->{$authorised_value} ); }
$authvalcode = GetAuthValCode($kohafield,$frameworkcode);
$authvalcode = GetAuthValCodeFromField($field,$subfield,$frameworkcode);
$subfield
can be undefined
$authvalues = GetAuthorisedValues([$category]);
This function returns all authorised values from the'authorised_value' table in a reference to array of hashrefs.
$category
returns authorised values for just one category (optional).
$opac
If set to a true value, displays OPAC descriptions rather than normal ones when they exist.
$auth_categories = GetAuthorisedValueCategories();
Return an arrayref of all of the available authorised value categories.
$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
Return the lib attribute from authorised_values from the row identified by the passed category and code
Takes $kohafield, $fwcode as parameters.
If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
Returns hashref of Code => description
Returns undef if no authorised value category is defined for the kohafield.
Takes $field, $subfield, $fwcode as parameters.
If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist. $subfield can be undefined
Returns hashref of Code => description
Returns undef if no authorised value category is defined for the given field and subfield
Takes a hash as a parameter. The interface key indicates the description to use in the mapping.
Returns hashref of: "{kohafield},{frameworkcode},{authorised_value}" => "{description}" for all the kohafields, frameworkcodes, and authorised values.
Returns undef if nothing is found.
my $escaped_string = C4::Koha::xml_escape($string);
Convert &, <, >, ', and " in a string to XML entities
Takes $category, $authorised_value as parameters.
If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
Returns authorised value description
my $display_form = C4::Koha::display_marc_indicators($field);
$field
is a MARC::Field object
Generate a display form of the indicators of a variable MARC field, replacing any blanks with '#'.
Takes a hashref of options
Currently supported options are:
'id' An exact quote id 'random' Select a random quote noop When no option is passed in, this sub will return the quote timestamped for the current day
The function returns an anonymous hash following this format:
{ 'source' => 'source-of-quote', 'timestamp' => 'timestamp-value', 'text' => 'text-of-quote', 'id' => 'quote-id' };
my $isbns = NormalizedISBN({ isbn => $isbn, strip_hyphens => [0,1], format => ['ISBN-10', 'ISBN-13'] }); Returns an isbn validated by Business::ISBN. Optionally strips hyphens and/or forces the isbn to be of the specified format. If the string cannot be validated as an isbn, it returns nothing.
my @isbns = GetVariationsOfISBN( $isbn ); Returns a list of variations of the given isbn in both ISBN-10 and ISBN-13 formats, with and without hyphens. In a scalar context, the isbns are returned as a string delimited by ' | '.
my @isbns = GetVariationsOfISBNs( @isbns ); Returns a list of variations of the given isbns in both ISBN-10 and ISBN-13 formats, with and without hyphens. In a scalar context, the isbns are returned as a string delimited by ' | '.
my $is_linked = IsKohaFieldLinked({ kohafield => $kohafield, frameworkcode => $frameworkcode, }); Return 1 if the field is linked
Koha Team