<<

NAME

C4::Message - object for messages in the message_queue table

SYNOPSIS

How to add a new message to the queue:

  use C4::Message;
  use C4::Items;
  my $borrower = { borrowernumber => 1 };
  my $item     = Koha::Items->find($itemnumber)->unblessed;
  my $letter =  C4::Letters::GetPreparedLetter (
      module => 'circulation',
      letter_code => 'CHECKOUT',
      branchcode => $branch,
      tables => {
          'biblio', $item->{biblionumber},
          'biblioitems', $item->{biblionumber},
      },
  );
  C4::Message->enqueue($letter, $borrower->{borrowernumber}, 'email');

How to update a borrower's last checkout message:

  use C4::Message;
  my $borrower = { borrowernumber => 1 };
  my $message  = C4::Message->find_last_message($borrower, 'CHECKOUT', 'email');
  $message->append("you also checked out some other book....");
  $message->update;

DESCRIPTION

This module presents an OO interface to the message_queue. Previously, you could only add messages to the message_queue via C4::Letters::EnqueueMessage(). With this module, you can also get previously inserted messages, manipulate them, and save them back to the database.

Class Methods

C4::Message->new(\%attributes)

This method creates an in-memory version of a message object.

C4::Message->find($id)

This method searches the message_queue table for a row with the given message_id and it'll return a C4::Message object if it finds one.

C4::Message->find_last_message($borrower, $letter_code, $transport)

This method is used to get the borrower's most recent, pending, check-in or checkout message. (This makes it possible to add more information to the message before it gets sent out.)

C4::Message->enqueue($letter, $borrower, $transport)

This is a front-end for C4::Letters::EnqueueLetter() that adds metadata to the message.

Instance Methods

$message->update()

This saves the $message object back to the database. It needs to have already been created via enqueue for this to work.

$message->metadata(\%new_metadata)

This method automatically serializes and deserializes the metadata attribute. (It is stored in YAML format.)

$message->append(\%letter)

If passed a hashref, this method will assume that the hashref is in the form that C4::Letters::getletter() returns. It will append the body of the letter to the message.

$message->append($string)

If passed a string, it'll append the string to the message.

Attributes Accessors

$message->message_id

$message->borrowernumber

$message->subject

$message->content

$message->metadata

$message->letter_code

$message->message_transport_type

$message->status

$message->time_queued

$message->to_address

$message->from_address

$message->content_type

SEE ALSO

C4::Circulation, C4::Letters, C4::Members::Messaging

AUTHOR

John Beppu <john.beppu@liblime.com>

<<