Gossamer Forum
Quote Reply
Payment links globals
Hello

Does anyone know of a global that will allow us to display a list of all Links with a Paid status, and a global that will rotate a 2 random links from these links?

We have tried the following for the first one:

sub {
# Displays the partners links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Title ASC Limit 250')|| return $GT::SQL::error;
$sth = $search_db->select ( {ExpiryDate '!=" '2147483647'})|| return $GT::SQL::error;
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_short', $link);
}
return $output;
}

and tried

sub {
# Displays the featured links on the home page.
my $db = $DB->table('Links');
my $cond = GT::SQL::Condition->new('ExpiryDate', '!=', '2147483647');
my $total = $db->count ( $cond );
my $rand = int rand $total;
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select($cond)->fetchrow_hashref;
return Links::SiteHTML::display('link_short', $link);
}

for the second one..

Any ideas?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Payment links globals In reply to
First of all, you should use the payment constants (UNPAID, UNLIMITED, FREE). Second, you should use VIEWABLE (to make sure you only display non-expired, and validated links).

$DB->table('Links')->select(GT::SQL::Condition->new(ExpiryDate => '<' => FREE), VIEWABLE);

Third, it's usually more flexible if your globals return data that can be used in the template rather than to return HTML. So return { paid_links => \@array_of_paid_links }; and looping through it in the templates. Either way works, but it's a little nicer to not return html.

Adrian
Quote Reply
Re: [brewt] Payment links globals In reply to
Hello again

I have tried this but it does not seem to work..

sub {
# Displays the featured links on the home page.
my $db = $DB->table('Links');
my $cond = GT::SQL::Condition->new(ExpiryDate => '<' => time);
my $total = $db->count ( $cond );
my $rand = int rand $total;
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select($cond)->fetchrow_hashref;
return Links::SiteHTML::display('link', $link);
}

We are not getting any links to display, it parses the links template itself.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory