Make NewslettCollaboration templatable, and add concept of recent issues.
This commit is contained in:
parent
e82b8fe088
commit
218ebbbad6
4 changed files with 147 additions and 48 deletions
|
|
@ -21,6 +21,19 @@ sub definition {
|
||||||
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
||||||
|
|
||||||
tie my %properties, 'Tie::IxHash', (
|
tie my %properties, 'Tie::IxHash', (
|
||||||
|
viewTemplateId => {
|
||||||
|
fieldType => 'template',
|
||||||
|
label => 'Template',
|
||||||
|
tab => 'display',
|
||||||
|
defaultValue => 'aYVYFpofaYvmRYoHwl3x4w',
|
||||||
|
namespace => 'NewsletterCollection',
|
||||||
|
},
|
||||||
|
recentIssueCount => {
|
||||||
|
fieldType => 'integer',
|
||||||
|
label => 'Number of recent issues',
|
||||||
|
tab => 'display',
|
||||||
|
defaultValue => 1,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
push @{ $definition }, {
|
push @{ $definition }, {
|
||||||
|
|
@ -29,7 +42,7 @@ sub definition {
|
||||||
autoGenerateForms => 1,
|
autoGenerateForms => 1,
|
||||||
tableName => 'NewsletterCollection',
|
tableName => 'NewsletterCollection',
|
||||||
className => 'WebGUI::Asset::Wobject::NewsletterCollection',
|
className => 'WebGUI::Asset::Wobject::NewsletterCollection',
|
||||||
properties => \%properties
|
properties => \%properties,
|
||||||
};
|
};
|
||||||
|
|
||||||
return $class->SUPER::definition( $session, $definition );
|
return $class->SUPER::definition( $session, $definition );
|
||||||
|
|
@ -70,48 +83,82 @@ sub generateEmailContent {
|
||||||
return $issue->view;
|
return $issue->view;
|
||||||
}
|
}
|
||||||
|
|
||||||
##----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
#sub prepareView {
|
sub getAssetContent {
|
||||||
# my $self = shift;
|
my $self = shift;
|
||||||
# $self->SUPER::prepareView();
|
my $asset = shift;
|
||||||
# my $template = WebGUI::Asset::Template->new( $self->session, $self->get("templateIdView") );
|
my $var = $self->session->var;
|
||||||
# $template->prepare($self->getMetaDataAsTemplateVariables);
|
|
||||||
# $self->{_viewTemplate} = $template;
|
my $adminOn = $var->isAdminOn;
|
||||||
#}
|
$var->switchAdminOff;
|
||||||
|
|
||||||
|
$asset->prepareView;
|
||||||
|
my $content = $asset->view;
|
||||||
|
|
||||||
|
$var->switchAdminOn if $adminOn;
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub prepareView {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
$self->SUPER::prepareView;
|
||||||
|
|
||||||
|
my $template = WebGUI::Asset::Template->new( $session, $self->get('viewTemplateId') );
|
||||||
|
$template->prepare( $self->getMetaDataAsTemplateVariables );
|
||||||
|
|
||||||
|
$self->{ _viewTemplate } = $template;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getViewVars {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
my $var = $self->get;
|
||||||
|
|
||||||
|
my $issueCount = 0;
|
||||||
|
my ( @recentIssues, @olderIssues );
|
||||||
|
my $issues = $self->getIssues;
|
||||||
|
foreach my $issue ( @{ $issues } ) {
|
||||||
|
my $issueVar = $issue->get;
|
||||||
|
$issueVar->{ url } = $issue->getUrl;
|
||||||
|
|
||||||
|
$issueCount++;
|
||||||
|
|
||||||
|
if ( $issueCount <= $self->get('recentIssueCount') ) {
|
||||||
|
$issueVar->{ content } = $self->getAssetContent( $issue );
|
||||||
|
|
||||||
|
push @recentIssues, $issueVar;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
push @olderIssues, $issueVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$var->{ recent_issue_loop } = \@recentIssues;
|
||||||
|
$var->{ recent_issue_count } = scalar @recentIssues;
|
||||||
|
$var->{ older_issue_loop } = \@olderIssues;
|
||||||
|
$var->{ older_issue_count } = scalar @olderIssues;
|
||||||
|
$var->{ issue_count } = $issueCount;
|
||||||
|
|
||||||
|
$self->appendSubscriptionFormVars( $var );
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
|
||||||
|
|
||||||
my $output = $self->getToolbar if $session->var->isAdminOn;
|
my $var = $self->getViewVars;
|
||||||
|
|
||||||
my $issues = $self->getIssues;
|
return $self->processTemplate( $var, undef, $self->{_viewTemplate} );
|
||||||
return $output . "No issues yet" unless scalar @{ $issues };
|
|
||||||
|
|
||||||
$output .= $self->getSubscriptionForm;
|
|
||||||
# $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 .=
|
|
||||||
join '',
|
|
||||||
map {
|
|
||||||
'<li>'
|
|
||||||
.'<a href="' . $_->getUrl . '">' . $_->get('title') . '</a>'
|
|
||||||
.' :: '
|
|
||||||
.' <a href="' .$self->getUrl('func=previewEmail;issueId='.$_->getId.';userId=3').'">preview</a>'
|
|
||||||
.'</li>'
|
|
||||||
}
|
|
||||||
@{ $issues };
|
|
||||||
$output .= '</ul></p>';
|
|
||||||
|
|
||||||
$issues->[0]->prepareView;
|
|
||||||
$output .= $issues->[0]->view;
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -151,11 +151,13 @@ sub isSubscribed {
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub getSubscriptionForm {
|
sub appendSubscriptionFormVars {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $var = shift || {};
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
||||||
|
|
||||||
|
# Setup form controls
|
||||||
my $formHeader =
|
my $formHeader =
|
||||||
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
||||||
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
||||||
|
|
@ -167,20 +169,28 @@ sub getSubscriptionForm {
|
||||||
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
||||||
my $formFooter = WebGUI::Form::formFooter( $session );
|
my $formFooter = WebGUI::Form::formFooter( $session );
|
||||||
|
|
||||||
my $output = '';
|
# Compose default subscription form for current user
|
||||||
|
my $form = '';
|
||||||
if ( $session->user->isRegistered ) {
|
if ( $session->user->isRegistered ) {
|
||||||
$output .= $subscribeButton if $self->canSubscribe;
|
$form .= $subscribeButton if $self->canSubscribe;
|
||||||
$output .= $unsubscribeButton if $self->canUnsubscribe;
|
$form .= $unsubscribeButton if $self->canUnsubscribe;
|
||||||
|
|
||||||
return unless $output;
|
|
||||||
return $formHeader . $output . $formFooter;
|
|
||||||
}
|
}
|
||||||
#### TODO: anonymousAllowed
|
elsif ( $self->get('allowAnonymousSubscription') ) {
|
||||||
else {
|
$form = $emailBox . $subscribeButton . $unsubscribeButton;
|
||||||
return $formHeader . $emailBox . $subscribeButton . $unsubscribeButton . $formFooter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
# Setup tmpl_vars
|
||||||
|
$var->{ subscriptionForm_form } = "$formHeader $form $formFooter" if $form;
|
||||||
|
$var->{ subscriptionForm_header } = $formHeader;
|
||||||
|
$var->{ subscriptionForm_footer } = $formFooter;
|
||||||
|
$var->{ subscriptionForm_subscribeButton } = $subscribeButton;
|
||||||
|
$var->{ subscriptionForm_unsubscribeButton } = $unsubscribeButton;
|
||||||
|
$var->{ subscrittionForm_emailBox } = $emailBox;
|
||||||
|
$var->{ user_canSubscribe } = $self->canSubscribe;
|
||||||
|
$var->{ user_canUnsubscribe } = $self->canUnsubscribe;
|
||||||
|
$var->{ user_isRegistered } = $session->user->isRegistered;
|
||||||
|
|
||||||
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ installMailingTables( $session );
|
||||||
installNewsletterInAdminConsole( $session );
|
installNewsletterInAdminConsole( $session );
|
||||||
installNewsletterSettings( $session );
|
installNewsletterSettings( $session );
|
||||||
addPluginsToConfigFile( $session );
|
addPluginsToConfigFile( $session );
|
||||||
|
addTemplateColumnToNewsletterCollection( $session );
|
||||||
|
addRecentColumnToNewsletterCollection( $session );
|
||||||
|
|
||||||
finish($session);
|
finish($session);
|
||||||
|
|
||||||
|
|
@ -106,6 +108,46 @@ EOSQL
|
||||||
print "Done.\n";
|
print "Done.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub addTemplateColumnToNewsletterCollection {
|
||||||
|
my $session = shift;
|
||||||
|
my $db = $session->db;
|
||||||
|
print "\tAdding view template column to NewletterCollection...";
|
||||||
|
|
||||||
|
my $hasColumn = $db->quickScalar( 'show columns from NewsletterCollection where Field=?', [ 'viewTemplateId' ] );
|
||||||
|
|
||||||
|
unless ( $hasColumn ) {
|
||||||
|
$db->write( 'alter table NewsletterCollection add column viewTemplateId char(22) binary not null default ?', [
|
||||||
|
'aYVYFpofaYvmRYoHwl3x4w'
|
||||||
|
] );
|
||||||
|
$db->write( 'update NewsletterCollection set viewTemplateId=?', [
|
||||||
|
'aYVYFpofaYvmRYoHwl3x4w',
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Done.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub addRecentColumnToNewsletterCollection {
|
||||||
|
my $session = shift;
|
||||||
|
my $db = $session->db;
|
||||||
|
print "\tAdding recent issues column to NewletterCollection...";
|
||||||
|
|
||||||
|
my $hasColumn = $db->quickScalar( 'show columns from NewsletterCollection where Field=?', [ 'recentIssueCount' ] );
|
||||||
|
|
||||||
|
unless ( $hasColumn ) {
|
||||||
|
$db->write( 'alter table NewsletterCollection add column recentIssueCount int(3) not null default ?', [
|
||||||
|
1,
|
||||||
|
] );
|
||||||
|
$db->write( 'update NewsletterCollection set recentIssueCount=?', [
|
||||||
|
1
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Done.\n";
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub installMailingTables {
|
sub installMailingTables {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue