Added Newsletter Asset (Funded by United Knowledge)
This commit is contained in:
parent
245c7b947e
commit
9248570f79
16 changed files with 1295 additions and 149 deletions
|
|
@ -24,6 +24,54 @@ use WebGUI::Asset::RSSCapable;
|
|||
use base 'WebGUI::Asset::RSSCapable';
|
||||
use base 'WebGUI::Asset::Wobject';
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _computePostCount {
|
||||
my $self = shift;
|
||||
return scalar @{$self->getLineage(['descendants'], {includeOnlyClasses => ['WebGUI::Asset::Post']})};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _computeThreadCount {
|
||||
my $self = shift;
|
||||
return scalar @{$self->getLineage(['children'], {includeOnlyClasses => ['WebGUI::Asset::Post::Thread']})};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# format the date according to rfc 822 (for RSS export)
|
||||
my @_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
sub _get_rfc822_date {
|
||||
my $self = shift;
|
||||
my ($time) = @_;
|
||||
my ($year, $mon, $mday, $hour, $min, $sec) = $self->session->datetime->localtime($time);
|
||||
my $month = $_months[$mon - 1];
|
||||
return sprintf("%02d %s %04d %02d:%02d:%02d GMT",
|
||||
$mday, $month, $year, $hour, $min, $sec);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _visitorCacheKey {
|
||||
my $self = shift;
|
||||
my $pn = $self->session->form->process('pn');
|
||||
return "view_".$self->getId."?pn=".$pn;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _visitorCacheOk {
|
||||
my $self = shift;
|
||||
return ($self->session->user->userId eq '1'
|
||||
&& !$self->session->form->process('sortBy'));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# encode a string to include in xml (for RSS export)
|
||||
sub _xml_encode {
|
||||
my $text = shift;
|
||||
$text =~ s/&/&/g;
|
||||
$text =~ s/</</g;
|
||||
$text =~ s/\]\]>/\]\]>/g;
|
||||
return $text;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub addChild {
|
||||
my $self = shift;
|
||||
|
|
@ -554,7 +602,7 @@ sub definition {
|
|||
fieldType=>"template",
|
||||
namespace=>"Collaboration/Notification",
|
||||
defaultValue=>'PBtmpl0000000000000027',
|
||||
tab=>'display',
|
||||
tab=>'mail',
|
||||
label=>$i18n->get('notification template'),
|
||||
hoverHelp=>$i18n->get('notification template description'),
|
||||
},
|
||||
|
|
@ -664,6 +712,27 @@ sub duplicate {
|
|||
return $newAsset;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditTabs {
|
||||
my $self = shift;
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Collaboration");
|
||||
|
||||
return (['mail', $i18n->get('mail'), 9]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getNewThreadUrl( )
|
||||
|
||||
Formats the url to start a new thread.
|
||||
|
||||
=cut
|
||||
|
||||
sub getNewThreadUrl {
|
||||
my $self = shift;
|
||||
$self->getUrl("func=add;class=WebGUI::Asset::Post::Thread");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getRssItems {
|
||||
my $self = shift;
|
||||
|
|
@ -726,27 +795,6 @@ SQL
|
|||
return @posts;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditTabs {
|
||||
my $self = shift;
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Collaboration");
|
||||
|
||||
return (['mail', $i18n->get('mail'), 9]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getNewThreadUrl( )
|
||||
|
||||
Formats the url to start a new thread.
|
||||
|
||||
=cut
|
||||
|
||||
sub getNewThreadUrl {
|
||||
my $self = shift;
|
||||
$self->getUrl("func=add;class=WebGUI::Asset::Post::Thread");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getSearchUrl ( )
|
||||
|
|
@ -806,14 +854,78 @@ sub getUnsubscribeUrl {
|
|||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _computeThreadCount {
|
||||
sub getViewTemplateVars {
|
||||
my $self = shift;
|
||||
return scalar @{$self->getLineage(['children'], {includeOnlyClasses => ['WebGUI::Asset::Post::Thread']})};
|
||||
}
|
||||
|
||||
sub _computePostCount {
|
||||
my $self = shift;
|
||||
return scalar @{$self->getLineage(['descendants'], {includeOnlyClasses => ['WebGUI::Asset::Post']})};
|
||||
my $scratchSortBy = $self->getId."_sortBy";
|
||||
my $scratchSortOrder = $self->getId."_sortDir";
|
||||
my $sortBy = $self->session->form->process("sortBy") || $self->session->scratch->get($scratchSortBy) || $self->get("sortBy");
|
||||
my $sortOrder = $self->session->scratch->get($scratchSortOrder) || $self->get("sortOrder");
|
||||
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
|
||||
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
|
||||
} elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
|
||||
if ($sortOrder eq "asc") {
|
||||
$sortOrder = "desc";
|
||||
} else {
|
||||
$sortOrder = "asc";
|
||||
}
|
||||
$self->session->scratch->set($scratchSortOrder, $sortOrder);
|
||||
}
|
||||
$sortBy ||= "dateUpdated";
|
||||
$sortOrder ||= "desc";
|
||||
my %var;
|
||||
$var{'user.canPost'} = $self->canPost;
|
||||
$var{"add.url"} = $self->getNewThreadUrl;
|
||||
$var{"rss.url"} = $self->getRssUrl;
|
||||
$var{'user.isModerator'} = $self->canModerate;
|
||||
$var{'user.isVisitor'} = ($self->session->user->userId eq '1');
|
||||
$var{'user.isSubscribed'} = $self->isSubscribed;
|
||||
$var{'sortby.title.url'} = $self->getSortByUrl("title");
|
||||
$var{'sortby.username.url'} = $self->getSortByUrl("username");
|
||||
$var{'karmaIsEnabled'} = $self->session->setting->get("useKarma");
|
||||
$var{'sortby.karmaRank.url'} = $self->getSortByUrl("karmaRank");
|
||||
$var{'sortby.date.url'} = $self->getSortByUrl("dateSubmitted");
|
||||
$var{'sortby.lastreply.url'} = $self->getSortByUrl("lastPostDate");
|
||||
$var{'sortby.views.url'} = $self->getSortByUrl("views");
|
||||
$var{'sortby.replies.url'} = $self->getSortByUrl("replies");
|
||||
$var{'sortby.rating.url'} = $self->getSortByUrl("rating");
|
||||
$var{"search.url"} = $self->getSearchUrl;
|
||||
$var{"subscribe.url"} = $self->getSubscribeUrl;
|
||||
$var{"unsubscribe.url"} = $self->getUnsubscribeUrl;
|
||||
$var{"collaborationAssetId"} = $self->getId;
|
||||
my $sql = "
|
||||
select
|
||||
asset.assetId,
|
||||
asset.className,
|
||||
assetData.revisionDate as revisionDate
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.assetId
|
||||
left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate
|
||||
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
|
||||
where
|
||||
asset.parentId=".$self->session->db->quote($self->getId)."
|
||||
and asset.state='published'
|
||||
and asset.className='WebGUI::Asset::Post::Thread'
|
||||
and assetData.revisionDate=(
|
||||
select
|
||||
max(revisionDate)
|
||||
from
|
||||
assetData
|
||||
where
|
||||
assetData.assetId=asset.assetId
|
||||
and (status='approved' or status='archived')
|
||||
)
|
||||
and status='approved'
|
||||
group by
|
||||
assetData.assetId
|
||||
order by
|
||||
Thread.isSticky desc,
|
||||
".$sortBy."
|
||||
".$sortOrder;
|
||||
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
|
||||
$p->setDataByQuery($sql);
|
||||
$self->appendPostListTemplateVars(\%var, $p);
|
||||
$self->appendTemplateLabels(\%var);
|
||||
return \%var;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -1053,18 +1165,6 @@ sub unsubscribe {
|
|||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _visitorCacheOk {
|
||||
my $self = shift;
|
||||
return ($self->session->user->userId eq '1'
|
||||
&& !$self->session->form->process('sortBy'));
|
||||
}
|
||||
|
||||
sub _visitorCacheKey {
|
||||
my $self = shift;
|
||||
my $pn = $self->session->form->process('pn');
|
||||
return "view_".$self->getId."?pn=".$pn;
|
||||
}
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
if ($self->_visitorCacheOk) {
|
||||
|
|
@ -1072,87 +1172,16 @@ sub view {
|
|||
$self->session->errorHandler->debug("HIT") if $out;
|
||||
return $out if $out;
|
||||
}
|
||||
my $scratchSortBy = $self->getId."_sortBy";
|
||||
my $scratchSortOrder = $self->getId."_sortDir";
|
||||
my $sortBy = $self->session->form->process("sortBy") || $self->session->scratch->get($scratchSortBy) || $self->get("sortBy");
|
||||
my $sortOrder = $self->session->scratch->get($scratchSortOrder) || $self->get("sortOrder");
|
||||
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
|
||||
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
|
||||
} elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
|
||||
if ($sortOrder eq "asc") {
|
||||
$sortOrder = "desc";
|
||||
} else {
|
||||
$sortOrder = "asc";
|
||||
}
|
||||
$self->session->scratch->set($scratchSortOrder, $sortOrder);
|
||||
}
|
||||
$sortBy ||= "dateUpdated";
|
||||
$sortOrder ||= "desc";
|
||||
my %var;
|
||||
$var{'user.canPost'} = $self->canPost;
|
||||
$var{"add.url"} = $self->getNewThreadUrl;
|
||||
$var{"rss.url"} = $self->getRssUrl;
|
||||
$var{'user.isModerator'} = $self->canModerate;
|
||||
$var{'user.isVisitor'} = ($self->session->user->userId eq '1');
|
||||
$var{'user.isSubscribed'} = $self->isSubscribed;
|
||||
$var{'sortby.title.url'} = $self->getSortByUrl("title");
|
||||
$var{'sortby.username.url'} = $self->getSortByUrl("username");
|
||||
$var{'karmaIsEnabled'} = $self->session->setting->get("useKarma");
|
||||
$var{'sortby.karmaRank.url'} = $self->getSortByUrl("karmaRank");
|
||||
$var{'sortby.date.url'} = $self->getSortByUrl("dateSubmitted");
|
||||
$var{'sortby.lastreply.url'} = $self->getSortByUrl("lastPostDate");
|
||||
$var{'sortby.views.url'} = $self->getSortByUrl("views");
|
||||
$var{'sortby.replies.url'} = $self->getSortByUrl("replies");
|
||||
$var{'sortby.rating.url'} = $self->getSortByUrl("rating");
|
||||
$var{"search.url"} = $self->getSearchUrl;
|
||||
$var{"subscribe.url"} = $self->getSubscribeUrl;
|
||||
$var{"unsubscribe.url"} = $self->getUnsubscribeUrl;
|
||||
$var{"collaborationAssetId"} = $self->getId;
|
||||
my $sql = "
|
||||
select
|
||||
asset.assetId,
|
||||
asset.className,
|
||||
assetData.revisionDate as revisionDate
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.assetId
|
||||
left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate
|
||||
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
|
||||
where
|
||||
asset.parentId=".$self->session->db->quote($self->getId)."
|
||||
and asset.state='published'
|
||||
and asset.className='WebGUI::Asset::Post::Thread'
|
||||
and assetData.revisionDate=(
|
||||
select
|
||||
max(revisionDate)
|
||||
from
|
||||
assetData
|
||||
where
|
||||
assetData.assetId=asset.assetId
|
||||
and (status='approved' or status='archived')
|
||||
)
|
||||
and status='approved'
|
||||
group by
|
||||
assetData.assetId
|
||||
order by
|
||||
Thread.isSticky desc,
|
||||
".$sortBy."
|
||||
".$sortOrder;
|
||||
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
|
||||
$p->setDataByQuery($sql);
|
||||
$self->appendPostListTemplateVars(\%var, $p);
|
||||
$self->appendTemplateLabels(\%var);
|
||||
|
||||
# If the asset is not called through the normal prepareView/view cycle, first call prepareView.
|
||||
# This happens for instance in the viewDetail method in the Matrix. In that case the Collaboration
|
||||
# is called through the api.
|
||||
$self->prepareView unless ($self->{_viewTemplate});
|
||||
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
||||
my $out = $self->processTemplate($self->getViewTemplateVars,undef,$self->{_viewTemplate});
|
||||
if ($self->_visitorCacheOk) {
|
||||
WebGUI::Cache->new($self->session,$self->_visitorCacheKey)
|
||||
->set($out,$self->get("visitorCacheTimeout"));
|
||||
$self->session->errorHandler->debug("MISS");
|
||||
WebGUI::Cache->new($self->session,$self->_visitorCacheKey)->set($out,$self->get("visitorCacheTimeout"));
|
||||
}
|
||||
return $out;
|
||||
return $out;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -1221,28 +1250,6 @@ sub www_unsubscribe {
|
|||
return $self->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# format the date according to rfc 822 (for RSS export)
|
||||
my @_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
sub _get_rfc822_date {
|
||||
my $self = shift;
|
||||
my ($time) = @_;
|
||||
my ($year, $mon, $mday, $hour, $min, $sec) = $self->session->datetime->localtime($time);
|
||||
my $month = $_months[$mon - 1];
|
||||
return sprintf("%02d %s %04d %02d:%02d:%02d GMT",
|
||||
$mday, $month, $year, $hour, $min, $sec);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# encode a string to include in xml (for RSS export)
|
||||
sub _xml_encode {
|
||||
my $text = shift;
|
||||
$text =~ s/&/&/g;
|
||||
$text =~ s/</</g;
|
||||
$text =~ s/\]\]>/\]\]>/g;
|
||||
return $text;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
|
|
|
|||
242
lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm
Normal file
242
lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
package WebGUI::Asset::Wobject::Collaboration::Newsletter;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Utility;
|
||||
use base 'WebGUI::Asset::Wobject::Collaboration';
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( )
|
||||
|
||||
defines wobject properties for Newsletter instances. You absolutely need
|
||||
this method in your new Wobjects. If you choose to "autoGenerateForms", the
|
||||
getEditForm method is unnecessary/redundant/useless.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_Newsletter');
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
newsletterHeader => {
|
||||
defaultValue=>undef,
|
||||
fieldType=>"HTMLArea",
|
||||
tab=>"mail",
|
||||
label=>$i18n->get("newsletter header"),
|
||||
hoverHelp=>$i18n->get("newsletter header help"),
|
||||
},
|
||||
newsletterFooter => {
|
||||
defaultValue=>undef,
|
||||
fieldType=>"HTMLArea",
|
||||
tab=>"mail",
|
||||
label=>$i18n->get("newsletter footer"),
|
||||
hoverHelp=>$i18n->get("newsletter footer help"),
|
||||
},
|
||||
newsletterTemplateId => {
|
||||
defaultValue=>'newsletter000000000001',
|
||||
fieldType=>"template",
|
||||
namespace=>"newsletter",
|
||||
tab=>"mail",
|
||||
label=>$i18n->get("newsletter template"),
|
||||
hoverHelp=>$i18n->get("newsletter template help"),
|
||||
},
|
||||
mySubscriptionsTemplateId => {
|
||||
defaultValue=>'newslettersubscrip0001',
|
||||
fieldType=>"template",
|
||||
namespace=>"newsletter/mysubscriptions",
|
||||
tab=>"display",
|
||||
label=>$i18n->get("my subscriptions template"),
|
||||
hoverHelp=>$i18n->get("my subscriptions template help"),
|
||||
},
|
||||
);
|
||||
if ($session->setting->get("metaDataEnabled")) {
|
||||
$properties{newsletterCategories} = {
|
||||
defaultValue=>undef,
|
||||
fieldType=>"checkList",
|
||||
tab=>"properties",
|
||||
options=>$session->db->buildHashRef("select fieldId, fieldName from metaData_properties where
|
||||
fieldType in ('selectBox', 'checkList', 'radioList') order by fieldName"),
|
||||
label=>$i18n->get("newsletter categories"),
|
||||
hoverHelp=>$i18n->get("newsletter categories help"),
|
||||
vertical=>1,
|
||||
};
|
||||
}
|
||||
else {
|
||||
$properties{newsletterCategories} = {
|
||||
fieldType=>"readOnly",
|
||||
value=>'<b style="color: #800000;">'.$i18n->get("content profiling needed").'</b>',
|
||||
};
|
||||
}
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
icon=>'newsletter.gif',
|
||||
autoGenerateForms=>1,
|
||||
tableName=>'Newsletter',
|
||||
className=>'WebGUI::Asset::Wobject::Collaboration::Newsletter',
|
||||
properties=>\%properties
|
||||
});
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 duplicate ( )
|
||||
|
||||
duplicates a Newsletter. This method is unnecessary, but if you have
|
||||
auxiliary, ancillary, or "collateral" data or files related to your
|
||||
wobject instances, you will need to duplicate them here.
|
||||
|
||||
=cut
|
||||
|
||||
sub duplicate {
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate(@_);
|
||||
return $newAsset;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getUserSubscriptions {
|
||||
my $self = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
my ($subscriptionString) = $self->session->db->quickArray("select subscriptions from Newsletter_subscriptions where
|
||||
assetId=? and userId=?", [$self->getId, $userId]);
|
||||
return split("\n", $subscriptionString);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub getViewTemplateVars {
|
||||
my $self = shift;
|
||||
my $var = $self->SUPER::getViewTemplateVars;
|
||||
$var->{mySubscriptionsUrl} = $self->getUrl("func=mySubscriptions");
|
||||
return $var;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
$self->session->db->write("delete from Newsletter_subscriptions where assetId=?", [$self->getId]);
|
||||
$self->SUPER::purge(@_);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub setUserSubscriptions {
|
||||
my $self = shift;
|
||||
my $subscriptions = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
$self->session->db->write("replace into Newsletter_subscriptions (assetId, userId, subscriptions, lastSendTime)
|
||||
values (?,?,?,?)", [$self->getId, $userId, $subscriptions, time()]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 view ( )
|
||||
|
||||
method called by the www_view method. Returns a processed template
|
||||
to be displayed within the page style.
|
||||
|
||||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
#This automatically creates template variables for all of your wobject's properties.
|
||||
my $var = $self->getViewTemplateVars;
|
||||
|
||||
#This is an example of debugging code to help you diagnose problems.
|
||||
#WebGUI::ErrorHandler::warn($self->get("templateId"));
|
||||
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_edit ( )
|
||||
|
||||
Web facing method which is the default edit page. This method is entirely
|
||||
optional. Take it out unless you specifically want to set a submenu in your
|
||||
adminConsole views.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
return $self->session->privilege->insufficient() unless $self->canEdit;
|
||||
return $self->session->privilege->locked() unless $self->canEditIfLocked;
|
||||
my $i18n = WebGUI::International->new($self->session, "Asset_Newsletter");
|
||||
return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get("edit title"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_mySubscriptions {
|
||||
my $self = shift;
|
||||
return $self->session->privilege->insufficient unless ($self->canView && $self->session->user->userId ne "1");
|
||||
my %var = ();
|
||||
my $meta = $self->getMetaDataFields;
|
||||
my @categories = ();
|
||||
my @userPrefs = $self->getUserSubscriptions;
|
||||
foreach my $id (keys %{$meta}) {
|
||||
my @options = ();
|
||||
if (isIn($id, split("\n", $self->get("newsletterCategories")))) {
|
||||
foreach my $option (split("\n", $meta->{$id}{possibleValues})) {
|
||||
$option =~ s/\s+$//; # remove trailing spaces
|
||||
next if $option eq ""; # skip blank values
|
||||
my $preferenceName = $id."~".$option;
|
||||
push(@options, {
|
||||
optionName => $option,
|
||||
optionForm => WebGUI::Form::checkbox($self->session, {
|
||||
name => "subscriptions",
|
||||
value => $preferenceName,
|
||||
checked => isIn($preferenceName, @userPrefs),
|
||||
})
|
||||
});
|
||||
}
|
||||
push (@categories, {
|
||||
categoryName => $meta->{$id}{fieldName},
|
||||
optionsLoop => \@options
|
||||
});
|
||||
}
|
||||
}
|
||||
$var{categoriesLoop} = \@categories;
|
||||
if (scalar(@categories)) {
|
||||
$var{formHeader} = WebGUI::Form::formHeader($self->session, {action=>$self->getUrl, method=>"post"})
|
||||
.WebGUI::Form::hidden($self->session, {name=>"func", value=>"mySubscriptionsSave"});
|
||||
$var{formFooter} = WebGUI::Form::formFooter($self->session);
|
||||
$var{formSubmit} = WebGUI::Form::submit($self->session);
|
||||
}
|
||||
return $self->processStyle($self->processTemplate(\%var, $self->get("mySubscriptionsTemplateId")));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_mySubscriptionsSave {
|
||||
my $self = shift;
|
||||
return $self->session->privilege->insufficient unless ($self->canView && $self->session->user->userId ne "1");
|
||||
my $subscriptions = $self->session->form->process("subscriptions", "checkList");
|
||||
$self->setUserSubscriptions($subscriptions);
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue