public function testActivateSubscription()
 {
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('email', '*****@*****.**');
     $subscriber->setAttribute('user_id', 10);
     $subscriber->store();
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('subscriber_type', 'ezcomcomment');
     $subscription->setAttribute('enabled', 0);
     $subscription->setAttribute('content_id', '10_2');
     $hashString = ezcomUtility::instance()->generateSubscriptionHashString($subscription);
     $subscription->setAttribute('hash_string', $hashString);
     $subscription->store();
     $id = $subscription->attribute('id');
     $tpl = eZTemplate::factory();
     $subscriptionManager = ezcomSubscriptionManager::instance($tpl, null, null, 'ezcomSubscriptionManager');
     $subscriptionManager->activateSubscription($hashString);
     $subscriptionActivated = ezcomSubscription::fetch($id);
     $this->assertEquals(1, $subscriptionActivated->attribute('enabled'));
 }
Ejemplo n.º 2
0
            if (!$subscribed) {
                $subscription->remove();
            }
        }
        $tpl->setVariable('update_success', 1);
        $redirectURI = 'comment/setting';
        if (!is_null($hashString)) {
            $redirectURI = $redirectURI . '/' . $hashString;
        }
        $module->redirectTo($redirectURI);
        return;
    }
}
//1.fetch Contents
$ini = eZINI::instance('ezcomments.ini');
$numberPerPage = $ini->variable('NotificationSettings', 'NumberPerPage');
$limit = array();
$limit['offset'] = ($page - 1) * $numberPerPage;
$limit['length'] = $numberPerPage;
$sorts = array();
$sorts = array('subscription_time' => 'desc');
$iniSite = eZINI::instance();
$languageCode = $iniSite->variable('RegionalSettings', 'ContentObjectLocale');
$language = eZContentLanguage::fetchByLocale($languageCode);
$languageID = $language->attribute('id');
$subscriptionList = ezcomSubscription::fetchListBySubscriberID($subscriber->attribute('id'), $languageID, 1, $sorts, $limit);
$totalCount = ezcomSubscription::countWithSubscriberID($subscriber->attribute('id'), $languageID, 1);
$tpl->setVariable('subscription_list', $subscriptionList);
$tpl->setVariable('total_count', $totalCount);
$Result['content'] = $tpl->fetch('design:comment/setting.tpl');
$Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezcomments/comment/setting', 'Comment settings')));
Ejemplo n.º 3
0
 /**
  * Test exists method
  */
 public function testExists()
 {
     $subscriptionType = 'ezcomcomment';
     //insert a subscriber object and subscription object
     $time = time();
     $testemail = '*****@*****.**';
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('email', $testemail);
     $subscriber->setAttribute('user_id', 10);
     $subscriber->setAttribute('enabled', 0);
     $subscriber->store();
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('user_id', 15);
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('subscription_type', $subscriptionType);
     $subscription->setAttribute('content_id', '210');
     $subscription->setAttribute('subscription_time', $time);
     $subscription->setAttribute('enabled', 1);
     $subscription->setAttribute('language_id', 2);
     $subscription->store();
     //1. test if the subscription exists by contentID
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType);
     $this->assertTrue($exists);
     $exists = ezcomSubscription::exists('20009', '2', $subscriptionType);
     $this->assertFalse($exists);
     $exists = ezcomSubscription::exists('20009', '2', 'othertypesssss');
     $this->assertFalse($exists);
     $exists = ezcomSubscription::exists('20009', '2', 'othertypesssss', null, null);
     $this->assertNull($exists);
     //2. test if the subsription exists by contenetID and enabled
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, null, 0);
     $this->assertTrue($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, null, 1);
     $this->assertFalse($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, null, 12);
     $this->assertNull($exists);
     //3. test if the subscription exists by contentID and email
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, $testemail);
     $this->assertTrue($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, '*****@*****.**');
     $this->assertFalse($exists);
     //4. test if the subscription exists by contentID, email and enabled
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, $testemail, 0);
     $this->assertTrue($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, $testemail, 1);
     $this->assertFalse($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, '*****@*****.**', 0);
     $this->assertFalse($exists);
     $exists = ezcomSubscription::exists('210', '2', $subscriptionType, $testemail, 46);
     $this->assertNull($exists);
 }
