I’m looking for a way to limit comments on any post to one per member.
Specifically I have hacked together a product rating system for members (had to hack the mod.comment.php and then used the comment location field to store ratings)
Members can rate each product from 1 to 5 using the comment form.
Now I want to make sure that if a member has already commented and rated, they can’t rate again (so they can’t unduly skew results).
{if previously_rated} thanks, you’ve already rate this product! {/if}
Well, with extensions it should be easy with no hacking- I added a rating box to the form in about 10 minutes via an extension- now just need to add another hook and we can enter it into either a comment field or better yet a ratings table and it should work like you want.
No need to hack things up and alter the backend. I’ll post the results once I get the chance- or just look at the comment hooks- an extension should be easy to add.
Dinking with it now- trying to figure if it’s better to insert the rev data before or after the comment data. I prefer after- but if there was no comment, think that would trigger an error and keep it from getting to the ‘after’. So. Dinking.
Do they have to be members to leave a rating/comment? If not- how are you checking it? name/ip/email- some combo?
Yea- that’s currently the glitch- if they don’t add anything to the comment and I have the extension pluging in at the insert_comment_end then the rating doesn’t get added. But it’s nicer at the end because it means they’ve passed a ton of checks on whether they should post. Which- I could add some checks at the beginning, but I don’t want to get to redundant with it.
One thought was if there was anyway to combine the rating into the comment.
So essentially the comment field became “rating code” + comment.
That way, if they didn’t rate or didn’t comment, neither would cause a problem.
The rating would still need to be entered into a table field so that you could get an average of course.
Heh- I’m a sneaky bastard. What I did, added a hidden comment field at the top of the form- comment=’.’- so it won’t be empty. Then, IF you want to be able to have them submit a blank comment and still have the rating go in, you have to rename the comment field that shows to alt_comment- so in your template you have:
<p><textarea name="alt_comment" cols="70" rows="10">{comment}</textarea></p> instead of <p><textarea name="comment" cols="70" rows="10">{comment}</textarea></p>
Then, after the error checking has happend and I’ve inserted the rating, I swap it back out:
//sneaky bit if ($_POST['alt_comment'] == '') { if ( ! isset($_POST['RET']) OR $_POST['RET'] == '') { return false; }
Ah - I follow that - clever solution.
Now for the ratings, where are you storing them? A new table? or once of the existing comments fileds (e.g. location or URL)
Yea- I made it a module - still need the extension too. Just cleaner if it’s in its own table. Wanted to hack it, could be easily done to insert it into one of the member fields- location or something. I’m about done with it for the night- can download/test out/read the lame docs. I KNOW I need to go back in and make it work with preview- so expect that to explode. And basically- I need to step back and make sure the logic as a hole makes sense. Think so. Once it’s shined up, it will be pretty slick. Needs a lot of shining, though.
Anyway- I’m fried for the night. Oh- gotta register to download the zip- mostly because I’m testing a new download script, so you all must SUFFER! Hm- anyway, will dink with it tomorrow when I’m fresh and have thought on it a bit. Basic approach of using the comment form to piggy back was handy. Wonder how hard it would be to add an ajax interface? Not very, I bet.
Hopefully the sucker will install enough for you to test it out. But for tonight, I think I’m done playing with it.
Not understanding extensions I guess though.
How am I able to manually control this so that I can determine in which comment forms in which weblogs the rating system appears.
And so that I can custom design the rating system.
You have ratings built into the extenison to display on every comment page and the comment=”.”
So I am wondering how I can control this on an as needed basis. For most pages, I would use regular comment tags and no visible ratings. For some pages I will use comments and it would be nice if I could define the style of rating (so for example, I am looking at using the Amazon star system.) and critical that I can change the title and names of the ratings.
I assume I can remove the rate_it function and just put that directly into the forms of interest and have control that way (is this true?). But it would be better if there was some option so I could control aspects.
I am amazed on this in general. Look forward to tinkering.
Installed module and extension. While the rating drop down shows up in the form (as mentioned above, would be good to have this selected per comment from), when I submit a comment and rating, nothing shows up.
No comment posts and nothing appears in the exp_ez_rate_stats table.
Disable extension and comments reappear.
Am I missing an install step or something I need to customize for my site?
Hey artlab, sorry I’m pokey getting back to you. This sucker is turning into a full blown script. Check out updated docs and download- still very much beta, but the extension is no longer needed.
You CAN use the extension and I’ve added some bits to it and made it- you know- work. Hopefully. Be sure to disable the current extension you uploaded and delete it from your site. I went with a different naming structure in order to avoid some problems.
Give it a try- I need some debugging. I’m actually going to try and get a new one up tomorrow with an improved approach to the extension. And some other stuff.
Wow - this is getting to be a sophisticated little project.
Just installed and ran first test which seems very good, in fact phenomenal! Going to play some more.
Question: How would I be able to call to the database in order to show the individual rankings that each user gave.
So if they commented and rated and I wanted to show their rating along with their comment (like Amazon does), what would I need to do?
I tried the following but no luck (could be a simple error on my part)
{exp:comment:entries weblog=”{my_weblog}”}
{exp:query sql=“SELECT rating FROM exp_ez_rate_stats WHERE member_id = ‘{author_id}’”}
The rating: {rating}
{/exp:query}
{comment}
{/exp:comment:entries}
Never mind on the above. It does work - I think it might have been a page cache issue so the ranking was not showing up.
Will do more testing but this seems outstanding and a great addition to EE.
Did some more testing and am running into an odd problem.
If there are no ratings for a post, I am ending up with a blank page if I try to test for this.
So within my page detail, I have
Hi,
maybe I will have stupid question, is there any options how to sort entries by highest rate? for example gallery. I would like to sort images by highest rate.
I tried the code you posted in order to display the members rating
{exp:query sql=“SELECT rating FROM exp_ez_rate_stats WHERE member_id = ‘{author_id}’”}
The rating: {rating}
{/exp:query}
And I got the following error
MySQL ERROR:
Error Number: 1064
Description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘��4918’’ at line 1
Query: SELECT rating FROM exp_ez_rate_stats WHERE member_id = ‘4918’