diff options
author | Yorhel <git@yorhel.nl> | 2020-07-25 14:03:37 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-07-25 14:03:37 +0200 |
commit | 025ab84a962f3c61fd4217f1518ef4928bf72bf3 (patch) | |
tree | 3c553ead5033006e51736922720af2f41568d8c7 /lib/VNWeb/Prelude.pm | |
parent | 40ea78ddfa265daea03f9904784bc0c35980b894 (diff) |
Reports: Allow reporting DB entries
Diffstat (limited to 'lib/VNWeb/Prelude.pm')
-rw-r--r-- | lib/VNWeb/Prelude.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/VNWeb/Prelude.pm b/lib/VNWeb/Prelude.pm index c79cc09b..50906792 100644 --- a/lib/VNWeb/Prelude.pm +++ b/lib/VNWeb/Prelude.pm @@ -72,6 +72,7 @@ sub import { *{$c.'::RE'} = *RE; *{$c.'::in'} = \∈ *{$c.'::idcmp'} = \&idcmp; + *{$c.'::dbobj'} = \&dbobj; } @@ -122,4 +123,26 @@ sub idcmp($$) { $a1 cmp $b1 || $a2 <=> $b2 } + +# Returns very generic information on a DB entry object. +# Only { id, title, entry_hidden, entry_locked } for now. +# Suitable for passing to HTML::framework_'s dbobj argument. +sub dbobj { + my($type, $id) = @_; + + my sub item { + my($table, $title) = @_; + tuwf->dbRowi('SELECT id,', $title, ' AS title, hidden AS entry_hidden, locked AS entry_locked FROM', $table, 'WHERE id =', \$id); + }; + + !$type ? undef : + $type eq 'u' ? tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \$id) : + $type eq 'p' ? item producers => 'name' : + $type eq 'v' ? item vn => 'title' : + $type eq 'r' ? item releases => 'title' : + $type eq 'c' ? item chars => 'name' : + $type eq 's' ? item staff => '(SELECT name FROM staff_alias WHERE aid = staff.aid)' : + $type eq 'd' ? item docs => 'title' : die; +} + 1; |