classes/ezcomsubscriptionmanager.php
public function addSubscription( $email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true )
    {
        //1. insert into subscriber
        $ezcommentsINI = eZINI::instance( 'ezcomments.ini' );
        $subscriber = ezcomSubscriber::fetchByEmail( $email );
        //if there is no data in subscriber for same email, save it
        if ( is_null( $subscriber ) )
        {
            $subscriber = ezcomSubscriber::create();
            $subscriber->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscriber->setAttribute( 'email', $email );
            if ( $user->isAnonymous() )
            {
                $util = ezcomUtility::instance();
                $hashString = $util->generateSusbcriberHashString( $subscriber );
                $subscriber->setAttribute( 'hash_string', $hashString );
            }
            $subscriber->store();
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__ );
            $subscriber = ezcomSubscriber::fetchByEmail( $email );
        }
        else
        {
            if ( $subscriber->attribute( 'enabled' ) == false )
            {
                throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED );
            }
        }
        //3 insert into subscription table
        // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
        $hasSubscription = ezcomSubscription::exists( $contentID,
                                                      $languageID,
                                                      $subscriptionType,
                                                      $email );
        if ( $hasSubscription === false )
        {
            $subscription = ezcomSubscription::create();
            $subscription->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscription->setAttribute( 'subscriber_id', $subscriber->attribute( 'id' ) );
            $subscription->setAttribute( 'subscription_type', $subscriptionType );
            $subscription->setAttribute( 'content_id', $contentID );
            $subscription->setAttribute( 'language_id', $languageID );
            $subscription->setAttribute( 'subscription_time', $currentTime );
            $defaultActivated = $ezcommentsINI->variable( 'CommentSettings', 'SubscriptionActivated' );

            if ( $user->isAnonymous() && $defaultActivated !== 'true' && $activate === true )
            {
                $subscription->setAttribute( 'enabled', 0 );
                $utility = ezcomUtility::instance();
                $subscription->setAttribute( 'hash_string', $utility->generateSubscriptionHashString( $subscription ) );
                $subscription->store();

                $result = ezcomSubscriptionManager::sendActivationEmail( eZContentObject::fetch( $contentID ),
                                                                         $subscriber,
                                                                         $subscription );
                if ( !$result )
                {
                    eZDebug::writeError( "Error sending mail to '$email'", __METHOD__ );
                }
            }
            else
            {
                $subscription->setAttribute( 'enabled', 1 );
                $subscription->store();
            }
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__ );
        }
    }
public function addSubscription( $email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true )
    {
        //1. insert into subscriber
        $ezcommentsINI = eZINI::instance( 'ezcomments.ini' );
        $subscriber = ezcomSubscriber::fetchByEmail( $email );
        //if there is no data in subscriber for same email, save it
        if ( is_null( $subscriber ) )
        {
            $subscriber = ezcomSubscriber::create();
            $subscriber->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscriber->setAttribute( 'email', $email );
            if ( $user->isAnonymous() )
            {
                $util = ezcomUtility::instance();
                $hashString = $util->generateSusbcriberHashString( $subscriber );
                $subscriber->setAttribute( 'hash_string', $hashString );
            }
            $subscriber->store();
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__ );
            $subscriber = ezcomSubscriber::fetchByEmail( $email );
        }
        else
        {
            if ( $subscriber->attribute( 'enabled' ) == false )
            {
                throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED );
            }
        }
        //3 insert into subscription table
        // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
        $hasSubscription = ezcomSubscription::exists( $contentID,
                                                      $languageID,
                                                      $subscriptionType,
                                                      $email );
        if ( $hasSubscription === false )
        {
            $subscription = ezcomSubscription::create();
            $subscription->setAttribute( 'user_id', $user->attribute( 'contentobject_id' ) );
            $subscription->setAttribute( 'subscriber_id', $subscriber->attribute( 'id' ) );
            $subscription->setAttribute( 'subscription_type', $subscriptionType );
            $subscription->setAttribute( 'content_id', $contentID );
            $subscription->setAttribute( 'language_id', $languageID );
            $subscription->setAttribute( 'subscription_time', $currentTime );
            $defaultActivated = $ezcommentsINI->variable( 'CommentSettings', 'SubscriptionActivated' );

            if ( $user->isAnonymous() && $defaultActivated !== 'true' && $activate === true )
            {
                $subscription->setAttribute( 'enabled', 0 );
                $utility = ezcomUtility::instance();
                $subscription->setAttribute( 'hash_string', $utility->generateSubscriptionHashString( $subscription ) );
                $subscription->store();

                $result = ezcomSubscriptionManager::sendActivationEmail( eZContentObject::fetch( $contentID ),
                                                                         $subscriber,
                                                                         $subscription );
                if ( !$result )
                {
                    eZDebug::writeError( "Error sending mail to '$email'", __METHOD__ );
                }
            }
            else
            {
                $subscription->setAttribute( 'enabled', 1 );
                $subscription->store();
            }
            eZDebugSetting::writeNotice( 'extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__ );
        }
    }
