C4::Creators::Template - A class for creating and manipulating template objects in Koha
This module provides methods for creating, retrieving, and otherwise manipulating label template objects used by Koha.
Invoking the I<new> method constructs a new template object containing the default values for a template. The following parameters are optionally accepted as key => value pairs: C<profile_id> A valid profile id to be assciated with this template. NOTE: The profile must exist in the database and B<not> be assigned to another template. C<template_code> A template code. ie. 'Avery 5160 | 1 x 2-5/8' C<template_desc> A readable description of the template. ie. '3 columns, 10 rows of labels' C<page_width> The width of the page measured in the units supplied by the units parameter in this template. C<page_height> The height of the page measured in the same units. C<label_width> The width of a single label on the page this template applies to. C<label_height> The height of a single label on the page. C<top_text_margin> The measure of the top margin on a single label on the page. C<left_text_margin> The measure of the left margin on a single label on the page. C<top_margin> The measure of the top margin of the page. C<left_margin> The measure of the left margin of the page. C<cols> The number of columns of labels on the page. C<rows> The number of rows of labels on the page. C<col_gap> The measure of the gap between the columns of labels on the page. C<row_gap> The measure of the gap between the rows of labels on the page. C<units> The units of measure used for this template. These B<must> match the measures you supply above or bad things will happen to your document. NOTE: The only supported units at present are:
example: my $template = Template->new(); # Creates and returns a new template object with the defaults my $template = C4::Labels::Template->new(profile_id => 1, page_width => 8.5, page_height => 11.0, units => 'INCH'); # Creates and returns a new template object using the supplied values to override the defaults B<NOTE:> This template is I<not> written to the database until save() is invoked. You have been warned!
Invoking the I<retrieve> method constructs a new template object containing the current values for template_id. The method returns a new object upon success and -1 upon failure. Errors are logged to the Apache log. Two further options may be accessed. See the example below for further description. examples: C<my $template = C4::Labels::Template->retrieve(template_id => 1); # Retrieves template record 1 and returns an object containing the record> C<my $template = C4::Labels::Template->retrieve(template_id => 1, convert => 1); # Retrieves template record 1, converts the units to points, and returns an object containing the record> C<my $template = C4::Labels::Template->retrieve(template_id => 1, profile_id => 1); # Retrieves template record 1, converts the units to points, applies the currently associated profile id, and returns an object containing the record.>
Invoking the delete method attempts to delete the template from the database. The method returns -1 upon failure. Errors are logged to the Apache log. NOTE: This method may also be called as a function and passed a key/value pair simply deleteing that template from the database. See the example below. examples: C<my $exitstat = $template->delete(); # to delete the record behind the $template object> C<my $exitstat = C4::Labels::Template::delete(template_id => 1); # to delete template record 1>
Invoking the I<save> method attempts to insert the template into the database if the template is new and update the existing template record if the template exists. The method returns the new record template_id upon success and -1 upon failure (This avoids template_ids conflicting with a record template_id of 1). Errors are logged to the Apache log. example: C<my $template_id = $template->save(); # to save the record behind the $template object>
Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors. example: C<my $value = $template->get_attr($attribute);>
Invoking the I<set_attr> method will set the value of the supplied attributes to the supplied values. The method accepts key/value pairs separated by commas. example: C<$template->set_attr(attribute => value);>
Invoking the I<get_label_position> method will return the row, column coordinates on the starting page and the lower left x,y coordinates on the starting label for the template object. examples: C<my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);>
Chris Nighswonger <cnighswonger AT foundations DOT edu>
Copyright 2009 Foundations Bible College.
This file is part of Koha.
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Koha; if not, see <http://www.gnu.org/licenses>.
Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.