/
db_columns.coretag
61 lines (53 loc) · 1.57 KB
/
db_columns.coretag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2002-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
UserTag db_columns Order name columns joiner passed_order
UserTag db_columns AttrAlias table name
UserTag db_columns AttrAlias fields columns
UserTag db_columns Version 1.5
UserTag db_columns Routine <<EOR
sub {
my ($table,$columns, $joiner, $passed_order) = @_;
$table = $Values->{mv_data_table}
unless $table;
my $db = Vend::Data::database_exists_ref($table)
or return undef;
my $acl = UI::Primitive::get_ui_table_acl($table);
$db = $db->ref() unless $Vend::Interpolate::Db{$table};
my $key = $db->config('KEY');
$joiner = "\n" unless defined $joiner;
my @cols;
if(! $columns || $columns =~ /^[\s,\0]*$/) {
@cols = $db->columns();
}
else {
@cols = grep /\S/, split /[\s,\0]+/, $columns;
my (@allcols) = $db->columns();
my %col;
if($passed_order) {
@col{@allcols} = @allcols;
@allcols = @cols;
my $found;
for(@cols) {
next unless $_ eq $key;
$found = 1;
last;
}
unshift (@allcols, $key) if ! $found;
}
else {
@col{@cols} = @cols;
}
$col{$key} = $key if ! defined $col{$key};
@cols = grep defined $col{$_}, @cols;
}
if($acl) {
@cols = UI::Primitive::ui_acl_grep( $acl, 'fields', @cols);
}
return @cols if wantarray;
return join $joiner, @cols;
}
EOR