public function addSubscription ( $ email , $ user , $ contentID , $ languageID , $ subscriptionType , $ currentTime , $ activate = true ) { //1. insert into subscriber $ ezcommentsINI = eZINI :: instance ( 'ezcomments.ini' ) ; $ subscriber = ezcomSubscriber :: fetchByEmail ( $ email ) ; //if there is no data in subscriber for same email, save it if ( is_null ( $ subscriber ) ) { $ subscriber = ezcomSubscriber :: create ( ) ; $ subscriber -> setAttribute ( 'user_id' , $ user -> attribute ( 'contentobject_id' ) ) ; $ subscriber -> setAttribute ( 'email' , $ email ) ; if ( $ user -> isAnonymous ( ) ) { $ util = ezcomUtility :: instance ( ) ; $ hashString = $ util -> generateSusbcriberHashString ( $ subscriber ) ; $ subscriber -> setAttribute ( 'hash_string' , $ hashString ) ; } $ subscriber -> store ( ) ; eZDebugSetting :: writeNotice ( 'extension-ezcomments' , 'Subscriber does not exist, added one' , __METHOD__ ) ; $ subscriber = ezcomSubscriber :: fetchByEmail ( $ email ) ; } else { if ( $ subscriber -> attribute ( 'enabled' ) == false ) { throw new Exception ( 'Subscription can not be added because the subscriber is disabled.' , self :: ERROR_SUBSCRIBER_DISABLED ) ; } } //3 insert into subscription table // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id $ hasSubscription = ezcomSubscription :: exists ( $ contentID , $ languageID , $ subscriptionType , $ email ) ; if ( $ hasSubscription === false ) { $ subscription = ezcomSubscription :: create ( ) ; $ subscription -> setAttribute ( 'user_id' , $ user -> attribute ( 'contentobject_id' ) ) ; $ subscription -> setAttribute ( 'subscriber_id' , $ subscriber -> attribute ( 'id' ) ) ; $ subscription -> setAttribute ( 'subscription_type' , $ subscriptionType ) ; $ subscription -> setAttribute ( 'content_id' , $ contentID ) ; $ subscription -> setAttribute ( 'language_id' , $ languageID ) ; $ subscription -> setAttribute ( 'subscription_time' , $ currentTime ) ; $ defaultActivated = $ ezcommentsINI -> variable ( 'CommentSettings' , 'SubscriptionActivated' ) ; if ( $ user -> isAnonymous ( ) && $ defaultActivated !== 'true' && $ activate === true ) { $ subscription -> setAttribute ( 'enabled' , 0 ) ; $ utility = ezcomUtility :: instance ( ) ; $ subscription -> setAttribute ( 'hash_string' , $ utility -> generateSubscriptionHashString ( $ subscription ) ) ; $ subscription -> store ( ) ; $ result = ezcomSubscriptionManager :: sendActivationEmail ( eZContentObject :: fetch ( $ contentID ) , $ subscriber , $ subscription ) ; if ( ! $ result ) { eZDebug :: writeError ( "Error sending mail to '$email'" , __METHOD__ ) ; } } else { $ subscription -> setAttribute ( 'enabled' , 1 ) ; $ subscription -> store ( ) ; } eZDebugSetting :: writeNotice ( 'extension-ezcomments' , 'No existing subscription for this content and user, added one' , __METHOD__ ) ; } }
Add an subscription. If the subscriber is disabled, throw an exception
If there is no subscriber, add one.
If there is no subscription for the content, add one
@param $email: user's email
@return void
Add an subscription . If the subscriber is disabled throw an exception If there is no subscriber add one . If there is no subscription for the content add one