summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-11-10 21:01:14 +0100
committerYorhel <git@yorhel.nl>2010-11-10 21:04:37 +0100
commit15808bc64c7717c0a157c24ee9bfd0a097daf707 (patch)
treecc8782101c744ae43f6f9e2529ce85582c892600 /lib
parent134ebe506dc37073b474a83a5c3a3ab33fa411a1 (diff)
Started on adding an "official" flag to vn<->vn relations
This is the first part. The flag is stored in the database, can be edited through the usual VN edit form, and is displayed in the diff viewer. Things to do to make this feature fully functional: - display "official" status on VN page at the relation listing - update relation graphs to display unofficial relations differently - update guidelines
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/VN.pm11
-rw-r--r--lib/VNDB/Handler/VNEdit.pm20
-rw-r--r--lib/VNDB/Handler/VNPage.pm3
3 files changed, 19 insertions, 15 deletions
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 0088d18f..6d99ba8a 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -125,11 +125,12 @@ sub dbVNGet {
if($o{what} =~ /relations/) {
push(@{$r->[$r{$_->{vid1}}]{relations}}, {
relation => $_->{relation},
+ official => $_->{official},
id => $_->{vid2},
title => $_->{title},
- original => $_->{original}
+ original => $_->{original},
}) for(@{$self->dbAll(q|
- SELECT rel.vid1, rel.vid2, rel.relation, vr.title, vr.original
+ SELECT rel.vid1, rel.vid2, rel.relation, rel.official, vr.title, vr.original
FROM vn_relations rel
JOIN vn v ON rel.vid2 = v.id
JOIN vn_rev vr ON v.latest = vr.id
@@ -176,9 +177,9 @@ sub dbVNRevisionInsert {
if($o->{relations}) {
$self->dbExec('DELETE FROM edit_vn_relations');
- my $q = join ',', map '(?, ?)', @{$o->{relations}};
- my @val = map +($_->[1], $_->[0]), @{$o->{relations}};
- $self->dbExec("INSERT INTO edit_vn_relations (vid, relation) VALUES $q", @val) if @val;
+ my $q = join ',', map '(?, ?, ?)', @{$o->{relations}};
+ my @val = map +($_->[1], $_->[0], $_->[2]?1:0), @{$o->{relations}};
+ $self->dbExec("INSERT INTO edit_vn_relations (vid, relation, official) VALUES $q", @val) if @val;
}
if($o->{anime}) {
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index bfc37e02..122b432e 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -30,7 +30,7 @@ sub edit {
my %b4 = !$vid ? () : (
(map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai l_vnn img_nsfw ihid ilock|),
anime => join(' ', sort { $a <=> $b } map $_->{id}, @{$v->{anime}}),
- vnrelations => join('|||', map $_->{relation}.','.$_->{id}.','.$_->{title}, sort { $a->{id} <=> $b->{id} } @{$v->{relations}}),
+ vnrelations => join('|||', map $_->{relation}.','.$_->{id}.','.($_->{official}?1:0).','.$_->{title}, sort { $a->{id} <=> $b->{id} } @{$v->{relations}}),
screenshots => join(' ', map sprintf('%d,%d,%d', $_->{id}, $_->{nsfw}?1:0, $_->{rid}), @{$v->{screenshots}}),
);
@@ -62,14 +62,14 @@ sub edit {
if(!$frm->{_err}) {
# parse and re-sort fields that have multiple representations of the same information
my $anime = { map +($_=>1), grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} };
- my $relations = [ map { /^([a-z]+),([0-9]+),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3 ] : () } split /\|\|\|/, $frm->{vnrelations} ];
+ my $relations = [ map { /^([a-z]+),([0-9]+),([01]),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3, $4 ] : () } split /\|\|\|/, $frm->{vnrelations} ];
my $screenshots = [ map /^[0-9]+,[01],[0-9]+$/ ? [split /,/] : (), split / +/, $frm->{screenshots} ];
$frm->{ihid} = $frm->{ihid}?1:0;
$frm->{ilock} = $frm->{ilock}?1:0;
$relations = [] if $frm->{ihid};
$frm->{anime} = join ' ', sort { $a <=> $b } keys %$anime;
- $frm->{vnrelations} = join '|||', map $_->[0].','.$_->[1].','.$_->[2], sort { $a->[1] <=> $b->[1]} @{$relations};
+ $frm->{vnrelations} = join '|||', map $_->[0].','.$_->[1].','.($_->[2]?1:0).','.$_->[3], sort { $a->[1] <=> $b->[1]} @{$relations};
$frm->{img_nsfw} = $frm->{img_nsfw} ? 1 : 0;
$frm->{screenshots} = join ' ', map sprintf('%d,%d,%d', $_->[0], $_->[1]?1:0, $_->[2]), sort { $a->[0] <=> $b->[0] } @$screenshots;
@@ -96,8 +96,8 @@ sub edit {
# update reverse relations & relation graph
if(!$vid && $#$relations >= 0 || $vid && $frm->{vnrelations} ne $b4{vnrelations}) {
- my %old = $vid ? (map { $_->{id} => $_->{relation} } @{$v->{relations}}) : ();
- my %new = map { $_->[1] => $_->[0] } @$relations;
+ my %old = $vid ? (map +($_->{id} => [ $_->{relation}, $_->{official} ]), @{$v->{relations}}) : ();
+ my %new = map +($_->[1] => [ $_->[0], $_->[2] ]), @$relations;
_updreverse($self, \%old, \%new, $nrev->{iid}, $nrev->{rev});
}
@@ -211,6 +211,8 @@ sub _form {
end;
td class => 'tc_rel';
txt mt('_vnedit_rel_isa').' ';
+ input type => 'checkbox', id => 'official', checked => 'checked';
+ label for => 'official', mt '_vnedit_rel_official';
Select;
option value => $_, mt "_vnrel_$_"
for (sort { $self->{vn_relations}{$a}[0] <=> $self->{vn_relations}{$b}[0] } keys %{$self->{vn_relations}});
@@ -250,7 +252,7 @@ sub _form {
# Update reverse relations and regenerate relation graph
# Arguments: %old. %new, vid, rev
-# %old,%new -> { vid2 => relation, .. }
+# %old,%new -> { vid2 => [ relation, official ], .. }
# from the perspective of vid
# rev is of the related edit
sub _updreverse {
@@ -261,8 +263,8 @@ sub _updreverse {
for (keys %$old, keys %$new) {
if(exists $$old{$_} and !exists $$new{$_}) {
$upd{$_} = undef;
- } elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_} ne $$new{$_})) {
- $upd{$_} = $self->{vn_relations}{$$new{$_}}[1];
+ } elsif((!exists $$old{$_} and exists $$new{$_}) || ($$old{$_}[0] ne $$new{$_}[0] || !$$old{$_}[1] != !$$new{$_}[1])) {
+ $upd{$_} = [ $self->{vn_relations}{ $$new{$_}[0] }[1], $$new{$_}[1] ];
}
}
return if !keys %upd;
@@ -271,7 +273,7 @@ sub _updreverse {
for my $i (keys %upd) {
my $r = $self->dbVNGet(id => $i, what => 'relations')->[0];
my @newrel = map $_->{id} != $vid ? [ $_->{relation}, $_->{id} ] : (), @{$r->{relations}};
- push @newrel, [ $upd{$i}, $vid ] if $upd{$i};
+ push @newrel, [ $upd{$i}[0], $vid, $upd{$i}[1] ] if $upd{$i};
$self->dbItemEdit(v => $r->{cid},
relations => \@newrel,
editsum => "Reverse relation update caused by revision v$vid.$rev",
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 0dff5627..32188e00 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -204,7 +204,8 @@ sub _revision {
$_[0] ? sprintf '<a href="http://renai.us/game/%s.shtml">%1$s</a>', xml_escape $_[0] : mt '_revision_nolink'
}],
[ relations => join => '<br />', split => sub {
- my @r = map sprintf('%s: <a href="/v%d" title="%s">%s</a>',
+ my @r = map sprintf('[%s] %s: <a href="/v%d" title="%s">%s</a>',
+ mt($_->{official} ? '_vndiff_rel_official' : '_vndiff_rel_unofficial'),
mt("_vnrel_$_->{relation}"), $_->{id}, xml_escape($_->{original}||$_->{title}), xml_escape shorten $_->{title}, 40
), sort { $a->{id} <=> $b->{id} } @{$_[0]};
return @r ? @r : (mt '_revision_empty');