1 of 2
1
Can you limit comments to one per member per article using PHP?
Posted: 19 February 2006 10:36 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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}

Can anyone suggest on how to do this in PHP?

Profile
 
 
Posted: 19 February 2006 11:14 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 February 2006 12:42 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

Can you post or send that extension?  I’m afraid I am pretty clueless on how to write extensions.

Profile
 
 
Posted: 19 February 2006 12:51 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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?

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 February 2006 01:02 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

Yes - I am requiring that they be members to that I can control that they don’t post/rate multiple times.

Good point on the after - I was wondering how I would deal with if the person did not comment but only rated.

Profile
 
 
Posted: 19 February 2006 01:10 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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.

Dinking some more….

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 February 2006 02:10 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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.

Not sure if that offers any solutions though.

look forward to your extension!

Profile
 
 
Posted: 19 February 2006 03:12 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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;
        
}
        
            $FNS
->redirect($_POST['RET']);
        
}
$data[
'comment'] = $REGX->xss_clean($_POST['alt_comment']);
return
$data;

And presto- it works.  OK- now to the initial question- get rid of the rating field if they’ve already rated it.  Should be easy.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 February 2006 03:55 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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)

Profile
 
 
Posted: 19 February 2006 04:53 PM   [ Ignore ]   [ # 9 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 February 2006 06:49 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

Got it installed. Will test shortly.

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.

Profile
 
 
Posted: 19 February 2006 11:57 PM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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?

Profile
 
 
Posted: 20 February 2006 05:59 PM   [ Ignore ]   [ # 12 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23485
Joined  05-20-2002

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.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 21 February 2006 03:33 PM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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}

Profile
 
 
Posted: 25 February 2006 10:31 AM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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.

Profile
 
 
Posted: 28 February 2006 02:53 PM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

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

{exp:ez_rate:form module=“weblog”}
{if current_votes }
{current_votes}
{/if}
{/exp:ez_rate:form}

On non rated posts this gives a blank page

Profile
 
 
Posted: 28 February 2006 03:19 PM   [ Ignore ]   [ # 16 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  06-16-2004

I wish there was a way to delete posts on this board.
Was actually my code error missing a bracket.

Actually all seems to be working and nicely!

Profile
 
 
Posted: 21 November 2006 04:17 PM   [ Ignore ]   [ # 17 ]  
Summer Student
Total Posts:  2
Joined  06-25-2006

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.

Profile
 
 
Posted: 04 September 2007 08:55 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Rank
Total Posts:  70
Joined  02-20-2006

Artlab,

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’


Any idea why?


By the way, this module is awesome!

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64549 Total Logged-in Users: 28
Total Topics: 81145 Total Anonymous Users: 19
Total Replies: 436551 Total Guests: 176
Total Posts: 517696    
Members ( View Memberlist )