Tridion UGC Blog Series: Manage Comments

Submitting and Viewing UGC Comments through a Web Page

Once you have setup and configured UGC successfully (Refer THIS post) the major functionality of UGC you may want to integrate on your website page is submitting comments by the visitors of your web site and display of comments on a particular content to the visitors of your website. There are two ways to achieve it:

  1. Using UGC Mark-ups
  2. Using Tridion UGC Web Service API

Submit and View UGC Comments using UGC Markup

You can refer the ugc samples comes in the SDL Tridion 2013 installation disk for typical UGC markups for Submitting and Viewing comments. A typical markup for submitting and viewing the already submitted comments are as shown below – you can put this in your template building block or choose to create a User Control to be rendered at run time:

Display All Comments:

tcm:2-95-64 – TCM URI of the Page on which Comments are submitted and displayed

<ugc:ManageComments runat="server" ItemURI="tcm:2-95-64" PostParameter="addCommenttcm:2-95-64" UsernameParameter="usernametcm:2-95-64" EmailParameter="emailtcm:2-95-64" EditParameter="editCommenttcm:2-95-64" CommentIdParameter="commentIdtcm:2-95-64" RemoveParameter="removeCommenttcm:2-95-64"> 
 <!-- Display comments section -->
 <h3>Comments view</h3>
 <ugc:VoteComment runat="server" VoteParameter="votetcm:2-95-64" CommentIdParameter="commentIdtcm:2-95-64"> 
 <!-- Show all comments (including unmoderated comments) -->
 <ugc:Comments runat="server" ItemURI="tcm:2-95-64"> 
 <ol>
 <ugc:ForEachComment runat="server"> 
 <li>
 Author: <ugc:ContextVariable runat='server' Var='ugcComment.User.Name'/><br/> 
 <ugc:Choose runat="server"> 
 <ugc:When runat="server" Test="ugcUserId equals ugcComment.User.Id"> 
 <form method="post" id="editCommentForm">
 <input type="hidden" name="commentIdtcm:2-95-64" value="<ugc:ContextVariable runat='server' Var='ugcComment.Id'/>"/>
 <textarea rows="4" cols="30" name="editCommenttcm:2-95-64"><ugc:ContextVariable runat='server' Var='ugcComment.Content'/></textarea><br/>
 <input type="submit" value="Save comment"/>
 </form>
 <form method="post" id="removeCommentForm" style="display: inline">
 <input type="hidden" name="removeCommenttcm:2-95-64" value="<ugc:ContextVariable runat='server' Var='ugcComment.Id'/>"/>
 <input type="submit" value="Remove comment"/>
 </form>
 </ugc:When> 
 <ugc:Otherwise runat="server"> 
 <ugc:ContextVariable runat='server' Var='ugcComment.Content'/> 
 </ugc:Otherwise> 
 </ugc:Choose> 
 <br/>
 
 Comment score: <ugc:ContextVariable runat='server' Var='ugcComment.Score'/> 
 <form method="post" id="like" style="display: inline">
 <input type="hidden" name="commentIdtcm:2-95-64" value="<ugc:ContextVariable runat='server' Var='ugcComment.Id'/>"/>
 <input type="hidden" name="votetcm:2-95-64" value="up">
 <input type="submit" value="Like">
 </form>
 <form method="post" id="dislike" style="display: inline">
 <input type="hidden" name="commentIdtcm:2-95-64" value="<ugc:ContextVariable runat='server' Var='ugcComment.Id'/>"/>
 <input type="hidden" name="votetcm:2-95-64" value="down">
 <input type="submit" value="Dislike">
 </form>
 </li>
 </ugc:ForEachComment> 
 </ol>
 </ugc:Comments> 
 </ugc:VoteComment>
</ugc:ManageComments>

Post a Comment:

