Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Review Duplicate - in global

Quote Reply
Review Duplicate - in global
Hi,

I have this global to diplay the latest links that have a new review. The only issue is a link that has more than one review is duplicated on the output thus:

Good Food - Peter
Good Food - Harry
Best Computers - John

I really wanted:

Good Food - Peter
Best Computers - John

as peter was the latest review added.

Any help really appreciated!


sub {
my (@links,$sth,$link);
my $search_db = $DB->table('Links','Reviews');
$search_db->select_options ("ORDER BY Review_Date DESC","LIMIT $_[0]");
$sth = $search_db->select ( { Review_Validated => 'Yes' });
while (my $link = $sth->fetchrow_hashref()) {
if (length $link->{Title} > 50) {
$link->{Title} = substr($link->{Title}, 0, 50) . '...'; }
$link = Links::SiteHTML::tags('link', $link);
push@links, $link;
}
return {LatestRevs=>\@links};
}


<%Latest_Revs(15)%>
<%loop LatestRevs%>
<a href="<%detailed_url%>"><%Title%></a> - <%Review_GuestName%><br/>
<%endloop%>

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Review Duplicate - in global In reply to
Untested:

$sth = $search_db->select ( ['Distinct Review_LinkID'],{ Review_Validated => 'Yes' });

You may also need to add Links.* and Reviews.* to get all the fields.
Quote Reply
Re: [afinlr] Review Duplicate - in global In reply to
Many thanks for the code.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Review Duplicate - in global In reply to
This is a great global. I've been looking for something like this for ages - why is it not in the resource section???

Anyway, to my query. I have created a seperate page template ( latest_reviews.html ) and have used the global loop on it. In the Reviews database tables I have added <%Title%> so on the Latest Reviews page I now have a list that consists of Link Title, Reviewers Name and Reviewers Rating. I would like to add the Review Date to this list but I am not getting the same date format as on the reviews page.

On the actual review page the date displays as 16 Jan 2006

On my latest_reviews page it displays as 2006-01-16

I am using <%Review_Date%> on both of these pages so why is the output different?

A little long winded I know but thanks.
Quote Reply
Re: [MJB] Review Duplicate - in global In reply to
On the reviews page the output comes from Review.pm which does a lot of stuff Wink.

To show the date in the same format you need to use something like this in your global:
$review->{Review_Date} = GT::Date::date_transform($review->{Review_Date}, $CFG->{date_db_format},$CFG->{date_user_format});

Alternatively, I think you can do this with a tag on the page (untested):

<%GT::Date::date_transform($Review_Date, $cfg.date_db_format,$cfg.date_user_format)%>
Quote Reply
Re: [afinlr] Review Duplicate - in global In reply to
Can't get either of those to work.
Quote Reply
Re: [MJB] Review Duplicate - in global In reply to
Sorry, the tag should have config instead of cfg.

And the global line should be $link->{Review_Date} and obviously not $review - I must take longer to reply in future and reread what I've written!
Quote Reply
Re: [afinlr] Review Duplicate - in global In reply to
Brilliant! Works a treat.

So to clear this up if anyone else wants to add the review date to the global:

Add to global:
Code:
$link->{Review_Date} = GT::Date::date_transform($link->{Review_Date}, $CFG->{date_db_format}, $CFG->{date_user_format});

and add to template:
Code:
<%GT::Date::date_transform($Review_Date, $config.date_db_format,$config.date_user_format)%>

Thanks afinlr.