summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Chars.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-02-21 10:19:48 +0100
committerYorhel <git@yorhel.nl>2011-02-21 10:19:48 +0100
commitacdbb717bb426d237efb7195fc8658eee64d107b (patch)
tree14c59ff7491b4b077baeb5dd4dde05341ddaff43 /lib/VNDB/DB/Chars.pm
parent0d8e97158208681c63d934e0c75472d8f5eb11c8 (diff)
chardb: char-by-trait lookup + trait usage count + tag-code sharing
I'll have to optimize the updating of traits_chars as soon as I have some data to test with. Also renamed tags.c_vns to c_items, to have it share the same name as traits.c_items. This makes it a lot easier to re-use code for both tags and traits, such as what I did with dbTagTree/dbTraitTree -> dbTTTree and the childtags() and parenttags() functions.
Diffstat (limited to 'lib/VNDB/DB/Chars.pm')
-rw-r--r--lib/VNDB/DB/Chars.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
index e1f045a7..22ddd5d5 100644
--- a/lib/VNDB/DB/Chars.pm
+++ b/lib/VNDB/DB/Chars.pm
@@ -8,7 +8,7 @@ use Exporter 'import';
our @EXPORT = qw|dbCharGet dbCharRevisionInsert dbCharImageId|;
-# options: id rev what results page
+# options: id rev traitspoil trait_inc trait_exc what results page
# what: extended traits changes
sub dbCharGet {
my $self = shift;
@@ -16,6 +16,7 @@ sub dbCharGet {
page => 1,
results => 10,
what => '',
+ traitspoil => 0,
@_
);
@@ -23,6 +24,11 @@ sub dbCharGet {
!$o{id} && !$o{rev} ? ( 'c.hidden = FALSE' => 1 ) : (),
$o{id} ? ( 'c.id = ?' => $o{id} ) : (),
$o{rev} ? ( 'h.rev = ?' => $o{rev} ) : (),
+ $o{trait_inc} ? (
+ 'c.id IN(SELECT cid FROM traits_chars WHERE tid IN(!l) AND spoil <= ? GROUP BY cid HAVING COUNT(tid) = ?)',
+ [ ref $o{trait_inc} ? $o{trait_inc} : [$o{trait_inc}], $o{traitspoil}, ref $o{trait_inc} ? $#{$o{trait_inc}}+1 : 1 ]) : (),
+ $o{trait_exc} ? (
+ 'c.id NOT IN(SELECT cid FROM traits_chars WHERE tid IN(!l))' => [ ref $o{trait_exc} ? $o{trait_exc} : [$o{trait_exc}] ] ) : (),
);
my @select = (qw|c.id cr.name cr.original|, 'cr.id AS cid');