Merge branch 'registration_plugin' into mailcommand
Conflicts: sbin/install_newsletter.pl
This commit is contained in:
commit
a15b6a0edb
4 changed files with 237 additions and 0 deletions
191
lib/WebGUI/Registration/Step/MailingSubscribe.pm
Normal file
191
lib/WebGUI/Registration/Step/MailingSubscribe.pm
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
package WebGUI::Registration::Step::MailingSubscribe;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Tie::IxHash;
|
||||
use List::MoreUtils qw{ uniq };
|
||||
|
||||
use WebGUI::Form::Checkbox;
|
||||
|
||||
use base qw{ WebGUI::Registration::Step };
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getAvailableMailings {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $availableMailings = WebGUI::Asset->getRoot( $session )->getLineage( ['descendants'], {
|
||||
returnObjects => 1,
|
||||
isa => 'WebGUI::Asset::Wobject::NewsletterCollection',
|
||||
} );
|
||||
|
||||
return $availableMailings;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub apply {
|
||||
my $self = shift;
|
||||
my $user = $self->registration->instance->user;
|
||||
|
||||
my $subscribeTo = {
|
||||
map { $_ => 1 } @{ $self->getConfigurationData->{ subscribeMailings } || [] }
|
||||
};
|
||||
|
||||
my $availableMailings = $self->getAvailableMailings;
|
||||
|
||||
my $sendNotification = 0;
|
||||
foreach my $mailing ( @{ $availableMailings } ) {
|
||||
next unless $mailing->isa( 'WebGUI::AssetAspect::Subscriber' );
|
||||
|
||||
if ( $subscribeTo->{ $mailing->getId } ) {
|
||||
$mailing->subscribe( $user, $sendNotification ) unless $mailing->isSubscribed( $user );
|
||||
}
|
||||
else {
|
||||
$mailing->unsubscribe( $user, $sendNotification ) if $mailing->isSubscribed( $user );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
##-------------------------------------------------------------------
|
||||
#sub crud_definition {
|
||||
# my $class = shift;
|
||||
# my $session = shift;
|
||||
# my $definition = $class->SUPER::crud_definition( $session );
|
||||
# my $i18n = WebGUI::International->new( $session, 'Registration_Step_Homepage' );
|
||||
#
|
||||
#
|
||||
# $definition->{ dynamic }->{ urlStorageField } = {
|
||||
# fieldType => 'selectBox',
|
||||
# label => 'Store homepage url in field',
|
||||
# options => \%profileFields,
|
||||
# };
|
||||
#
|
||||
# return $definition;
|
||||
#}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getSummaryTemplateVars {
|
||||
my $self = shift;
|
||||
my $includeAdminControls = shift;
|
||||
my $session = $self->session;
|
||||
my $i18n = WebGUI::International->new( $session, 'RegistrationStep_MailingSubscribe' );
|
||||
my @fields;
|
||||
|
||||
# Fetch preferred homepage url
|
||||
my $mailings = $self->getConfigurationData->{ subscribeMailings };
|
||||
|
||||
my @assets =
|
||||
grep { defined $_ }
|
||||
map { WebGUI::Asset->newByDynamicClass( $session, $_ ) }
|
||||
@{ $mailings };
|
||||
|
||||
push @fields, {
|
||||
field_label => $i18n->get( 'Subscribe to mailings' ),
|
||||
field_value => join( ', ', map { $_->getTitle } @assets ),
|
||||
};
|
||||
|
||||
# Setup tmpl_var
|
||||
my $var = {
|
||||
field_loop => \@fields,
|
||||
category_label => $self->get('title'),
|
||||
category_edit_url => $self->changeStepDataUrl,
|
||||
};
|
||||
|
||||
return ( $var );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getViewVars {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $session->form;
|
||||
my $user = $self->registration->instance->user;
|
||||
my $i18n = WebGUI::International->new( $session, 'RegistrationStep_MailingSubscribe' );
|
||||
|
||||
my $availableMailings = $self->getAvailableMailings;
|
||||
|
||||
# Figure out what mailings to check in the form
|
||||
my @subscribeMailings;
|
||||
if ( $form->checkList( 'subscribeMailings' ) ) {
|
||||
# The user just posted but made an error
|
||||
@subscribeMailings = $form->checkList( 'subscribeMailings' );
|
||||
}
|
||||
elsif ( exists $self->getConfigurationData->{'subscribeMailings'} ) {
|
||||
# The step is being changed
|
||||
@subscribeMailings = @{ $self->getConfigurationData->{'subscribeMailings'} || [] };
|
||||
}
|
||||
else {
|
||||
# The step hasn't been done yet.
|
||||
@subscribeMailings = grep { $_->isSubscribed( $user ) } @{ $availableMailings };
|
||||
}
|
||||
|
||||
# Create lookup table
|
||||
my %isSubscribed = map { $_ => 1 } @subscribeMailings;
|
||||
|
||||
my $var = $self->SUPER::getViewVars;
|
||||
|
||||
# Add form elems in alphabetic order.
|
||||
foreach my $mailing ( sort { $a->getTitle cmp $b->getTitle } @{ $availableMailings } ) {
|
||||
my $id = $mailing->getId;
|
||||
|
||||
push @{ $var->{ field_loop } }, (
|
||||
{
|
||||
field_label => $mailing->getTitle,
|
||||
field_formElement =>
|
||||
WebGUI::Form::checkbox( $session, {
|
||||
name => 'subscribeMailings',
|
||||
value => $id,
|
||||
checked => $isSubscribed{ $id },
|
||||
label => $i18n->get( 'Subscribe to this mailing' ),
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub isComplete {
|
||||
my $self = shift;
|
||||
|
||||
return defined $self->getConfigurationData->{subscribeMailings};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub onDeleteAccount {
|
||||
my $self = shift;
|
||||
my $doit = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
$self->SUPER::onDeleteAccount( $doit );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub updateFromFormPost {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
$self->SUPER::updateFromFormPost;
|
||||
|
||||
# $self->update( {
|
||||
# } );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub processStepFormData {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my @subscribeMailings = $session->form->checkList( 'subscribeMailings' );
|
||||
|
||||
$self->setConfigurationData( subscribeMailings => \@subscribeMailings );
|
||||
return [];
|
||||
}
|
||||
|
||||
1;
|
||||
15
lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm
Normal file
15
lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package WebGUI::i18n::Dutch::RegistrationStep_MailingSubscribe;
|
||||
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'Subscribe to mailings' => {
|
||||
message => 'Abonneren op nieuwsbrieven',
|
||||
},
|
||||
'Subscribe to this mailing' => {
|
||||
message => 'Abonneer op deze nieuwsbrief',
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
15
lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm
Normal file
15
lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package WebGUI::i18n::English::RegistrationStep_MailingSubscribe;
|
||||
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'Subscribe to mailings' => {
|
||||
message => 'Subscribe to mailings',
|
||||
},
|
||||
'Subscribe to this mailing' => {
|
||||
message => 'Subscribe to this mailing',
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -33,6 +33,7 @@ addRecentColumnToNewsletterCollection( $session );
|
|||
renamespaceTemplates( $session );
|
||||
addSpecialStateTable( $session );
|
||||
addListNameColumn( $session );
|
||||
addRegistrationSteps( $session );
|
||||
|
||||
finish($session);
|
||||
|
||||
|
|
@ -290,6 +291,21 @@ EOSQL
|
|||
print "Done.\n";
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub addRegistrationSteps {
|
||||
my $session = shift;
|
||||
|
||||
print "\tAdding MailingSubscribe Registration Step to config...";
|
||||
|
||||
my %steps = map { $_ => 1 } @{ $session->config->get( 'registrationSteps' ) || [] };
|
||||
$steps{ 'WebGUI::Registration::Step::MailingSubscribe' } = 1;
|
||||
|
||||
$session->config->set( 'registrationSteps', [ keys %steps ] );
|
||||
|
||||
print "Done.\n";
|
||||
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub start {
|
||||
my $webguiRoot = shift;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue