|
Lines 191-232
This will return a list of all columns for a report area
Link Here
|
| 191 |
=cut |
191 |
=cut |
| 192 |
|
192 |
|
| 193 |
sub get_columns { |
193 |
sub get_columns { |
| 194 |
|
194 |
my ($area) = @_; |
| 195 |
# this calls the internal function _get_columns |
|
|
| 196 |
my ( $area, $cgi ) = @_; |
| 197 |
my %table_areas = get_table_areas; |
195 |
my %table_areas = get_table_areas; |
| 198 |
my $tables = $table_areas{$area} |
196 |
my $tables = $table_areas{$area} |
| 199 |
or die qq{Unsuported report area "$area"}; |
197 |
or die qq{Unsupported report area "$area"}; |
| 200 |
|
198 |
|
| 201 |
my @allcolumns; |
199 |
my $columns; |
| 202 |
my $first = 1; |
200 |
for my $table (@$tables) { |
| 203 |
foreach my $table (@$tables) { |
201 |
$columns->{$table} = _get_columns($table); |
| 204 |
my @columns = _get_columns($table,$cgi, $first); |
|
|
| 205 |
$first = 0; |
| 206 |
push @allcolumns, @columns; |
| 207 |
} |
202 |
} |
| 208 |
return ( \@allcolumns ); |
203 |
return $columns; |
| 209 |
} |
204 |
} |
| 210 |
|
205 |
|
| 211 |
sub _get_columns { |
206 |
sub _get_columns { |
| 212 |
my ($tablename,$cgi, $first) = @_; |
207 |
my ($table_name) = @_; |
| 213 |
my $dbh = C4::Context->dbh(); |
208 |
my $dbh = C4::Context->dbh(); |
| 214 |
my $sth = $dbh->prepare("show columns from $tablename"); |
209 |
my $all_columns = Koha::Database::Columns->columns; |
| 215 |
$sth->execute(); |
210 |
|
| 216 |
my @columns; |
211 |
# Sanitize input, just in case |
| 217 |
my $columns = Koha::Database::Columns->columns; |
212 |
die sprintf( 'Invalid table name %s', $table_name ) unless exists $all_columns->{$table_name}; |
| 218 |
my %tablehash; |
213 |
|
| 219 |
$tablehash{'table'}=$tablename; |
214 |
my $columns = $dbh->selectall_arrayref( sprintf( q{SHOW COLUMNS FROM %s}, $table_name ), { Slice => {} } ); |
| 220 |
$tablehash{'__first__'} = $first; |
215 |
return [ |
| 221 |
push @columns, \%tablehash; |
216 |
map { |
| 222 |
while ( my $data = $sth->fetchrow_arrayref() ) { |
217 |
my $column_name = $_->{Field}; |
| 223 |
my %temphash; |
218 |
{ |
| 224 |
$temphash{'name'} = "$tablename.$data->[0]"; |
219 |
name => sprintf( "%s.%s", $table_name, $column_name ), |
| 225 |
$temphash{'description'} = $columns->{$tablename}->{$data->[0]}; |
220 |
description => $all_columns->{$table_name}->{$column_name}, |
| 226 |
push @columns, \%temphash; |
221 |
}; |
| 227 |
} |
222 |
|
| 228 |
$sth->finish(); |
223 |
} @$columns |
| 229 |
return (@columns); |
224 |
]; |
| 230 |
} |
225 |
} |
| 231 |
|
226 |
|
| 232 |
=head2 build_query($columns,$criteria,$orderby,$area) |
227 |
=head2 build_query($columns,$criteria,$orderby,$area) |