<ugc:ManageComments runat="server" ItemURI="tcm:2-95-64" PostParameter="addCommenttcm:2-95-64" UsernameParameter="usernametcm:2-95-64" EmailParameter="emailtcm:2-95-64" EditParameter="editCommenttcm:2-95-64" CommentIdParameter="commentIdtcm:2-95-64" RemoveParameter="removeCommenttcm:2-95-64">
<!-- Send comments section -->
 <h3>Comments post</h3>
 <fieldset style="width:270px">
 <legend><b>Post a new comment</b></legend> 
 <form method="post" id="commentForm">
 <table border="0">
 <tr><td><label for="newCommentName">Name:</label></td>
 <td><input id="newCommentName" type="text" name="usernametcm:2-95-64" value=""/></td></tr>
 <tr><td><label for="newCommentEmail">Email:</label></td>
 <td><input id="newCommentEmail" type="text" name="emailtcm:2-95-64" value=""/></td></tr>
 <tr><td colspan="2"><label for="newCommentText">Enter comment:</label><br/>
 <textarea id="newCommentText" rows="4" cols="30" name="addCommenttcm:2-95-64"></textarea></td></tr>
 <tr><td colspan="2"><input type="submit" name="B1" value="Submit"/>
 <input type="reset" name="B2" value="Reset"/>
 </td></tr>
 </table>
 </form>
 </fieldset>
 </ugc:ManageComments>

Submit and View UGC Comments using Tridion UGC Web Service API

Instead of UGC markup, from the scalability, flexibility and manageability purpose, you may want to use Tridion UGC Web Service to perform various activities like submitting the comments, retrieving the comments etc. by making web service calls.

For this, please get the Tridion.ContentDelivery.UGC.dll from the SDL Tridion installation disk and add a reference to it.In your code, add following using namespaces:

using Tridion.ContentDelivery.UGC.Web.Model;
using Tridion.ContentDelivery.UGC.WebService;

then use following web service calls:

To Retrieve All Comments for a page:

CommentsRetriever.RetrieveComments(PageUri, Submitted, FlaggedForModeration, Posted, Resubmitted, Rejected, FlaggedForDeletion, OrderDescending, int.MaxValue, 0);

This will return a List<Comment> object which can be traversed to retrieve various information about the comment as below:

Comment.User.Name - Name of the Comment Submitter
Comment.CreationDate - Comment Create Date
Comment.Content - Comment Text
Comment.Score - Total Number of likes for the comment

To Post a Comment for a page:

WebServiceHelper.PostComment(PageUri, UserName, UserEmailID, CommentText);

Based on your need, you can user either way of Retrieving and Submitting the Comments for a Page (or similarly for a content on a page).

NEXT – Submit and View Ratings

LATERTridion UGC Web Service API Cheatsheet

LATERManaging and Analyzing Comments/Rating from CME

10+ years of experience in Software Development Life Cycle using AGILE, Iterative and RUP approaches. Hand-on experience in following: - CMS packages: SDL Tridion, Umbraco, Kentico, SiteFinity and Alfresco - Search Engines: SOLR, Endecca, FAST - .NET Technologies: .NET & .NET CE Framework, ASP.NET, ASP.NET MVC, WCF, WinForms - Mobile Development: Android Native App, Windows Mobile App - Database: MS-SQL Server, MySQL - Program Management: JIRA, MS-Project - Design Tools: MS-Visio, StarUML Have decent knowledge about Core Java, Spring MVC, Ektron and Google Mini Instrumental in Application Architecture, Designing (HLD & LLD), Coding and deployment .NET applications (Web, Desktop, Mobile). Experience in following domain: - Digital Media & eCommerce - Travel & Hospitality - Aviation Industry - Education - Insurance - Automation - Automobile - Railways Freelance trainer and consultant in .NET, CMS, SDL Tridion, Alfresco and soft skills like business communication, e-mail etiquette etc. Education: Bachelor Degree in Computer Engineering and Post Graduate Diploma in Business Administration with specialization in Marketing

Tagged with: , , ,
Posted in SDL Tridion

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: