[xwiki-users] Adding survey question and details to page template...
One of the things I've been asked to accomplish using XWiki is a single question *survey* type section at the bottom of my FAQ pages. Something like: 68% of 158 people found this information useful. Was this information helpful? O Yes O No [Submit] You get the idea. Now, the problem is I'm not sure exactly how I'd accomplish something like this. I know I can create a survey class and sheet that will allow me to store the data and display it the way I want, but how do I update the values when the person clicks submit? Would it just be an update SQL statement, or would I update properties of an attached instance of the survey class and then save the page? Any hints or examples would be appreciated. I found the Polls application, but it only supports creating a new poll and not updating values in an existing Poll, which is more like what I am looking to do. Thanks! .:. Kevin -- View this message in context: http://n2.nabble.com/Adding-survey-question-and-details-to-page-template...-... Sent from the XWiki- Users mailing list archive at Nabble.com.
I got it. -- View this message in context: http://n2.nabble.com/Adding-survey-question-and-details-to-page-template...-... Sent from the XWiki- Users mailing list archive at Nabble.com.
Kevin and others It is really good that you "got it" but I think it is very important for people to share with others what they "got", so if someone has a similar problem he/she can at least see a possible solution rather than repost the same question again. This happens very often on all forums. In my mind it doesn't matter how simple / trivial the solution is (user error, one line code etc) the point is it should be described and posted for future use. Regards Ajdin -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of KevinC Sent: 21 January 2009 18:41 To: [email protected] Subject: Re: [xwiki-users] Adding survey question and details to page template... I got it. -- View this message in context: http://n2.nabble.com/Adding-survey-question-and-details-to-page-template ...-tp2192675p2193848.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users -------------------------------------------------------- NOTICE This message and any files transmitted with it is intended for the addressee only and may contain information that is confidential or privileged. Unauthorised use is strictly prohibited. If you are not the addressee, you should not read, copy, disclose or otherwise use this message, except for the purpose of delivery to the addressee. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of Coventry University.
Ajdin, You are absolutely right, especially since there seem to be so few people posting information from a users perspective. So here's what I did. The key to getting it working was an example I found in the snippets section that talked about how to create new documents with Tags. It showed an example of how to check if there was an instance of a certain class already attached to a document and create one if not (I already knew how to do this more or less). The important piece was how to set a property on that object once you have a handle to it. I don't have the code done completely yet but the basic shell is something like: #set($surveyObj = $doc.getObject("CPA_FAQs.SurveyClass")) #set($surveyChoice = $request.getParameter("surveyChoice")) #if(!$surveyObj) ##Create a new survey object and attach it to this document. #set($sObj = $doc.newObject("CPA_FAQs.SurveyClass")) $sObj.set("votetotal", $voteCnt) ## these are just here as an example $sObj.set("voters", $voters) ## as I haven't even created the Survey class yet $doc.save() #end #if($surveyChoice) ## Need to update the objects values here #end ## If the current user has voted don't allow them to vote again Was this information useful to you? <form action="${doc.getURL()}" method="POST" style="display: inline"> <input name="surveyChoice" type="radio" name="Yes" value="Yes"/>Yes <input name="surveyChoice" type="radio" name="No" value="No"/>No <input type="submit" value="Submit"/> </form> I still need to implement a few things but I know should work for what I need. The main thing I'm trying to determine at this point is if I can't require someone to have an account in order to vote, how do I keep them from voting multiple times? I can't use cookies, and I'm not sure using their IP address will prove of any use. Even if users do have to register in order to vote, I'm not sure there's an API method available that allows me to access their unique user ID as opposed to their user name. If I have to track usernames on each of these objects for all of the people who have ever voted on a particular question it could get out of hand really fast! Any ideas? Thanks! .:. Kevin -- View this message in context: http://n2.nabble.com/Adding-survey-question-and-details-to-page-template...-... Sent from the XWiki- Users mailing list archive at Nabble.com.
Kevin
The main thing I'm trying to determine at this point is if I can't require someone to have an account in order to vote, how do I keep them from voting multiple times? I can't use cookies, and I'm not sure using their IP address will prove of any use. Even if users do have to register in order to vote, I'm not sure there's an API method available that allows me to access their unique user ID as opposed to their user name. If I have to track usernames on each of these objects for all of the people who have ever voted on a particular question it could get out of hand really fast! Any ideas?
Not sure if storing IDs instead of usernames makes much difference. Also IP addresses will change but maybe not that often. Just thinking but perhaps you could create a new property in your page class and add username to it each time someone votes. Then on load (view mode) you can get this list of usernames as an array and loop to check if current user already in there. If so then do not show the vote form. Ajdin -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of KevinC Sent: 22 January 2009 12:54 To: [email protected] Subject: Re: [xwiki-users] Adding survey question and details to page template... Ajdin, You are absolutely right, especially since there seem to be so few people posting information from a users perspective. So here's what I did. The key to getting it working was an example I found in the snippets section that talked about how to create new documents with Tags. It showed an example of how to check if there was an instance of a certain class already attached to a document and create one if not (I already knew how to do this more or less). The important piece was how to set a property on that object once you have a handle to it. I don't have the code done completely yet but the basic shell is something like: #set($surveyObj = $doc.getObject("CPA_FAQs.SurveyClass")) #set($surveyChoice = $request.getParameter("surveyChoice")) #if(!$surveyObj) ##Create a new survey object and attach it to this document. #set($sObj = $doc.newObject("CPA_FAQs.SurveyClass")) $sObj.set("votetotal", $voteCnt) ## these are just here as an example $sObj.set("voters", $voters) ## as I haven't even created the Survey class yet $doc.save() #end #if($surveyChoice) ## Need to update the objects values here #end ## If the current user has voted don't allow them to vote again Was this information useful to you? <form action="${doc.getURL()}" method="POST" style="display: inline"> <input name="surveyChoice" type="radio" name="Yes" value="Yes"/>Yes <input name="surveyChoice" type="radio" name="No" value="No"/>No <input type="submit" value="Submit"/> </form> I still need to implement a few things but I know should work for what I need. The main thing I'm trying to determine at this point is if I can't require someone to have an account in order to vote, how do I keep them from voting multiple times? I can't use cookies, and I'm not sure using their IP address will prove of any use. Even if users do have to register in order to vote, I'm not sure there's an API method available that allows me to access their unique user ID as opposed to their user name. If I have to track usernames on each of these objects for all of the people who have ever voted on a particular question it could get out of hand really fast! Any ideas? Thanks! .:. Kevin -- View this message in context: http://n2.nabble.com/Adding-survey-question-and-details-to-page-template ...-tp2192675p2197567.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users -------------------------------------------------------- NOTICE This message and any files transmitted with it is intended for the addressee only and may contain information that is confidential or privileged. Unauthorised use is strictly prohibited. If you are not the addressee, you should not read, copy, disclose or otherwise use this message, except for the purpose of delivery to the addressee. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of Coventry University.
participants (2)
-
Ajdin Brandic -
KevinC