diff options
author | Yorhel <git@yorhel.nl> | 2009-10-21 11:30:24 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-10-21 11:33:46 +0200 |
commit | 06a2e823c738a622625dce599fa19580714834a5 (patch) | |
tree | bfa0da620c11812b1289543127567f0445b6e18b /lib/VNDB/DB/Producers.pm | |
parent | 815ed4023dea8c3a4168bc6826a7e9515631dab8 (diff) |
Started on the producer relations
The current list of relations isn't final yet, may be changed later on.
Quite a bit of this code has been copied from the VN relations... need
to find a way to use prober code reuse here.
TODO:
- Nice relation editor interface
- Display relations in revision browser
- Display relations on producer pages
- Generate relation graphs
- Sync update_2.8.sql into dump.sql
Diffstat (limited to 'lib/VNDB/DB/Producers.pm')
-rw-r--r-- | lib/VNDB/DB/Producers.pm | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm index afc21492..c28d12d7 100644 --- a/lib/VNDB/DB/Producers.pm +++ b/lib/VNDB/DB/Producers.pm @@ -9,7 +9,7 @@ our @EXPORT = qw|dbProducerGet dbProducerEdit dbProducerAdd|; # options: results, page, id, search, char, rev -# what: extended, changes, vn +# what: extended, changes, vn, relations sub dbProducerGet { my $self = shift; my %o = ( @@ -41,7 +41,7 @@ sub dbProducerGet { push @join, 'JOIN changes c ON c.id = pr.id' if $o{what} =~ /changes/ || $o{rev}; push @join, 'JOIN users u ON u.id = c.requester' if $o{what} =~ /changes/; - my $select = 'p.id, pr.type, pr.name, pr.original, pr.lang'; + my $select = 'p.id, pr.type, pr.name, pr.original, pr.lang, pr.id AS cid'; $select .= ', pr.desc, pr.alias, pr.website, p.hidden, p.locked' if $o{what} =~ /extended/; $select .= q|, extract('epoch' from c.added) as added, c.requester, c.comments, p.latest, pr.id AS cid, u.username, c.rev| if $o{what} =~ /changes/; @@ -78,6 +78,22 @@ sub dbProducerGet { )}); } + if(@$r && $o{what} =~ /relations/) { + my %r = map { + $r->[$_]{relations} = []; + ($r->[$_]{cid}, $_) + } 0..$#$r; + + push @{$r->[$r{$_->{pid1}}]{relations}}, $_ for(@{$self->dbAll(q| + SELECT rel.pid1, rel.pid2 AS id, rel.relation, pr.name, pr.original + FROM producers_relations rel + JOIN producers p ON rel.pid2 = p.id + JOIN producers_rev pr ON p.latest = pr.id + WHERE rel.pid1 IN(!l)|, + [ keys %r ] + )}); + } + return wantarray ? ($r, $np) : $r; } @@ -103,7 +119,7 @@ sub dbProducerAdd { # helper function, inserts a producer revision -# Arguments: global revision, item id, { columns in producers_rev } +# Arguments: global revision, item id, { columns in producers_rev }, relations sub insert_rev { my($self, $cid, $pid, $o) = @_; $self->dbExec(q| @@ -111,6 +127,12 @@ sub insert_rev { VALUES (!l)|, [ $cid, $pid, @$o{qw| name original website type lang desc alias|} ] ); + + $self->dbExec(q| + INSERT INTO producers_relations (pid1, pid2, relation) + VALUES (?, ?, ?)|, + $cid, $_->[1], $_->[0] + ) for (@{$o->{relations}}); } |