summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Affiliates.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-04-29 12:11:28 +0200
committerYorhel <git@yorhel.nl>2011-04-29 12:11:28 +0200
commit67afab5bfa32662f53699eb2fe37a9adec86a1ab (patch)
treef683ad9819a7249aed7b715cb22b6c79eb18b39c /lib/VNDB/DB/Affiliates.pm
parentd1937fbfbc4996a524fe1649c081d9a486a34ab7 (diff)
affiliates: +data column, hide hidden links, better browser, Multi fixes
Diffstat (limited to 'lib/VNDB/DB/Affiliates.pm')
-rw-r--r--lib/VNDB/DB/Affiliates.pm23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/VNDB/DB/Affiliates.pm b/lib/VNDB/DB/Affiliates.pm
index 2aa891ce..51320b47 100644
--- a/lib/VNDB/DB/Affiliates.pm
+++ b/lib/VNDB/DB/Affiliates.pm
@@ -9,23 +9,38 @@ use Exporter 'import';
our @EXPORT = qw|dbAffiliateGet dbAffiliateEdit dbAffiliateDel dbAffiliateAdd|;
-# options: id rids affiliate hide_hidden
+# options: id rids affiliate hidden sort reverse
# what: release
sub dbAffiliateGet {
my($self, %o) = @_;
+ $o{sort} ||= 'id';
+ $o{reverse} //= 0;
my %where = (
$o{id} ? ('id = ?' => $o{id}) : (),
$o{rids} ? ('rid IN(!l)' => [$o{rids}]) : (),
defined($o{affiliate}) ? ('affiliate = ?' => $o{affiliate}) : (),
- $o{hide_hidden} ? ('NOT hidden' => 1) : (),
+ defined($o{hidden}) ? ('!s af.hidden' => $o{hidden} ? '' : 'NOT') : (),
);
my $join = $o{what} ? 'JOIN releases r ON r.id = af.rid JOIN releases_rev rr ON rr.id = r.latest' : '';
my $select = $o{what} ? ', rr.title' : '';
- return $self->dbAll("SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version, extract('epoch' from af.lastfetch) as lastfetch, af.price$select
- FROM affiliate_links af $join !W", \%where);
+ my $order = sprintf {
+ id => 'af.id %s',
+ rel => 'rr.title %s',
+ prio => 'af.priority %s',
+ url => 'af.url %s',
+ lastfetch => 'af.lastfetch %s',
+ }->{$o{sort}}, $o{reverse} ? 'DESC' : 'ASC';
+
+ return $self->dbAll(qq|
+ SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version,
+ extract('epoch' from af.lastfetch) as lastfetch, af.price$select
+ FROM affiliate_links af
+ $join
+ !W
+ ORDER BY !s|, \%where, $order);
}