$Result['content'] = $tpl->fetch('design:comment/add.tpl'); return $Result; } else { // Validate given input date against form setup $formTool = ezcomAddCommentTool::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()); $Result['content'] = $tpl->fetch('design:comment/add.tpl'); return $Result; } //TODO: from 63, most of the code can be implemented in a class see another TODO in edit.php // Build ezcomcomment object $comment = ezcomComment::create(); $formTool->fillObject($comment); $comment->setAttribute('contentobject_id', $contentObjectId); $languageId = eZContentLanguage::idByLocale($languageCode); $comment->setAttribute('language_id', $languageId); $sessionKey = $http->getSessionKey(); $comment->setAttribute('session_key', $sessionKey); $util = ezcomUtility::instance(); $ip = $util->getUserIP(); $comment->setAttribute('ip', $ip); $user = eZUser::currentUser(); $comment->setAttribute('user_id', $user->attribute('contentobject_id')); $currentTime = time(); $comment->setAttribute('created', $currentTime); $comment->setAttribute('modified', $currentTime); // toggle notification state on change in state
$tpl = eZTemplate::factory(); $user = eZUser::currentUser(); $http = eZHttpTool::instance(); // get the action parameter $Module = $Params['Module']; $commentID = $Params['CommentID']; // fetch comment object if (is_null($commentID) || $commentID == '') { eZDebug::writeError('The parameter comment id is null.', 'ezcomments'); return; } if (!is_numeric($commentID)) { eZDebug::writeError('The parameter comment id is not a number.', 'ezcomments'); return; } $comment = ezcomComment::fetch($commentID); if (is_null($comment)) { eZDebug::writeError('The comment doesn\'t exist.', 'ezcomments'); return; } //check the permission $contentObject = $comment->contentObject(); $contentNode = $contentObject->mainNode(); $languageID = $comment->attribute('language_id'); $languageCode = eZContentLanguage::fetch($languageID)->attribute('locale'); $canEdit = false; $canEditResult = ezcomPermission::hasAccessToFunction('edit', $contentObject, $languageCode, $comment, null, $contentNode); $canEdit = $canEditResult['result']; $tpl->setVariable('can_edit', $canEdit); if (!$canEdit) { $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezcomments/comment/edit', 'Edit comment')));
/** * Test FetchByContentObjectList */ public function testFetchByContentObjectIDList() { $language = eZContentLanguage::fetchByLocale('eng-GB'); $languageID = $language->attribute('id'); $time = time(); $comment1 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time, 'modified' => $time, 'text' => 'comment1', 'user_id' => 15); $comment2 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 1, 'modified' => $time + 1, 'text' => 'comment2', 'user_id' => 15); $comment3 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 2, 'modified' => $time + 2, 'text' => 'comment3', 'user_id' => 15); $comment4 = array('contentobject_id' => 14, 'language_id' => $languageID, 'created' => $time + 3, 'modified' => $time + 3, 'text' => 'comment4', 'user_id' => 14); $comment = ezcomComment::create($comment1); $comment->store(); $comment = ezcomComment::create($comment2); $comment->store(); $comment = ezcomComment::create($comment3); $comment->store(); $comment = ezcomComment::create($comment4); $comment->store(); // test null contentobject id and user id $result = ezcomComment::fetchByContentObjectIDList(null, 15, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment3', $result[0]->attribute('text')); $this->assertEquals('comment1', $result[2]->attribute('text')); // test null contentobject id array and empty user_id $result = ezcomComment::fetchByContentObjectIDList(null, null, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment1', $result[3]->attribute('text')); // test one contentobject id array $result = ezcomComment::fetchByContentObjectIDList(array(14), null, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment4', $result[0]->attribute('text')); // test many contentobjects array and sort $result = ezcomComment::fetchByContentObjectIDList(array(14, 15), null, 'eng-GB', null, array('modified' => 'asc'), 0); $this->assertEquals('comment3', $result[2]->attribute('text')); // test length with all null $result = ezcomComment::fetchByContentObjectIDList(null, null, null, null, null, null, 3); $this->assertEquals(3, count($result)); }
/** * 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')); }
/** * When deleting the content object, deleting all the comments. * @see kernel/classes/eZDataType#deleteStoredObjectAttribute($objectAttribute, $version) */ function deleteStoredObjectAttribute($contentObjectAttribute, $version = null) { $version = $contentObjectAttribute->objectVersion(); if (!is_null($version) && $version->attribute('status') == eZContentObjectVersion::STATUS_PUBLISHED) { $contentObjectID = $contentObjectAttribute->attribute('contentobject_id'); $languageID = $contentObjectAttribute->attribute('language_id'); eZPersistentObject::removeObject(ezcomComment::definition(), array('contentobject_id' => $contentObjectID, 'language_id' => $languageID)); } }
* File containing logic of removecomments view * * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * */ $Module = $Params['Module']; $http = eZHTTPTool::instance(); if ($http->hasPostVariable('ConfirmButton')) { $deleteIDArray = $http->hasSessionVariable('DeleteCommentsIDArray') ? $http->sessionVariable('DeleteCommentsIDArray') : array(); if (is_array($deleteIDArray) && !empty($deleteIDArray)) { $db = eZDB::instance(); $db->begin(); $commentManager = ezcomCommentManager::instance(); foreach ($deleteIDArray as $deleteID) { $commentToRemove = ezcomComment::fetch($deleteID); $deleteResult = $commentManager->deleteComment($commentToRemove); if ($deleteResult === true) { eZContentCacheManager::clearContentCacheIfNeeded($commentToRemove->attribute('contentobject_id')); } } $db->commit(); } $Module->redirectTo('/comment/list/'); } if ($http->hasPostVariable('CancelButton')) { $Module->redirectTo('/comment/list/'); } $contentInfoArray = array(); $tpl = eZTemplate::factory(); $tpl->setVariable('persistent_variable', false);
public static function fetchCommentCount($contentObjectID = false, $languageID = false, $status = null) { $result = ezcomComment::countByContent($contentObjectID, $languageID, $status); return array('result' => $result); }
if (is_null($contentObject)) { $cli->output("Content doesn't exist, delete the notification. Content ID:" . $contentObjectID); $db->query('DELETE FROM ezcomment_notification WHERE contentobject_id=' . $contentObjectID); continue; } // fetch subscribers $subscriptionList = $db->arrayQuery("SELECT subscriber_id FROM ezcomment_subscription" . " WHERE enabled = 1" . " AND content_id = {$contentObjectID}" . " AND language_id = {$contentLanguage}"); $subscriberList = array(); foreach ($subscriptionList as $subscription) { $subscriberList[] = ezcomSubscriber::fetch($subscription['subscriber_id']); } //fetch comment list $commentList = array(); foreach ($notifications as $notification) { // fetch comment object $comment = ezcomComment::fetch($notification['comment_id']); if (is_null($comment)) { $cli->output("Comment doesn't exist, delete the notification. Comment ID:" . $notification['comment_id']); $db->query('DELETE FROM ezcomment_notification WHERE id=' . $notification['id']); continue; } $commentList[] = $comment; } try { $notificationManager = ezcomNotificationManager::instance(); $commentsInOne = $ezcommentsINI->variable('NotificationSettings', 'CommentsInOne'); foreach ($subscriberList as $subscriber) { if ($commentsInOne !== 'true') { foreach ($commentList as $comment) { if ($comment->attribute('email') != $subscriber->attribute('email')) { $notificationManager->sendNotificationInMany($subscriber, $contentObject, $comment);