Make NewsletterCollection subscribable.
This commit is contained in:
parent
cfa018e04b
commit
0fa97d2d9d
3 changed files with 157 additions and 7 deletions
|
|
@ -10,6 +10,40 @@ use base qw{
|
||||||
WebGUI::Asset::Wobject
|
WebGUI::Asset::Wobject
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub canSubscribe {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return !$self->session->user->isVisitor && !$self->isSubscribed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub canUnsubscribe {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return !$self->session->user->isVisitor && $self->isSubscribed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub configureMailingForm {
|
||||||
|
my $self = shift;
|
||||||
|
my $f = $self->next::method;
|
||||||
|
|
||||||
|
tie my %issues, 'Tie::IxHash', (
|
||||||
|
'' => 'Choose issue...',
|
||||||
|
map { $_->getId => $_->getTitle }
|
||||||
|
@{ $self->getIssues }
|
||||||
|
);
|
||||||
|
|
||||||
|
$f->selectBox(
|
||||||
|
name => $issue,
|
||||||
|
label => 'Issue',
|
||||||
|
options => $self->getIssues
|
||||||
|
);
|
||||||
|
|
||||||
|
return $f;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub definition {
|
sub definition {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
@ -32,6 +66,29 @@ sub definition {
|
||||||
return $class->SUPER::definition( $session, $definition );
|
return $class->SUPER::definition( $session, $definition );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getIssues {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $issues = $self->getLineage( [ 'children' ], {
|
||||||
|
returnObjects => 1,
|
||||||
|
orderByClause => 'revisionDate desc',
|
||||||
|
} );
|
||||||
|
|
||||||
|
return $issues;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getRecipients {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my @subscribers = $db->buildArray( 'select userId from NewsletterCollection_subscriptions where assetId=?', [
|
||||||
|
$self->getId,
|
||||||
|
] );
|
||||||
|
|
||||||
|
return \@subscribers;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub generateEmailContent {
|
sub generateEmailContent {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
@ -47,7 +104,19 @@ sub generateEmailContent {
|
||||||
return $issue->view;
|
return $issue->view;
|
||||||
}
|
}
|
||||||
|
|
||||||
##-------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
sub isSubscribed {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->getId;
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
return $db->quickScalar( 'select 1 from NewsletterCollection_subscriptions where assetId=? and userId=?', [
|
||||||
|
$self->getId,
|
||||||
|
$userId,
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
##----------------------------------------------------------------------------
|
||||||
#sub prepareView {
|
#sub prepareView {
|
||||||
# my $self = shift;
|
# my $self = shift;
|
||||||
# $self->SUPER::prepareView();
|
# $self->SUPER::prepareView();
|
||||||
|
|
@ -56,20 +125,21 @@ sub generateEmailContent {
|
||||||
# $self->{_viewTemplate} = $template;
|
# $self->{_viewTemplate} = $template;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
||||||
my $issues = $self->getLineage( [ 'children' ], {
|
|
||||||
returnObjects => 1,
|
|
||||||
orderByClause => 'revisionDate desc',
|
|
||||||
} );
|
|
||||||
|
|
||||||
my $output = $self->getToolbar if $session->var->isAdminOn;
|
my $output = $self->getToolbar if $session->var->isAdminOn;
|
||||||
|
|
||||||
|
my $issues = $self->getIssues;
|
||||||
return $output . "No issues yet" unless scalar @{ $issues };
|
return $output . "No issues yet" unless scalar @{ $issues };
|
||||||
|
|
||||||
|
$output .= $self->isSubscribed
|
||||||
|
? '<p><a href="' . $self->getUrl( 'func=unsubscribe' ) . '">Unsubscribe</a></p>'
|
||||||
|
: '<p><a href="' . $self->getUrl( 'func=subscribe' ) . '">Subscribe</a></p>'
|
||||||
|
;
|
||||||
|
|
||||||
$output .= '<p>Issues: <ul>';
|
$output .= '<p>Issues: <ul>';
|
||||||
$output .=
|
$output .=
|
||||||
join '',
|
join '',
|
||||||
|
|
@ -89,5 +159,55 @@ sub view {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub subscribe {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->getId;
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
$db->write( 'replace into NewsletterCollection_subscriptions set assetId=?, userId=?', [
|
||||||
|
$self->getId,
|
||||||
|
$userId,
|
||||||
|
] );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub unsubscribe {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->getId;
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
$db->write( 'delete from NewsletterCollection_subscriptions where assetId=? and userId=?', [
|
||||||
|
$self->getId,
|
||||||
|
$userId,
|
||||||
|
] );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub www_subscribe {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ( $self->canSubscribe ) {
|
||||||
|
$self->subscribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub www_unsubscribe {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ( $self->canUnsubscribe ) {
|
||||||
|
$self->unsubscribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,17 @@ use Class::C3;
|
||||||
|
|
||||||
use WebGUI::Macro;
|
use WebGUI::Macro;
|
||||||
|
|
||||||
|
##----------------------------------------------------------------------------
|
||||||
|
#sub configureMailingForm {
|
||||||
|
# my $self = shift;
|
||||||
|
# my $f = WebGUI::HTMLForm->new( $session, { action => $self->getUrl } );
|
||||||
|
# $f->hidden(
|
||||||
|
# name => 'func'
|
||||||
|
# value => '
|
||||||
|
#
|
||||||
|
# return $f;
|
||||||
|
#}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub definition {
|
sub definition {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
@ -73,6 +84,17 @@ sub processContentAsUser {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##----------------------------------------------------------------------------
|
||||||
|
#sub www_configureMailing {
|
||||||
|
# my $self = shift;
|
||||||
|
#
|
||||||
|
# my $f = $self->configureMailingForm;
|
||||||
|
#
|
||||||
|
# $f->submit( 'Next step' );
|
||||||
|
#
|
||||||
|
# return $self->processStyle( $f->print );
|
||||||
|
#}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub www_previewEmail {
|
sub www_previewEmail {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,14 @@ sub installNewsletterCollection {
|
||||||
);
|
);
|
||||||
EOSQL
|
EOSQL
|
||||||
|
|
||||||
|
$session->db->write(<<EOSQL2);
|
||||||
|
create table if not exists NewsletterCollection_subscriptions (
|
||||||
|
assetId char(22) binary not null,
|
||||||
|
userId char(22) binary not null,
|
||||||
|
primary key( assetId, userId )
|
||||||
|
);
|
||||||
|
EOSQL2
|
||||||
|
|
||||||
print "Done.\n";
|
print "Done.\n";
|
||||||
}
|
}
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue