@ISA = qw(Exporter);
@EXPORT = qw(
get_report_types get_report_areas get_report_groups get_columns build_query get_criteria
- save_report get_saved_reports execute_query get_saved_report
+ save_report get_saved_reports execute_query
get_column_type get_distinct_values save_dictionary get_from_dictionary
delete_definition delete_report format_results get_sql
nb_rows update_sql
my (@ids) = @_;
return unless @ids;
foreach my $id (@ids) {
- my $data = get_saved_report($id);
- logaction( "REPORTS", "DELETE", $id, "$data->{'report_name'} | $data->{'savedsql'} " ) if C4::Context->preference("ReportsLog");
+ my $data = Koha::Reports->find($id);
+ logaction( "REPORTS", "DELETE", $id, $data->report_name." | ".$data->savedsql ) if C4::Context->preference("ReportsLog");
}
my $dbh = C4::Context->dbh;
my $query = 'DELETE FROM saved_sql WHERE id IN (' . join( ',', ('?') x @ids ) . ')';
return $result;
}
-sub get_saved_report {
- my $dbh = C4::Context->dbh();
- my $query;
- my $report_arg;
- if ($#_ == 0 && ref $_[0] ne 'HASH') {
- ($report_arg) = @_;
- $query = " SELECT * FROM saved_sql WHERE id = ?";
- } elsif (ref $_[0] eq 'HASH') {
- my ($selector) = @_;
- if ($selector->{name}) {
- $query = " SELECT * FROM saved_sql WHERE report_name = ?";
- $report_arg = $selector->{name};
- } elsif ($selector->{id} || $selector->{id} eq '0') {
- $query = " SELECT * FROM saved_sql WHERE id = ?";
- $report_arg = $selector->{id};
- } else {
- return;
- }
- } else {
- return;
- }
- return $dbh->selectrow_hashref($query, undef, $report_arg);
-}
-
-
=head2 get_column_type($column)
This takes a column name of the format table.column and will return what type it is
use Modern::Perl;
use C4::Reports::Guided;
+use Koha::Reports;
use JSON;
use CGI qw ( -utf8 );
my $report_name = $query->param('name');
my $report_annotation = $query->param('annotated');
-my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
+my $report_rec = Koha::Reports->find( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
if (!$report_rec) { die "There is no such report.\n"; }
-die "Sorry this report is not public\n" unless $report_rec->{public};
+die "Sorry this report is not public\n" unless $report_rec->public;
my @sql_params = $query->param('sql_params');
unless ($json_text) {
my $offset = 0;
my $limit = C4::Context->preference("SvcMaxReportRows") || 10;
- my $sql = $report_rec->{savedsql};
+ my $sql = $report_rec->savedsql;
# convert SQL parameters to placeholders
$sql =~ s/(<<.*?>>)/\?/g;
if ($cache_active) {
$cache->set_in_cache( $cache_key, $json_text,
- { expiry => $report_rec->{cache_expiry} } );
+ { expiry => $report_rec->cache_expiry } );
}
}
else {
use File::Temp;
use File::Basename qw( dirname );
use C4::Reports::Guided;
+use Koha::Reports;
use C4::Auth qw/:DEFAULT get_session/;
use C4::Output;
use C4::Debug;
if ( $op eq 'convert' ) {
my $report_id = $input->param('report_id');
- my $report = C4::Reports::Guided::get_saved_report($report_id);
+ my $report = Koha::Reports->find($report_id);
if ($report) {
- my $updated_sql = C4::Reports::Guided::convert_sql( $report->{savedsql} );
+ my $updated_sql = C4::Reports::Guided::convert_sql( $report->savedsql );
C4::Reports::Guided::update_sql(
$report_id,
{
sql => $updated_sql,
- name => $report->{report_name},
- group => $report->{report_group},
- subgroup => $report->{report_subgroup},
- notes => $report->{notes},
- public => $report->{public},
- cache_expiry => $report->{cache_expiry},
+ name => $report->report_name,
+ group => $report->report_group,
+ subgroup => $report->report_subgroup,
+ notes => $report->notes,
+ public => $report->public,
+ cache_expiry => $report->cache_expiry,
}
);
- $template->param( report_converted => $report->{report_name} );
+ $template->param( report_converted => $report->report_name );
}
}
elsif ( $phase eq 'Show SQL'){
my $id = $input->param('reports');
- my $report = get_saved_report($id);
+ my $report = Koha::Reports->find($id);
$template->param(
'id' => $id,
- 'reportname' => $report->{report_name},
- 'notes' => $report->{notes},
- 'sql' => $report->{savedsql},
- 'showsql' => 1,
+ 'reportname' => $report->report_name,
+ 'notes' => $report->notes,
+ 'sql' => $report->savedsql,
+ 'showsql' => 1,
);
}
elsif ( $phase eq 'Edit SQL'){
my $id = $input->param('reports');
- my $report = get_saved_report($id);
- my $group = $report->{report_group};
- my $subgroup = $report->{report_subgroup};
+ my $report = Koha::Reports->find($id);
+ my $group = $report->report_group;
+ my $subgroup = $report->report_subgroup;
$template->param(
- 'sql' => $report->{savedsql},
- 'reportname' => $report->{report_name},
+ 'sql' => $report->savedsql,
+ 'reportname' => $report->report_name,
'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
- 'notes' => $report->{notes},
+ 'notes' => $report->notes,
'id' => $id,
- 'cache_expiry' => $report->{cache_expiry},
- 'public' => $report->{public},
+ 'cache_expiry' => $report->cache_expiry,
+ 'public' => $report->public,
'usecache' => $usecache,
'editsql' => 1,
);
);
my ( $sql, $original_sql, $type, $name, $notes );
- if (my $report = get_saved_report($report_id)) {
- $sql = $original_sql = $report->{savedsql};
- $name = $report->{report_name};
- $notes = $report->{notes};
+ if (my $report = Koha::Reports->find($report_id)) {
+ $sql = $original_sql = $report->savedsql;
+ $name = $report->report_name;
+ $notes = $report->notes;
my @rows = ();
# if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
# export results to tab separated text or CSV
my $report_id = $input->param('report_id');
- my $report = get_saved_report($report_id);
- my $sql = $report->{savedsql};
+ my $report = Koha::Reports->find($report_id);
+ my $sql = $report->savedsql;
my @param_names = $input->multi_param('param_name');
my @sql_params = $input->multi_param('sql_params');
my $format = $input->param('format');
use C4::Auth;
use C4::Reports::Guided;
+use Koha::Reports;
use JSON;
use CGI qw ( -utf8 );
my $report_name = $query->param('name');
my $report_annotation = $query->param('annotated');
-my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
+my $report_rec = Koha::Reports->find( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
if (!$report_rec) { die "There is no such report.\n"; }
my @sql_params = $query->param('sql_params');
unless ($json_text) {
my $offset = 0;
my $limit = C4::Context->preference("SvcMaxReportRows") || 10;
- my $sql = $report_rec->{savedsql};
+ my $sql = $report_rec->savedsql;
# convert SQL parameters to placeholders
$sql =~ s/(<<.*?>>)/\?/g;
$json_text = encode_json($lines);
if ($cache_active) {
- $cache->set_in_cache( $cache_key, $json_text, { expiry => $report_rec->{cache_expiry} } );
+ $cache->set_in_cache( $cache_key, $json_text, { expiry => $report_rec->cache_expiry } );
}
}
else {