diff options
author | Yorhel <git@yorhel.nl> | 2009-02-15 11:43:07 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-02-15 11:43:07 +0100 |
commit | 678b6c3089cd4372ca9e4bd48e629d46a6549c1a (patch) | |
tree | 86b91981705bed225005ca9b567d13b7042f6a36 /lib/VNDB/DB/Tags.pm | |
parent | e79211c11fa51e6978a74f6fbf0bba68a33a4f4b (diff) |
Basic adding and editing of tags
Diffstat (limited to 'lib/VNDB/DB/Tags.pm')
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm index 5d0263fb..a4dc712b 100644 --- a/lib/VNDB/DB/Tags.pm +++ b/lib/VNDB/DB/Tags.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbTagGet|; +our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd|; # %options->{ id page results order what } @@ -33,8 +33,8 @@ sub dbTagGet { \%where, $o{order} ); - if($o{what} =~ /parents/) { - $_->{parents} = $self->dbAll(q|SELECT lvl, tag, name FROM tag_tree(?, -1, false)|, $_->{id}) for (@$r); + if($o{what} =~ /parents\((\d+)\)/) { + $_->{parents} = $self->dbAll(q|SELECT lvl, tag, name FROM tag_tree(?, ?, false)|, $_->{id}, $1) for (@$r); } if($o{what} =~ /childs\((\d+)\)/) { @@ -51,5 +51,29 @@ sub dbTagGet { } +# args: tag id, %options->{ columns in the tags table + parents } +sub dbTagEdit { + my($self, $id, %o) = @_; + + $self->dbExec('UPDATE tags !H WHERE id = ?', + { map { +"$_ = ?" => $o{$_} } qw|name meta aliases description| }, $id); + $self->dbExec('DELETE FROM tags_parents WHERE tag = ?', $id); + $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); + $self->dbExec('DELETE FROM tags_vn WHERE tag = ?', $id) if $o{meta}; +} + + +# same args as dbTagEdit, without the first tag id +# returns the id of the new tag +sub dbTagAdd { + my($self, %o) = @_; + my $id = $self->dbRow('INSERT INTO tags (name, meta, aliases, description) VALUES (!l) RETURNING id', + [ map $o{$_}, qw|name meta aliases description| ] + )->{id}; + $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); + return $id; +} + + 1; |