Skip to content

Commit

Permalink
Bug 2176 (4/5): adding RSS feed for patron overdue alerts
Browse files Browse the repository at this point in the history
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 <jmf@liblime.com>
  • Loading branch information
amoore authored and Joshua Ferraro committed Jun 20, 2008
1 parent 2cae4ef commit 4d0e0fe
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 2 deletions.
92 changes: 90 additions & 2 deletions C4/Letters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions koha-tmpl/opac-tmpl/prog/en/modules/opac-mymessages.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title></title>
<link></link>
<description></description>
<language></language>
<pubDate></pubDate>
<lastBuildDate></lastBuildDate>
<docs></docs>
<generator></generator>
<managingEditor></managingEditor>
<webMaster></webMaster>
<!-- TMPL_LOOP NAME="message_list" -->
<item>
<title><!-- TMPL_VAR ESCAPE=HTML NAME="subject" --></title>
<link><!-- TMPL_VAR ESCAPE=HTML NAME="title" --></link>
<description><!-- TMPL_VAR ESCAPE=HTML NAME="content"--></description>
<pubDate><!-- TMPL_VAR ESCAPE=HTML NAME="time_queued" --></pubDate>
<guid><!-- TMPL_VAR ESCAPE=HTML NAME="title" --></guid>
</item>
<!-- /TMPL_LOOP -->
</channel>
</rss>
49 changes: 49 additions & 0 deletions opac/opac-mymessages.pl
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 4d0e0fe

Please sign in to comment.