Poll comments

Vote:
 

I need the users to be able to comment on a poll. I cant find a way to do this.

Any good ideas?

 

#28293
Mar 02, 2009 11:27
Vote:
 

You could add a new attribute (that is an EPiServer community attribute) to the Poll class of type Blog. Then create a new module with module dependencies for the Poll- and Blog-modules. In your module you add a listener for the PollAdded-event on PollHandler in which you create a new Blog and assign it to the comment attribute of the newly created Poll.

This way all new Polls will have their own blog which can be accessed via GetAttributeValue (you might want to abstract the access by creating an extension method or by inheriting Poll and wrapping the attribute in a property). Each comment can then be an entry in the Polls blog.

Hope this helps. If my above explanation is a bit tricky to follow let me know and I can give you some code examples, given that I find some time :)

#28307
Mar 02, 2009 17:39
Vote:
 
Example code is always nice.
#28312
Mar 03, 2009 10:11
Vote:
 

To add a blog to all new polls create a module like this:

using System;
using System.Web;
using EPiServer.Common;
using EPiServer.Community.Blog;
using EPiServer.Community.Poll;

namespace EPiServer.Templates.RelatePlus.HttpModules
{
public class PollCommentsModule : IHttpModule
{
private static bool _communityStarted;
private static readonly Object _lockObject = new Object();

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(EndRequest);
}

private static void EndRequest(object sender, EventArgs e)
{
if (_communityStarted)
{
return;
}
lock (_lockObject)
{
if (_communityStarted)
{
return;
}

PollHandler.PollAdded += (s, args) =>
{
Poll poll = (Poll)args.Object;
string blogName = string.Format("Comments blog for poll with ID {0}", poll.ID);
Blog blog = new Blog(blogName);
blog = BlogHandler.AddBlog(blog);
poll.SetAttributeValue("CommentsBlog", blog);
PollHandler.UpdatePoll(poll);
};
_communityStarted = true;
}
}
}
}
You can then retrieve the Blog by using:
Blog commentsBlog = poll.GetAttributeValue("CommentsBlog"); 

 

#28327
Edited, Mar 03, 2009 14:00
Vote:
 
I wrote a blog post inspired by this thread.
#28531
Mar 13, 2009 8:43
Vote:
 
#55547
Edited, Dec 07, 2011 10:59
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.