[vhffs-dev] [1371] improved newsletter module by adding constants, delete subscription when the user is destroyed

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1371
Author:   gradator
Date:     2009-03-11 21:27:06 +0100 (Wed, 11 Mar 2009)

Log Message:
-----------
improved newsletter module by adding constants, delete subscription when the user is destroyed

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-panel/subscribe.pl
    trunk/vhffs-panel/user/prefs.pl


Modified: trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm	2009-03-11 19:48:30 UTC (rev 1370)
+++ trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm	2009-03-11 20:27:06 UTC (rev 1371)
@@ -42,7 +42,16 @@
 
 use Vhffs::Services::MailingList;
 
+use constant
+{
+	ACTIVE_OPTIN => 1,
+    	PASSIVE_OPTIN => 2,
+	ACTIVE_OPTOUT => 3,
+	PASSIVE_OPTOUT => 4,
+	PERMANENT => 5,
+};
 
+
 # Create a new instance of the current class
 sub init
 {
@@ -65,6 +74,13 @@
 	$this->{main} = $vhffs;
 	$this->{config} = $config;
 	$this->{user} = $user;
+	$this->{collectmode} = ACTIVE_OPTIN;
+	if( defined $config->{'collectmode'} ) {
+		$this->{collectmode} = PASSIVE_OPTIN if $config->{'collectmode'} eq 'passive_optin';
+		$this->{collectmode} = ACTIVE_OPTOUT if $config->{'collectmode'} eq 'active_optout';
+		$this->{collectmode} = PASSIVE_OPTOUT if $config->{'collectmode'} eq 'passive_optout';
+		$this->{collectmode} = PERMANENT if $config->{'collectmode'} eq 'permanent';
+	}
 	$this->{mailinglist_service} = $mailinglist_service;
 	bless( $this , $class );
 	return $this;
@@ -88,4 +104,10 @@
 	return $self->{'mailinglist_service'}->del_sub( $self->{'user'}->get_mail );
 }
 
+sub get_collectmode
+{
+	my $self = shift;
+	return $self->{collectmode};
+}
+
 1;

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2009-03-11 19:48:30 UTC (rev 1370)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2009-03-11 20:27:06 UTC (rev 1371)
@@ -303,6 +303,11 @@
 		$mu->delforward;
 	}
 
+	# remove subscription from newsletter
+	use Vhffs::Services::Newsletter;
+	my $newsletter = init Vhffs::Services::Newsletter( $self->{'main'} , $self );
+	$newsletter->del if defined $newsletter;
+
     # User references corresponding object with an ON DELETE cascade foreign key
     # so we don't even need to delete user
     # rows that reference this user will be deleted by foreign keys constraints

Modified: trunk/vhffs-panel/subscribe.pl
===================================================================
--- trunk/vhffs-panel/subscribe.pl	2009-03-11 19:48:30 UTC (rev 1370)
+++ trunk/vhffs-panel/subscribe.pl	2009-03-11 20:27:06 UTC (rev 1371)
@@ -200,13 +200,11 @@
 			# Newsletter
 			my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $user );
 			if( $newsletter ) {
-				my $mode = $newsletter->{'config'}->{'collectmode'} || 'undef';
-				if(  ( $mode eq 'undef' && $newslettercheckbox )
-				  || ( $mode eq 'active_optin' && $newslettercheckbox )
-				  || ( $mode eq 'passive_optin' && $newslettercheckbox )
-				  || ( $mode eq 'active_optout' && !$newslettercheckbox )
-				  || ( $mode eq 'passive_optout' )
-				  || ( $mode eq 'permanent' )
+				if(  ( $newsletter->get_collectmode == Vhffs::Services::Newsletter::ACTIVE_OPTIN && $newslettercheckbox )
+				  || ( $newsletter->get_collectmode == Vhffs::Services::Newsletter::PASSIVE_OPTIN && $newslettercheckbox )
+				  || ( $newsletter->get_collectmode == Vhffs::Services::Newsletter::ACTIVE_OPTOUT && !$newslettercheckbox )
+				  || ( $newsletter->get_collectmode == Vhffs::Services::Newsletter::PASSIVE_OPTOUT )
+				  || ( $newsletter->get_collectmode == Vhffs::Services::Newsletter::PERMANENT )
 				  ) {
 					$newsletter->add;
 				}

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2009-03-11 19:48:30 UTC (rev 1370)
+++ trunk/vhffs-panel/user/prefs.pl	2009-03-11 20:27:06 UTC (rev 1371)
@@ -295,12 +295,10 @@
 					# -- Newsletter
 					my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $userp );
 					if( defined $newsletter )  {
-						if( $newslettercheckbox && !$newsletter->exists ) {
+						if( $newslettercheckbox  &&  !$newsletter->exists ) {
 							$newsletter->add;
-						} elsif( !$newslettercheckbox && $newsletter->exists ) {
-							if( !defined $newsletter->{'config'}->{'collectmode'} || $newsletter->{'config'}->{'collectmode'} ne 'permanent' ) {
-								$newsletter->del;
-							}
+						} elsif( !$newslettercheckbox  &&  $newsletter->exists  &&  $newsletter->get_collectmode != Vhffs::Services::Newsletter::PERMANENT ) {
+							$newsletter->del;
 						}
 					}
 
@@ -465,7 +463,7 @@
 
 	my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $userp );
 	if( defined $newsletter )  {
-		if( !defined $newsletter->{'config'}->{'collectmode'} || $newsletter->{'config'}->{'collectmode'} ne 'permanent' ) {
+		if( $newsletter->get_collectmode != Vhffs::Services::Newsletter::PERMANENT ) {
 			$template->param( NEWSLETTER_TEXT => gettext('Receive mails from the newsletter') );
 			$template->param( NEWSLETTER_CHECKED => $newsletter->exists );
 		}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/