C4::Letters - Give functions for Letters management
use C4::Letters;
"Letters" is the tool used in Koha to manage informations sent to the patrons and/or the library. This include some cron jobs like late issues, as well as other tasks like sending a mail to users that have subscribed to a "serial issue alert" (= being warned every time a new issue has arrived at the library) Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too.
$letters = &GetLetters($module); returns informations about letters. if needed, $module filters for letters given module DEPRECATED - You must use Koha::Notice::Templates instead The group by clause is confusing and can lead to issues
my $letter_templates = GetLetterTemplates( { module => 'circulation', code => 'my code', branchcode => 'CPL', # '' for default, } ); Return a hashref of letter templates.
my $letters = GetLettersAvailableForALibrary( { branchcode => 'CPL', # '' for default module => 'circulation', } ); Return an arrayref of letters, sorted by name. If a specific letter exist for the given branchcode, it will be retrieve. Otherwise the default letter will be.
DelLetter( { branchcode => 'CPL', module => 'circulation', code => 'my code', [ mtt => 'email', ] } ); Delete the letter. The mtt parameter is facultative. If not given, all templates mathing the other parameters will be removed.
my $err = &SendAlerts($type, $externalid, $letter_code); Parameters: - $type : the type of alert - $externalid : the id of the "object" to query - $letter_code : the notice template to use C<&SendAlerts> sends an email notice directly to a patron or a vendor. Currently it supports ($type): - claim serial issues (claimissues) - claim acquisition orders (claimacquisition) - send acquisition orders to the vendor (orderacquisition) - notify patrons about newly received serial issues (issue) - notify patrons when their account is created (members) Returns undef or { error => 'message } on failure. Returns true on success.
my $letter = GetPreparedLetter( { module => "letter module", # mandatory letter_code => "letter code", # mandatory branchcode => "for letter selection", # if missing default system letter taken objects => {}, # a hashref with object names as keys and objects as values tables => {}, # a hashref with table names as keys. Values are either: # - a scalar - primary key value # - an arrayref - primary key values # - a hashref - full record substitute => {}, # custom substitution key/value pairs repeat => '', # records to be substituted on consecutive lines, accepts either: # - an arrayref # tries to guess what needs substituting by taking remaining # << >> tokensr; not recommended # - a hashref token => @tables # replaces <token> << >> << >> </token> subtemplate for each # @tables row; table is a hashref as above want_librarian => '' # boolean, if set to true triggers librarian details substitution # from the userenv } );
Return value: letter fields hashref (title & content useful)
parameters : - $letter : a hash to letter fields (title & content useful) - $table : the Koha table to parse. - $values_in : table record hashref parse all fields from a table, and replace values in title & content with the appropriate value (not exported sub, used only internally)
my $success = EnqueueLetter( { letter => $letter, borrowernumber => '12', message_transport_type => 'email' } )
Places a letter in the message_queue database table, which will eventually get processed (sent) by the process_message_queue.pl cronjob when it calls SendQueuedMessages.
Return message_id on success
Parameters * letter - required; A letter hashref as returned from GetPreparedLetter * message_transport_type - required; One of the available mtts * borrowernumber - optional if 'to_address' is passed; The borrowernumber of the patron we enqueuing the notice for * to_address - optional if 'borrowernumber' is passed; The destination email address for the notice (defaults to patron->notice_email_address) * from_address - optional; The from address for the notice, defaults to patron->library->from_email_address * reply_address - optional; The reply address for the notice, defaults to patron->library->reply_to
my $sent = SendQueuedMessages({ message_id => $id, borrowernumber => $who_letter_is_for, letter_code => $letter_code, # can be scalar or arrayref type => $type, # can be scalar or arrayref limit => 50, verbose => 1, where => $where, });
Sends 'pending' messages from the queue, based on parameters.
The (optional) message_id, borrowernumber, letter_code, type and where parameter are used to select which pending messages will be processed. The limit parameter determines the volume of results, i.e. sent messages.
The optional verbose parameter can be used to generate debugging output.
Returns number of messages sent.
my $message_list = GetRSSMessages( { limit => 10, borrowernumber => '14' } )
returns a listref of all queued RSS messages for a particular person.
my $message_list = GetPrintMessages( { borrowernumber => $borrowernumber } )
Returns a arrayref of all queued print messages (optionally, for a particular person).
my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } );
Fetches a list of messages from the message queue optionally filtered by borrowernumber and limited to specified limit.
Return is an arrayref of hashes, each has represents a message in the message queue.
my @mtt = GetMessageTransportTypes(); returns an arrayref of transport types
my $message = C4::Letters::Message($message_id);
Attempt to resend a message which has failed previously. my $has_been_resent = C4::Letters::ResendMessage($message_id); Updates the message to 'pending' status so that it will be resent later on. returns 1 on success, 0 on failure, undef if no message was found
_add_attachments({ letter => $letter, attachments => $attachments }); named parameters: letter - the standard letter hashref attachments - listref of attachments. each attachment is a hashref of: type - the mime type, like 'text/plain' content - the actual attachment filename - the name of the attachment. returns your letter object, with the content updated. This routine picks the I<content> of I<letter> and generates a MIME email, attaching the passed I<attachments> using Koha::Email. The content is replaced by the string representation of the MIME object, and the content-type is updated for later handling.
This function's parameter hash reference takes the following optional named parameters: message_transport_type: method of message sending (e.g. email, sms, etc.) Can be a single string, or an arrayref of strings borrowernumber : who the message is to be sent letter_code : type of message being sent (e.g. PASSWORD_RESET) Can be a single string, or an arrayref of strings message_id : the message_id of the message. In that case the sub will return only 1 result limit : maximum number of messages to send This function returns an array of matching hash referenced rows from message_queue with some borrower information added.
$content = add_tt_filters( $content );
Add TT filters to some specific fields if needed.
For now we only add the Remove_MARC_punctuation TT filter to biblio and biblioitem fields
my $item = Koha::Items->find(...)->unblessed; my @item_content_fields = qw( date_due title barcode author itemnumber ); my $item_content = C4::Letters::get_item_content({ item => $item, item_content_fields => \@item_content_fields });
This function generates a tab-separated list of values for the passed item. Dates are formatted following the current setup.