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

Show random paid link

(Page 2 of 2)
> >
Quote Reply
Re: [Piers1] Show random paid link In reply to
OK, took a while to work out why it wasn't working - but found some errors in the globals (also, you're using an old version of LSQL [2.1], so had a few tag issues =))

The final codes are:

random_paid_in_category

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY RAND() DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/Detailed/$hit->{ID}" }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

push @links, $hit;
}

return { random_link => \@links }

}

check_if_paid_exists

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);

# my $sth = $DB->table('Links','CatLinks','Category')->select ( $cond, $cond2 ) || die $GT::SQL::error;

# return $sth->query;

my $count = $DB->table('Links','CatLinks','Category')->count ( $cond, $cond2 ) || 0;

return { num_paid_found => $count }

}

..and the template code (category.html);

Code:
<%check_if_paid_exists($category_id)%>

<%if num_paid_found > 0%>
<%random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include include_paid_link.html%>
<%endloop%>
<%endif%>
<%endif%>

Tested, and its all working as its mean't to now :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Show random paid link In reply to
.....oh Andy...

I agree this does work, but it only shows one paid link. Is it easy to show ALL of the paid links in the category but still retain the random display order?
I thought this was what the loop random_link did, but it only ever returns one random record, even when there is more then one paid link.

Sorry the pain continues,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Sorry - thought you only wanted one =)

Try it now (I just removed LIMIT 1) =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Show random paid link In reply to
Andy,

I think your time on this one is truly done.....

Thank you so much - it all works as I wanted,

Best wishes,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Glad it works Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Show random paid link In reply to
Andy,

I have upgraded my test site to Linksql 3.2.0 and of course want the random paid link to work once more!

One major difference - I now only have one type of link.html template (as I can do the paid formatting using the "isPaidLink" tag) called by category.html

I have used the same globals as before and inserted the code into category.html, but am a little stuck.

I get correctly showing random paid links (but they ignore the "isPaidLink" tag for the fancy formatting), and then I get the paid links ordered alphabetically with fancy formatting. Not quite sure how to move forward, but it is very close already.
Here is the relevant bit from my category.html template;
Code:
<%if links_loop.length~%>
<h3>Links</h3>
<%if paging.num_hits%><div class="paging"><%Links::Utils::paging()%></div><%endif%>

<%-- Start of Random Paid Links --%>
<%check_if_paid_exists($category_id)%>
<%if num_paid_found > 0%>
<%random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include link.html%>
<%endloop%>
<%endif%>
<%endif%>
<%-- End of Random Paid Links --%>

<%loop links_loop~%>
<%include link.html%>
<%~endloop%>
This is a sample category from the test site which shows the problem;
Sample Category from test site

Could you take a look? - It would be much appreciated,

Best wishes,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

So whats not working - the isPaidLink tag is not being passed in, or am I mis-understanding the problem?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Show random paid link In reply to
Hi there,

Two problems;

1) I am seeing two lots of the paid links displayed in my categories. The first lot comes from your random global, and the second lot comes as standard.
How do I only display the paid links from your global, but still show the non paid links below them?

2) Some tags from your global are not being passed in;
isPaidLink
and if you own the link the 'Edit this Link', 'Renewal Payment' are also missing.

Cheers,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Please try this (for the second problem);

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY RAND() DESC LIMIT 10');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/Detailed/$hit->{ID}" }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

$hit->{isPaidLink} = 1;
$hit->{paymentsEnabled} = 1;

if ($hit->{LinkOwner} eq $USER->{Username}) {
$hit->{isLinkOwner} = 1;
}


push @links, $hit;
}

return { random_link => \@links }

}

...the first problem, I'm not sure there is a lot you can really do for that :(

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Aug 25, 2008, 3:39 AM
Quote Reply
Re: [Andy] Show random paid link In reply to
Almost....
I think I still need these tags to be passed through;

paymentsEnabled
isLinkOwner
isExpired
isUnpaid
wasPaid

However unless I can filter out the second display of paid links, then I have to stop using the whole global (which would be a pity as then random display of paid links has been requested by my users several times).

Cheers,
Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Regarding paymentsEnabled and isLinkOwner - try the modified version below.

Quote:
However unless I can filter out the second display of paid links, then I have to stop using the whole global (which would be a pity as then random display of paid links has been requested by my users several times).

So basically, you are on category.html - and you want to show this globals, BUT stop any of these ones, from showing up? There is a way of doing it - but it may add a lot more work for your server :/ (and, also it will mean that one or more links will be missed out - so instead of say showing 25 on the page, it may only show 20 - if there were 5 paid links on that page)

Code:
<%loop links_loop%>
<%set hasbeenshown = 0%>
<%loop random_link%>
<%if SavedID eq $ID%><%set hasbeenshown = 1%><%endif%>
<%endloop%>

<%if not hasbeenshown%>
<%include link.html%>
<%endif%>

<%endloop%>

..with this global:

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY RAND() DESC LIMIT 10');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/Detailed/$hit->{ID}" }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

$hit->{isPaidLink} = 1;
$hit->{paymentsEnabled} = 1;
$hit->{SavedID} = $hit->{ID}; # need to do this, otherwise cos of doing more than one loop of links - the ID will just get overwritten
if ($hit->{LinkOwner} eq $USER->{Username}) {
$hit->{isLinkOwner} = 1;
}


push @links, $hit;
}

return { random_link => \@links }

}

NB - not tested - so may not work Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Show random paid link In reply to
Andy,

1) The new category.html template code, results in just the standard links display without any random sorting of the paid links.

2) When logged in, ALL links in the Random Loop, I get offered the option to 'Sponsor Your Link' even for Links I don't own. The 'Edit Link' button does work correctly, so almost there.

Apologies - this is getting more involved then I expected.

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

For anyone intersted, heres how I did it:

redotheloop
Code:
sub {

my $random_loop = $_[0];
my $link_loop = $_[1];

my $ran_loop_ids;

foreach (@$random_loop) {
$ran_loop_ids->{$_->{ID}} = 1;
}

my @newlinks;
foreach (@$link_loop) {

if ($ran_loop_ids->{$_->{ID}}) {
# looks like this links in the random list - so ignore
} else {
push @newlinks, $_;
}
}

return { links_loop => \@newlinks }

}
..just add this into category.html:

Code:
<%redotheloop($random_link,$links_loop)%>

..just before the:

Code:
<%loop links_loop%>

..bit.

This basically weeds out the links that already exist in the priority listing stuff - thus they don't show 2 times =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
> >