3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Koha::DateUtils qw( dt_from_string output_pref );
27 use base qw(Koha::Object);
31 Koha::Report - Koha Report Object class
39 =head3 get_search_info
47 my $sub_mana_info = { 'query' => shift };
48 return $sub_mana_info;
51 =head3 get_sharable_info
53 Return properties that can be shared.
57 sub get_sharable_info {
59 my $shared_report_id = shift;
60 my $report = Koha::Reports->find($shared_report_id);
62 'savedsql' => $report->savedsql,
63 'report_name' => $report->report_name,
64 'notes' => $report->notes,
65 'report_group' => $report->report_group,
66 'type' => $report->type,
68 return $sub_mana_info;
73 Clear a Mana report to be imported in Koha?
81 $data->{mana_id} = $data->{id};
83 delete $data->{exportemail};
84 delete $data->{kohaversion};
85 delete $data->{creationdate};
86 delete $data->{lastimport};
88 delete $data->{nbofusers};
89 delete $data->{language};
91 Koha::Report->new($data)->store;
96 Prep the report and return executable sql with parameters embedded and a list of header types
97 for building batch action links in the template
102 my ( $self, $param_names, $sql_params ) = @_;
103 my $sql = $self->savedsql;
105 # First we split out the placeholders
106 # This part of the code supports using [[ table.field | alias ]] in the
107 # query and replaces it by table.field AS alias. This is used to build
108 # the batch action links foir cardnumbers, itemnumbers, and biblionumbers in the template
109 # while allowing the library to alter the column names
110 my @split = split /\[\[|\]\]/, $sql;
112 for ( my $i = 0 ; $i < $#split / 2 ; $i++ )
113 { #The placeholders are always the odd elements of the array
114 my ( $type, $name ) = split /\|/,
115 $split[ $i * 2 + 1 ]; # We split them on '|'
116 $headers->{$name} = $type; # Store as a lookup for the template
118 s/^\w*\.//; # strip the table name just as in $sth->{NAME} array
119 $split[ $i * 2 + 1 ] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g
120 ; #Quote any special characters so we can replace the placeholders
121 $name = C4::Context->dbh->quote($name);
122 $sql =~ s/\[\[$split[$i*2+1]\]\]/$type AS $name/
123 ; # Remove placeholders from SQL
127 @lookup{@$param_names} = @$sql_params;
128 @split = split /<<|>>/, $sql;
129 for ( my $i = 0 ; $i < $#split / 2 ; $i++ ) {
131 @$param_names ? $lookup{ $split[ $i * 2 + 1 ] } : @$sql_params[$i];
133 # if there are special regexp chars, we must \ them
134 $split[ $i * 2 + 1 ] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
135 if ( $split[ $i * 2 + 1 ] =~ /\|\s*date\s*$/ ) {
136 $quoted = output_pref(
138 dt => dt_from_string($quoted),
144 unless ( $split[ $i * 2 + 1 ] =~ /\|\s*list\s*$/ && $quoted ) {
145 $quoted = C4::Context->dbh->quote($quoted);
148 my @list = split /\n/, $quoted;
150 foreach my $item (@list) {
152 push @quoted_list, C4::Context->dbh->quote($item);
154 $quoted = "(" . join( ",", @quoted_list ) . ")";
156 $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
158 return $sql, $headers;
163 Returns name of corresponding DBIC resultset