From 4d0e0fec726dda8d37d20e3b2f1615d5f96edc61 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Fri, 20 Jun 2008 13:02:01 -0500 Subject: [PATCH] Bug 2176 (4/5): adding RSS feed for patron overdue alerts opac-mymessages.pl and opac-mymessages.tmpl generate an RSS feed of a patron's messages from the message_queue. Some more methods in C4::Letters to let us pluck out the right entries in the queue. Signed-off-by: Joshua Ferraro --- C4/Letters.pm | 92 ++++++++++++++++++- .../prog/en/modules/opac-mymessages.tmpl | 24 +++++ opac/opac-mymessages.pl | 49 ++++++++++ 3 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-mymessages.tmpl create mode 100755 opac/opac-mymessages.pl diff --git a/C4/Letters.pm b/C4/Letters.pm index a01d391c02..d82e2b82ac 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -24,6 +24,7 @@ use Mail::Sendmail; # use C4::Suggestions; use C4::Members; use C4::Log; +use C4::SMS; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -581,17 +582,104 @@ sub SendQueuedMessages { return scalar( @$unsent_messages ); } +=head2 GetRSSMessages + +=over 4 + +my $message_list = GetRSSMessages( { limit => 10, borrowernumber => '14' } ) + +returns a listref of all queued RSS messages for a particular person. + +=back + +=cut + +sub GetRSSMessages { + my $params = shift; + + return unless $params; + return unless ref $params; + return unless $params->{'borrowernumber'}; + + return _get_unsent_messages( { message_transport_type => 'rss', + limit => $params->{'limit'}, + borrowernumber => $params->{'borrowernumber'}, } ); +} + +=head2 GetQueuedMessages + +=over 4 + +my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } ); + +fetches messages out of the message queue. + +returns: +list of hashes, each has represents a message in the message queue. + +=back + +=cut + +sub GetQueuedMessages { + my $params = shift; + + my $dbh = C4::Context->dbh(); + my $statement = << 'ENDSQL'; +SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued +FROM message_queue +ENDSQL + + my @query_params; + my @whereclauses; + if ( exists $params->{'borrowernumber'} ) { + push @whereclauses, ' borrowernumber = ? '; + push @query_params, $params->{'borrowernumber'}; + } + + if ( @whereclauses ) { + $statement .= ' WHERE ' . join( 'AND', @whereclauses ); + } + + if ( defined $params->{'limit'} ) { + $statement .= ' LIMIT ? '; + push @query_params, $params->{'limit'}; + } + + my $sth = $dbh->prepare( $statement ); + my $result = $sth->execute( @query_params ); + my $messages = $sth->fetchall_arrayref({}); + return $messages; +} + sub _get_unsent_messages { + my $params = shift; my $dbh = C4::Context->dbh(); my $statement = << 'ENDSQL'; -SELECT message_id, borrowernumber, subject, content, type, status, time_queued +SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued FROM message_queue WHERE status = 'pending' ENDSQL + my @query_params; + if ( ref $params ) { + if ( $params->{'message_transport_type'} ) { + $statement .= ' AND message_transport_type = ? '; + push @query_params, $params->{'message_transport_type'}; + } + if ( $params->{'borrowernumber'} ) { + $statement .= ' AND borrowernumber = ? '; + push @query_params, $params->{'borrowernumber'}; + } + if ( $params->{'limit'} ) { + $statement .= ' limit ? '; + push @query_params, $params->{'limit'}; + } + } + my $sth = $dbh->prepare( $statement ); - my $result = $sth->execute(); + my $result = $sth->execute( @query_params ); my $unsent_messages = $sth->fetchall_arrayref({}); return $unsent_messages; } diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-mymessages.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-mymessages.tmpl new file mode 100644 index 0000000000..78d496dec0 --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-mymessages.tmpl @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + <!-- TMPL_VAR ESCAPE=HTML NAME="subject" --> + + + + + + + + diff --git a/opac/opac-mymessages.pl b/opac/opac-mymessages.pl new file mode 100755 index 0000000000..3cfd4fcb0e --- /dev/null +++ b/opac/opac-mymessages.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use warnings; +require Exporter; +use CGI; + +use C4::Auth; +use C4::Context; +use C4::Koha; +use C4::Letters; +use C4::Output; + +my $query = CGI->new(); + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => 'opac-mymessages.tmpl', + query => $query, + type => 'opac', + authnotrequired => 0, + flagsrequired => { borrow => 1 }, + debug => 1, + } +); + + +my $messages = C4::Letters::GetRSSMessages( { borrowernumber => $borrowernumber, + limit => 20 } ); + +$template->param( message_list => $messages, + ); + +output_html_with_http_headers $query, $cookie, $template->output; -- 2.39.2