Ejemplo n.º 4
0
Archivo: add.php Proyecto: legende91/ez
         $changeNotification = true;
     } else {
         //email is disabled in setting but user logged in
         if (is_null($email) && !$user->isAnonymous()) {
             $changeNotification = true;
             $email = $user->attribute('email');
             $comment->setAttribute('email', $email);
         }
     }
 }
 $commentManager = ezcomCommentManager::instance();
 $commentManager->tpl = $tpl;
 $existingNotification = false;
 $addingResult = false;
 if ($changeNotification) {
     $existingNotification = ezcomSubscription::exists($contentObjectId, $languageId, 'ezcomcomment', $email);
     if (!$existingNotification) {
         $addingResult = $commentManager->addComment($comment, $user, null, true);
     } else {
         $addingResult = $commentManager->addComment($comment, $user);
     }
 } else {
     $addingResult = $commentManager->addComment($comment, $user);
 }
 if ($addingResult !== true) {
     $tpl->setVariable('error_message', $addingResult);
     $Result['content'] = $tpl->fetch('design:comment/add.tpl');
     return $Result;
 }
 $tpl->setVariable('success', true);
 // add additional success message
Ejemplo n.º 5
0
$canEdit = $canEditResult['result'];
$tpl->setVariable('can_edit', $canEdit);
if (!$canEdit) {
    $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezcomments/comment/edit', 'Edit comment')));
    $Result['content'] = $tpl->fetch('design:comment/edit.tpl');
    return $Result;
}
$contentID = $comment->attribute('contentobject_id');
// get if notification is enabled and notification value
$ini = eZINI::instance('ezcomments.ini');
$formSettings = $ini->variable('FormSettings', 'AvailableFields');
$notificationEnabled = in_array('notificationField', $formSettings);
$emailEnabled = in_array('email', $formSettings);
$notified = null;
if ($notificationEnabled) {
    $notified = ezcomSubscription::exists($contentID, $languageID, 'ezcomcomment', $comment->attribute('email'));
    $tpl->setVariable('notified', $notified);
}
if ($Module->isCurrentAction('UpdateComment')) {
    // Validate given input date against form setup
    $formTool = ezcomEditCommentTool::instance();
    $formStatus = $formTool->checkVars();
    if (!$formStatus) {
        // missing form data
        $tpl->setVariable('error_message', ezpI18n::tr('ezcomments/comment/add/form', 'There is a problem with your comment form '));
        $tpl->setVariable('validation_messages', $formTool->messages());
        return showComment($comment, $tpl);
    }
    //TODO: code from 93 can be implement in a class, see another TODO in add.php
    $formTool->fillObject($comment);
    $time = time();
 /**
  * Test the addcomment method in ezcomComment
  */
 public function testAddComment()
 {
     //1. test adding a comment without notification
     $time = time();
     $contentObjectID = 209;
     $languageID = 2;
     $comment = ezcomComment::create();
     $comment->setAttribute('name', 'xc');
     $comment->setAttribute('email', '*****@*****.**');
     $comment->setAttribute('text', 'This is a test comment:)');
     $comment->setAttribute('contentobject_id', $contentObjectID);
     $comment->setAttribute('language_id', $languageID);
     $comment->setAttribute('created', $time);
     $comment->setAttribute('modified', $time);
     $user = eZUser::currentUser();
     $commentManager = ezcomCommentManager::instance();
     //1.1 without subscription
     $result = $commentManager->addComment($comment, $user);
     $this->assertSame(true, $result);
     //1.2 with subscription
     //add subscriber
     $time = $time + 1;
     $comment = ezcomComment::create();
     $comment->setAttribute('name', 'xc');
     $comment->setAttribute('email', '*****@*****.**');
     $comment->setAttribute('text', 'This is a test comment:)');
     $comment->setAttribute('contentobject_id', $contentObjectID);
     $comment->setAttribute('language_id', $languageID);
     $comment->setAttribute('created', $time);
     $comment->setAttribute('modified', $time);
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('user_id', $user->attribute('contentobject_id'));
     $subscriber->setAttribute('email', $comment->attribute('email'));
     $subscriber->store();
     //add subscription
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('content_id', $contentObjectID);
     $subscription->setAttribute('language_id', $languageID);
     $subscription->setAttribute('user_id', $user->attribute('contentobject_id'));
     $subscription->setAttribute('subscription_type', 'ezcomcomment');
     $subscription->setAttribute('subscription_time', $time);
     $subscription->store();
     //add comment
     $result = $commentManager->addComment($comment, $user);
     $this->assertSame(true, $result);
     //verify the notification
     $notifications = ezcomNotification::fetchNotificationList(1, 1, 0, array('id' => 'desc'));
     $this->assertEquals($contentObjectID, $notifications[0]->attribute('contentobject_id'));
     $this->assertEquals($comment->attribute('id'), $notifications[0]->attribute('comment_id'));
     $this->assertEquals($languageID, $notifications[0]->attribute('language_id'));
     //2. test adding a comment with notification
     $time2 = time() + 3;
     $contentObjectID = 210;
     $languageID = 2;
     $comment2 = ezcomComment::create();
     $comment2->setAttribute('name', 'chen');
     $comment2->setAttribute('email', '*****@*****.**');
     $comment2->setAttribute('text', 'notified comment');
     $comment2->setAttribute('contentobject_id', $contentObjectID);
     $comment2->setAttribute('language_id', $languageID);
     $comment2->setAttribute('created', $time2);
     $comment2->setAttribute('modified', $time2);
     $user2 = eZUser::currentUser();
     //2.1 if there is no subscription
     $result2 = $commentManager->addComment($comment2, $user2, $time2);
     $this->assertSame(true, $result2);
     $notifications = ezcomNotification::fetchNotificationList(1, 1, 0, array('id' => 'desc'));
     $this->assertNotEquals($notifications[0]->attribute('comment_id'), $comment2->attribute('id'));
     //assert that there is no new notification
     //2.2 if there is already subscription
     $comment2 = ezcomComment::create();
     $comment2->setAttribute('name', 'chen');
     $comment2->setAttribute('email', '*****@*****.**');
     $comment2->setAttribute('text', 'notified comment');
     $comment2->setAttribute('contentobject_id', $contentObjectID);
     $comment2->setAttribute('language_id', $languageID);
     $time2 = $time2 + 1;
     //add subscriber
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('user_id', $user2->attribute('contentobject_id'));
     $subscriber->setAttribute('email', $comment2->attribute('email'));
     $subscriber->store();
     //add subscription
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('content_id', $contentObjectID);
     $subscription->setAttribute('language_id', $languageID);
     $subscription->setAttribute('user_id', $user2->attribute('contentobject_id'));
     $subscription->setAttribute('subscription_type', 'ezcomcomment');
     $subscription->setAttribute('subscription_time', $time2);
     $subscription->store();
     //add comment
     $comment2->setAttribute('created', $time2);
     $comment2->setAttribute('modified', $time2);
     $result = $commentManager->addComment($comment2, $user2, $time2);
     $this->assertSame(true, $result);
     //vertify the notification
     $notifications = ezcomNotification::fetchNotificationList(1, 1, 0, array('id' => 'desc'));
     $this->assertEquals($contentObjectID, $notifications[0]->attribute('contentobject_id'));
     $this->assertEquals($comment2->attribute('id'), $notifications[0]->attribute('comment_id'));
     $this->assertEquals($languageID, $notifications[0]->attribute('language_id'));
 }
 /**
  * clean up subscription after updating comment
  * @see extension/ezcomments/classes/ezcomCommentManager#afterUpdatingComment($comment, $notified)
  */
 public function afterUpdatingComment($comment, $notified, $time)
 {
     $user = eZUser::fetch($comment->attribute('user_id'));
     // if notified is true, add subscription, else cleanup the subscription on the user and content
     $contentID = $comment->attribute('contentobject_id');
     $languageID = $comment->attribute('language_id');
     $subscriptionType = 'ezcomcomment';
     if (!is_null($notified)) {
         $subscriptionManager = ezcomSubscriptionManager::instance();
         if ($notified === true) {
             //add subscription but not send activation
             try {
                 $subscriptionManager->addSubscription($comment->attribute('email'), $user, $contentID, $languageID, $subscriptionType, $time, false);
             } catch (Exception $e) {
                 eZDebug::writeError($e->getMessage(), __METHOD__);
                 switch ($e->getCode()) {
                     case ezcomSubscriptionManager::ERROR_SUBSCRIBER_DISABLED:
                         return 'The subscriber is disabled.';
                     default:
                         return false;
                 }
             }
         } else {
             $subscriptionManager->deleteSubscription($comment->attribute('email'), $comment->attribute('contentobject_id'), $comment->attribute('language_id'));
         }
     }
     //3. update queue. If there is subscription, add one record into queue table
     // if there is subcription on this content, add one item into queue
     if (ezcomSubscription::exists($contentID, $languageID, $subscriptionType)) {
         $notification = ezcomNotification::create();
         $notification->setAttribute('contentobject_id', $comment->attribute('contentobject_id'));
         $notification->setAttribute('language_id', $comment->attribute('language_id'));
         $notification->setAttribute('comment_id', $comment->attribute('id'));
         $notification->store();
         eZDebugSetting::writeNotice('extension-ezcomments', 'There are subscriptions, added an update notification to the queue.', __METHOD__);
     } else {
         // todo: if there is no subscription on this content, consider to clean up the queue
     }
     return true;
 }
 /**
  * delete the subscription given the subscriber's email
  * @param $email
  * @param $contentObjectID
  * @param $languageID
  * @return unknown_type
  */
 public function deleteSubscription($email, $contentObjectID, $languageID)
 {
     $subscriber = ezcomSubscriber::fetchByEmail($email);
     $cond = array();
     $cond['subscriber_id'] = $subscriber->attribute('id');
     $cond['content_id'] = $contentObjectID;
     $cond['language_id'] = $languageID;
     $cond['subscription_type'] = 'ezcomcomment';
     $subscription = ezcomSubscription::fetchByCond($cond);
     $subscription->remove();
 }