Koha/svc/report
Srdjan 42acfbf75b Bug 7993: Save reports with Group/Subgroup hierarchy
This should make saved reports more manageable.
Group/Subgroup hierarchy is stored in authorised_values,
categories REPORT_GROUP and REPORT_SUBGROUP, connected by
REPORT_SUBGROUP.lib_opac -> REPORT_GROUP.authorised_value

Database changes:
* authorised_values: expanded category to 16 chars
* created default set of REPORT_GROUP authorised values to match
  hardcoded report areas
* reports_dictionary: replaced area int with report_area text, converted
  values
* saved_sql: added report_area, report_group and report_subgroup;
  report_area is not currently used, saved for the record

C4/Reports/Guided.pm:
* Replaced Area numeric values with the mnemonic codes
* get_report_areas(): returns hardcoded areas list
* created get_report_areas(): returns full hierarchy (groups with belonging
  subgroups)
* save_report(): changed iterface, accepts fields hashref as input
* update_sql(): changed iterface, accepts id and fields hashref as input
* get_saved_reports():]
- join to authorised_values to pick group and subgroup name
- accept group and subgroup filter params
* get_saved_report():
- changed iterface, return record hashref
- join to authorised_values to pick group and subgroup name
* build_authorised_value_list(): new sub, moved code from
  reports/guided_reports.pl
* Updated interfaces in:
cronjobs/runreport.pl, svc/report, opac/svc/report: get_saved_report()
reports/dictionary.pl: get_report_areas()
reports/guided_reports.pl

reports/guided_reports_start.tt:
* Reports list:
- added group/subgroup filter
- display area/group/subgroup for the reports
* Create report wizard:
- carry area to the end
- select group and subgroup when saving the report; group defaults to area,
  useful when report groups match areas
* Update report and Create from SQL: added group/subgroup
* Amended reports/guided_reports.pl accordingly

Conflicts:

    C4/Reports/Guided.pm
    admin/authorised_values.pl
    installer/data/mysql/kohastructure.sql
    installer/data/mysql/updatedatabase.pl
    koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl
    koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
    misc/cronjobs/runreport.pl
    reports/dictionary.pl
    reports/guided_reports.pl

Signed-off-by: Delaye Stephane <stephane.delaye@biblibre.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
2012-09-18 17:49:08 +02:00

73 lines
2.2 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2011 Chris Cormack <chris@bigballofwax.co.nz>
#
# This file is part of Koha.
#
# Koha 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.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
use strict;
use warnings;
use C4::Auth;
use C4::Reports::Guided;
use JSON;
use CGI;
use Koha::Cache;
my $query = CGI->new();
my $report_id = $query->param('id');
my $report_name = $query->param('name');
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "intranet-main.tmpl",
query => $query,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1, },
}
);
my $cache_active = Koha::Cache->is_cache_active;
my ($cache_key, $cache, $json_text);
if ($cache_active) {
$cache_key = "intranet:report:".($report_name ? "name:$report_name" : "id:$report_id");
$cache = Koha::Cache->new();
$json_text = $cache->get_from_cache($cache_key);
}
unless ($json_text) {
my $report_rec = get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id });
my $offset = 0;
my $limit = C4::Context->preference("SvcMaxReportRows") || 10;
my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit );
if ($sth) {
my $lines = $sth->fetchall_arrayref;
$json_text = to_json($lines);
if ($cache_active) {
$cache->set_in_cache( $cache_key, $json_text, $report_rec->{cache_expiry} );
}
}
else {
$json_text = to_json($errors);
}
}
print $query->header;
print $json_text;