summaryrefslogtreecommitdiff
path: root/lib/VNWeb/DB.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-08 18:16:46 +0200
committerYorhel <git@yorhel.nl>2019-10-10 16:40:30 +0200
commitb3a9130763879d60c0e413c724a759860bd396af (patch)
tree2de6f9d21d4ce9f00fc11595906570be43d8ae5c /lib/VNWeb/DB.pm
parent4c1dfc8bb62171c4c21057c47f238c8747bac3f8 (diff)
rewards: Apply supporters badge and unicode name (almost) everywhere
Only place where this isn't applied (yet?): Sorting user lists still goes by the old username and board names don't use the new unicode names. I have to say, I quite like the sql_user() and user_() pattern. It's not without problems when applied to everything, but it's good enough for several use cases.
Diffstat (limited to 'lib/VNWeb/DB.pm')
-rw-r--r--lib/VNWeb/DB.pm17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/VNWeb/DB.pm b/lib/VNWeb/DB.pm
index 0d5616e0..8b63c167 100644
--- a/lib/VNWeb/DB.pm
+++ b/lib/VNWeb/DB.pm
@@ -10,7 +10,7 @@ use VNDB::Schema;
our @EXPORT = qw/
sql
- sql_join sql_comma sql_and sql_or sql_array sql_func sql_fromhex sql_tohex sql_fromtime sql_totime
+ sql_join sql_comma sql_and sql_or sql_array sql_func sql_fromhex sql_tohex sql_fromtime sql_totime sql_user
enrich enrich_merge enrich_flatten
db_entry db_edit
/;
@@ -88,6 +88,21 @@ sub sql_totime($) {
sql "extract('epoch' from ", $_[0], ')';
}
+# Returns a list of column names to fetch for displaying a username with HTML::user_().
+# Arguments: Name of the 'users' table (default: 'u'), prefix for the fetched fields (default: 'user_').
+# (This function returns a plain string so that old non-SQL-Interp functions can also use it)
+sub sql_user {
+ my $tbl = shift||'u';
+ my $prefix = shift||'user_';
+ join ', ',
+ "$tbl.id as ${prefix}id",
+ "$tbl.username as ${prefix}name",
+ "$tbl.support_can as ${prefix}support_can",
+ "$tbl.support_enabled as ${prefix}support_enabled",
+ "$tbl.uniname_can as ${prefix}uniname_can",
+ "$tbl.uniname as ${prefix}uniname";
+}
+