View | Details | Raw Unified | Return to bug 8628
Collapse All | Expand All

(-)a/Koha/Schema/Result/SavedSql.pm (-2 / +19 lines)
Lines 162-170 __PACKAGE__->add_columns( Link Here
162
162
163
__PACKAGE__->set_primary_key("id");
163
__PACKAGE__->set_primary_key("id");
164
164
165
=head1 RELATIONS
165
166
166
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54
167
=head2 sign_streams
167
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7UCqSsNMGdq+S7MwZulmwA
168
169
Type: has_many
170
171
Related object: L<Koha::Schema::Result::SignStream>
172
173
=cut
174
175
__PACKAGE__->has_many(
176
  "sign_streams",
177
  "Koha::Schema::Result::SignStream",
178
  { "foreign.saved_sql_id" => "self.id" },
179
  { cascade_copy => 0, cascade_delete => 0 },
180
);
181
182
183
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f9cgj30zP/aIRPhEmZNT6g
168
185
169
186
170
# You can replace this text with custom content, and it will be preserved on regeneration
187
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Sign.pm (+132 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::Sign;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::Sign
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<signs>
19
20
=cut
21
22
__PACKAGE__->table("signs");
23
24
=head1 ACCESSORS
25
26
=head2 sign_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 name
33
34
  data_type: 'varchar'
35
  is_nullable: 1
36
  size: 64
37
38
=head2 webapp
39
40
  data_type: 'integer'
41
  default_value: 0
42
  is_nullable: 0
43
44
=head2 transition
45
46
  data_type: 'char'
47
  default_value: 'none'
48
  is_nullable: 0
49
  size: 16
50
51
=head2 swatch
52
53
  data_type: 'char'
54
  default_value: (empty string)
55
  is_nullable: 0
56
  size: 1
57
58
=head2 idleafter
59
60
  data_type: 'integer'
61
  default_value: 0
62
  is_nullable: 0
63
64
=head2 pagedelay
65
66
  data_type: 'integer'
67
  default_value: 0
68
  is_nullable: 0
69
70
=head2 reloadafter
71
72
  data_type: 'integer'
73
  default_value: 0
74
  is_nullable: 0
75
76
=cut
77
78
__PACKAGE__->add_columns(
79
  "sign_id",
80
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
81
  "name",
82
  { data_type => "varchar", is_nullable => 1, size => 64 },
83
  "webapp",
84
  { data_type => "integer", default_value => 0, is_nullable => 0 },
85
  "transition",
86
  { data_type => "char", default_value => "none", is_nullable => 0, size => 16 },
87
  "swatch",
88
  { data_type => "char", default_value => "", is_nullable => 0, size => 1 },
89
  "idleafter",
90
  { data_type => "integer", default_value => 0, is_nullable => 0 },
91
  "pagedelay",
92
  { data_type => "integer", default_value => 0, is_nullable => 0 },
93
  "reloadafter",
94
  { data_type => "integer", default_value => 0, is_nullable => 0 },
95
);
96
97
=head1 PRIMARY KEY
98
99
=over 4
100
101
=item * L</sign_id>
102
103
=back
104
105
=cut
106
107
__PACKAGE__->set_primary_key("sign_id");
108
109
=head1 RELATIONS
110
111
=head2 signs_to_streams
112
113
Type: has_many
114
115
Related object: L<Koha::Schema::Result::SignsToStream>
116
117
=cut
118
119
__PACKAGE__->has_many(
120
  "signs_to_streams",
121
  "Koha::Schema::Result::SignsToStream",
122
  { "foreign.sign_id" => "self.sign_id" },
123
  { cascade_copy => 0, cascade_delete => 0 },
124
);
125
126
127
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
128
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OWtbToVshm6D/q7jMbhAEA
129
130
131
# You can replace this text with custom code or comments, and it will be preserved on regeneration
132
1;
(-)a/Koha/Schema/Result/SignStream.pm (+105 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::SignStream;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::SignStream
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<sign_streams>
19
20
=cut
21
22
__PACKAGE__->table("sign_streams");
23
24
=head1 ACCESSORS
25
26
=head2 sign_stream_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 saved_sql_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 name
39
40
  data_type: 'varchar'
41
  is_nullable: 1
42
  size: 64
43
44
=cut
45
46
__PACKAGE__->add_columns(
47
  "sign_stream_id",
48
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
49
  "saved_sql_id",
50
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
51
  "name",
52
  { data_type => "varchar", is_nullable => 1, size => 64 },
53
);
54
55
=head1 PRIMARY KEY
56
57
=over 4
58
59
=item * L</sign_stream_id>
60
61
=back
62
63
=cut
64
65
__PACKAGE__->set_primary_key("sign_stream_id");
66
67
=head1 RELATIONS
68
69
=head2 saved_sql
70
71
Type: belongs_to
72
73
Related object: L<Koha::Schema::Result::SavedSql>
74
75
=cut
76
77
__PACKAGE__->belongs_to(
78
  "saved_sql",
79
  "Koha::Schema::Result::SavedSql",
80
  { id => "saved_sql_id" },
81
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
82
);
83
84
=head2 signs_to_streams
85
86
Type: has_many
87
88
Related object: L<Koha::Schema::Result::SignsToStream>
89
90
=cut
91
92
__PACKAGE__->has_many(
93
  "signs_to_streams",
94
  "Koha::Schema::Result::SignsToStream",
95
  { "foreign.sign_stream_id" => "self.sign_stream_id" },
96
  { cascade_copy => 0, cascade_delete => 0 },
97
);
98
99
100
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
101
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+QnTPOZSc8xl1o2qI0YB8A
102
103
104
# You can replace this text with custom code or comments, and it will be preserved on regeneration
105
1;
(-)a/Koha/Schema/Result/SignsToStream.pm (+114 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::SignsToStream;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::SignsToStream
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<signs_to_streams>
19
20
=cut
21
22
__PACKAGE__->table("signs_to_streams");
23
24
=head1 ACCESSORS
25
26
=head2 sign_to_stream_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 sign_stream_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 sign_id
39
40
  data_type: 'integer'
41
  is_foreign_key: 1
42
  is_nullable: 0
43
44
=head2 params
45
46
  data_type: 'varchar'
47
  default_value: (empty string)
48
  is_nullable: 0
49
  size: 255
50
51
=cut
52
53
__PACKAGE__->add_columns(
54
  "sign_to_stream_id",
55
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
56
  "sign_stream_id",
57
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
58
  "sign_id",
59
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
60
  "params",
61
  { data_type => "varchar", default_value => "", is_nullable => 0, size => 255 },
62
);
63
64
=head1 PRIMARY KEY
65
66
=over 4
67
68
=item * L</sign_to_stream_id>
69
70
=back
71
72
=cut
73
74
__PACKAGE__->set_primary_key("sign_to_stream_id");
75
76
=head1 RELATIONS
77
78
=head2 sign
79
80
Type: belongs_to
81
82
Related object: L<Koha::Schema::Result::Sign>
83
84
=cut
85
86
__PACKAGE__->belongs_to(
87
  "sign",
88
  "Koha::Schema::Result::Sign",
89
  { sign_id => "sign_id" },
90
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
91
);
92
93
=head2 sign_stream
94
95
Type: belongs_to
96
97
Related object: L<Koha::Schema::Result::SignStream>
98
99
=cut
100
101
__PACKAGE__->belongs_to(
102
  "sign_stream",
103
  "Koha::Schema::Result::SignStream",
104
  { sign_stream_id => "sign_stream_id" },
105
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
106
);
107
108
109
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
110
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fAi1KA4VmwQM96sQoI5DMQ
111
112
113
# You can replace this text with custom code or comments, and it will be preserved on regeneration
114
1;
(-)a/Koha/Sign.pm (+40 lines)
Line 0 Link Here
1
package Koha::Sign;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::Sign - Koha Sign object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'Sign';
38
}
39
40
1;
(-)a/Koha/SignStream.pm (+40 lines)
Line 0 Link Here
1
package Koha::SignStream;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::SignStream - Koha SignStream object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'SignStream';
38
}
39
40
1;
(-)a/Koha/SignStreams.pm (+59 lines)
Line 0 Link Here
1
package Koha::SignStreams;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::SignStream;
24
25
use base qw( Koha::Objects );
26
27
=head1 NAME
28
29
Koha::SignStreams - Koha SignStream object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'SignStream';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::SignStream';
51
}
52
53
=head1 AUTHOR
54
55
Aleisha Amohia <aleisha@catalyst.net.nz>
56
57
=cut
58
59
1;
(-)a/Koha/Signs.pm (-307 / +36 lines)
Lines 1-330 Link Here
1
package Koha::Signs;
1
package Koha::Signs;
2
2
3
use C4::Context;
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
use C4::Biblio;
4
#
5
use C4::Koha;
5
# This file is part of Koha.
6
use C4::Items;
6
#
7
use Modern::Perl;
7
# Koha is free software; you can redistribute it and/or modify it under the
8
8
# terms of the GNU General Public License as published by the Free Software
9
use base qw( Exporter );
9
# Foundation; either version 3 of the License, or (at your option) any later
10
10
# version.
11
# set the version for version checking
11
#
12
our @EXPORT = qw(
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
    AddSignStream
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
    ModSignStream
15
#
16
    GetSignStream
16
# You should have received a copy of the GNU General Public License along
17
    GetSignStreams
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
    DelSignStream
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
    GetSignStreamRecords
21
22
    AddSign
23
    ModSign
24
    GetSign
25
    GetSigns
26
    DelSign
27
28
    AttachSignStreamToSign
29
    DetachSignStreamFromSign
30
    GetSignStreamsAttachedToSign
31
    GetSignStreamsAttachedToSignWithRecords
32
33
    ModSignStreamParams
34
    GetSignStreamParams
35
);
36
37
my $dbh = C4::Context->dbh;
38
39
# Streams
40
41
# Returns id of new sign_stream
42
sub AddSignStream {
43
44
    my ( $name, $report ) = @_;
45
46
    my $sth=$dbh->prepare("INSERT INTO sign_streams SET name = ?, saved_sql_id = ?");
47
    $sth->execute( $name, $report );
48
    return $dbh->last_insert_id( undef, undef, 'sign_streams', 'sign_stream_id' );
49
50
}
51
52
sub ModSignStream {
53
54
    my ( $name, $report, $sign_stream_id ) = @_;
55
56
    my $sth = $dbh->prepare("UPDATE sign_streams SET name = ?, saved_sql_id = ? WHERE sign_stream_id = ?");
57
    return $sth->execute( $name, $report, $sign_stream_id );
58
59
}
60
61
sub GetSignStream {
62
63
    my ( $sign_id ) = @_;
64
65
    return unless $sign_id;
66
67
    my $query = "SELECT s.*, sq.report_name, sq.savedsql
68
                 FROM sign_streams AS s, saved_sql AS sq
69
                 WHERE s.saved_sql_id = sq.id
70
                   AND s.sign_stream_id = ?";
71
    my $sth = $dbh->prepare($query);
72
    $sth->execute($sign_id);
73
    return $sth->fetchrow_hashref();
74
75
}
76
77
sub GetSignStreams {
78
79
    my $query = "SELECT s.*, sq.report_name, sq.savedsql
80
                 FROM sign_streams AS s, saved_sql AS sq
81
                 WHERE s.saved_sql_id = sq.id
82
                 ORDER BY s.name";
83
    my $sth = $dbh->prepare($query);
84
    $sth->execute();
85
    return $sth->fetchall_arrayref({});
86
87
}
88
89
sub DelSignStream {
90
91
    my ( $sign_stream_id ) = @_;
92
93
    return unless $sign_stream_id;
94
95
    my $sth = $dbh->prepare('DELETE FROM sign_streams WHERE sign_stream_id = ?');
96
    return $sth->execute($sign_stream_id);
97
98
}
99
100
sub GetSignStreamRecords {
101
    my ( $stream, $sign_to_stream_id) = @_;
102
    my $sql = $stream->{'savedsql'};
103
104
    if ( defined $sign_to_stream_id ) {
105
        my $params = GetSignStreamParams( $sign_to_stream_id );
106
        $sql = ReplaceParamsInSQL( $sql, $params );
107
        return undef if ( $sql =~ m/<</ );
108
    }
109
110
    return {result => RunSQL( $sql ), sql => $sql };
111
}
112
113
# Signs
114
115
# Returns id of new sign
116
sub AddSign {
117
118
    my ( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter ) = @_;
119
120
    my $sth=$dbh->prepare("INSERT INTO signs SET name = ?, webapp = ?, swatch = ?, transition = ?, idleafter = ?, pagedelay = ?, reloadafter = ?");
121
    $sth->execute( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter );
122
    return $dbh->last_insert_id( undef, undef, 'signs', 'sign_id' );
123
124
}
125
126
sub ModSign {
127
128
    my ( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter, $sign_id ) = @_;
129
130
    my $sth = $dbh->prepare("UPDATE signs SET name = ?, webapp = ?, swatch = ?, transition = ?, idleafter = ?, pagedelay = ?, reloadafter = ? WHERE sign_id = ?");
131
    return $sth->execute( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter, $sign_id );
132
133
}
134
135
sub GetSign {
136
137
    my ( $sign_id ) = @_;
138
139
    return unless $sign_id;
140
141
    my $query = "SELECT *
142
                 FROM signs
143
                 WHERE sign_id = ?";
144
    my $sth = $dbh->prepare($query);
145
    $sth->execute($sign_id);
146
    return $sth->fetchrow_hashref();
147
19
148
}
20
use Modern::Perl;
149
150
sub GetSigns {
151
152
    my $query = "SELECT *
153
                 FROM signs
154
                 ORDER BY name";
155
    my $sth = $dbh->prepare($query);
156
    $sth->execute();
157
    return $sth->fetchall_arrayref({});
158
159
}
160
161
sub DelSign {
162
163
    my ( $sign_id ) = @_;
164
165
    return unless $sign_id;
166
167
    my $sth = $dbh->prepare('DELETE FROM signs WHERE sign_id = ?');
168
    return $sth->execute($sign_id);
169
170
}
171
172
# Streams attached to signs
173
174
# Returns the ID of the connection between sign and stream
175
sub AttachSignStreamToSign {
176
177
    my ( $sign_stream_id, $sign_id ) = @_;
178
179
    return unless $sign_stream_id || $sign_id;
180
181
    my $sth = $dbh->prepare( 'INSERT INTO signs_to_streams SET sign_stream_id = ?, sign_id = ?' );
182
    $sth->execute( $sign_stream_id, $sign_id );
183
    return $dbh->last_insert_id( undef, undef, 'signs_to_streams', 'sign_to_stream_id' );
184
185
}
186
187
sub ModSignStreamParams {
188
189
    my ( $sign_to_stream_id, $params ) = @_;
190
    return unless $sign_to_stream_id;
191
    my $sth = $dbh->prepare( 'UPDATE signs_to_streams SET params = ? WHERE sign_to_stream_id = ?' );
192
    return $sth->execute( $params, $sign_to_stream_id );
193
194
}
195
196
# Returns the string of params for a given stream-attached-to-sign
197
sub GetSignStreamParams {
198
199
    my ( $sign_to_stream_id ) = @_;
200
201
    return unless $sign_to_stream_id;
202
203
    my $query = 'SELECT params FROM signs_to_streams WHERE sign_to_stream_id = ?';
204
    my $sth = $dbh->prepare( $query );
205
    $sth->execute( $sign_to_stream_id );
206
    return $sth->fetchrow_array();
207
208
}
209
210
sub ReplaceParamsInSQL {
211
212
    my ( $sql, $params ) = @_;
213
214
    return unless $sql || $params;
215
    return $sql unless $sql =~ m/<</;
216
217
    foreach my $param ( split /&/, $params ) {
218
        my ( $key, $value ) = split /=/, $param;
219
        # FIXME Handle spaces
220
        $sql =~ s/<<$key>>/$value/g;
221
    }
222
    return $sql;
223
224
}
225
226
sub GetSignStreamsAttachedToSign {
227
228
    my ( $sign_id ) = @_;
229
230
    return unless $sign_id;
231
232
    my $query = 'SELECT s.*, sts.sign_to_stream_id, sts.params, sq.report_name, sq.savedsql
233
                 FROM sign_streams AS s, signs_to_streams AS sts, saved_sql AS sq
234
                 WHERE s.sign_stream_id = sts.sign_stream_id
235
                   AND s.saved_sql_id = sq.id
236
                   AND sts.sign_id = ?
237
                 ORDER BY s.name';
238
    my $sth = $dbh->prepare( $query );
239
    $sth->execute( $sign_id );
240
    return $sth->fetchall_arrayref({});
241
242
}
243
244
sub GetSignStreamsAttachedToSignWithRecords {
245
246
    my ( $sign_id, $include_marc ) = @_;
247
248
    return unless $sign_id;
249
250
    my $streams = GetSignStreamsAttachedToSign( $sign_id );
251
    my @changedstreams;
252
    my %record_cache = ();
253
254
    # Add records to the streams
255
    foreach my $stream ( @{$streams} ) {
256
257
        my $records = RunSQL( ReplaceParamsInSQL( $stream->{'savedsql'}, $stream->{'params'} ) );
258
259
        if ( $include_marc ) {
260
261
            my @processed_records;
262
            foreach my $rec ( @{$records} ) {
263
                unless(defined $record_cache{$rec->{'biblionumber'}}) {
264
                    my $marc = GetMarcBiblio( $rec->{'biblionumber'} );
265
                    if ( ! $marc ) {
266
                        next;
267
                    }
268
269
                    my $isbn = GetNormalizedISBN( undef, $marc, C4::Context->preference("marcflavor") ) || '';
270
                    $rec->{'isbn'} = $isbn;
271
21
272
                    my $dat = GetBiblioData($rec->{'biblionumber'});
22
use Koha::Database;
273
                    my @items = GetItemsInfo($rec->{'biblionumber'});
23
use Koha::Sign;
274
                    foreach my $item ( @items ) {
275
                        my $shelflocations = GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
276
                        if ( defined $item->{'location'} ) {
277
                            $item->{'location_description'} = $shelflocations->{ $item->{'location'} };
278
                        }
279
                    }
280
                    $rec->{'items'} = \@items;
281
                    foreach ( keys %{$dat} ) {
282
                        $rec->{"$_"} = defined $dat->{$_} ? $dat->{$_} : '';
283
                    }
284
24
285
                    $rec->{'marc'} = $marc;
25
use base qw( Koha::Objects );
286
26
287
                    $record_cache{$rec->{'biblionumber'}} = $rec;
27
=head1 NAME
288
                }
289
                push @processed_records, $record_cache{$rec->{'biblionumber'}};
290
            }
291
            $stream->{'records'} = \@processed_records;
292
28
293
        } else {
29
Koha::Signs - Koha Sign object set class
294
30
295
          $stream->{'records'} = $records;
31
=head1 API
296
32
297
        }
33
=head2 Class Methods
298
34
299
        push @changedstreams, $stream;
35
=cut
300
36
301
    }
37
=head3 type
302
38
303
    return \@changedstreams;
39
=cut
304
40
41
sub _type {
42
    return 'Sign';
305
}
43
}
306
44
307
sub DetachSignStreamFromSign {
45
=head3 object_class
308
309
    my ( $sign_to_stream_id ) = @_;
310
311
    return unless $sign_to_stream_id;
312
46
313
    my $sth = $dbh->prepare( 'DELETE FROM signs_to_streams WHERE sign_to_stream_id = ?' );
47
=cut
314
    return $sth->execute( $sign_to_stream_id );
315
48
49
sub object_class {
50
    return 'Koha::Sign';
316
}
51
}
317
52
318
sub RunSQL {
53
=head1 AUTHOR
319
54
320
    my ( $query ) = @_;
55
Aleisha Amohia <aleisha@catalyst.net.nz>
321
56
322
    return unless $query;
57
=cut
323
324
    my $sth = $dbh->prepare($query);
325
    $sth->execute();
326
    return $sth->fetchall_arrayref({});
327
328
}
329
58
330
1;
59
1;
(-)a/Koha/SignsToStream.pm (+40 lines)
Line 0 Link Here
1
package Koha::SignsToStream;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::SignsToStream - SignsToStream object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'SignsToStream';
38
}
39
40
1;
(-)a/Koha/SignsToStreams.pm (+59 lines)
Line 0 Link Here
1
package Koha::SignsToStreams;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::SignsToStream;
24
25
use base qw( Koha::Objects );
26
27
=head1 NAME
28
29
Koha::SignsToStreams - Koha SignsToStream object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'SignsToStream';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::SignsToStream';
51
}
52
53
=head1 AUTHOR
54
55
Aleisha Amohia <aleisha@catalyst.net.nz>
56
57
=cut
58
59
1;
(-)a/installer/data/mysql/atomicupdate/bug_8628-digital-signs.sql (-1 / +1 lines)
Lines 1-4 Link Here
1
DROP TABLE IF EXISTS signs_to_streams;
2
DROP TABLE IF EXISTS sign_streams;
1
DROP TABLE IF EXISTS sign_streams;
3
CREATE TABLE sign_streams (
2
CREATE TABLE sign_streams (
4
  sign_stream_id int(11) NOT NULL auto_increment,    -- primary key, used to identify streams
3
  sign_stream_id int(11) NOT NULL auto_increment,    -- primary key, used to identify streams
Lines 19-24 CREATE TABLE signs ( Link Here
19
  reloadafter int(11) NOT NULL default 0,      -- seconds to wait before reloading all the pages
18
  reloadafter int(11) NOT NULL default 0,      -- seconds to wait before reloading all the pages
20
  PRIMARY KEY (sign_id)
19
  PRIMARY KEY (sign_id)
21
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21
DROP TABLE IF EXISTS signs_to_streams;
22
CREATE TABLE signs_to_streams (
22
CREATE TABLE signs_to_streams (
23
  sign_to_stream_id int(11) NOT NULL auto_increment, -- primary key, used to identify connections between signs and streams (the same stream can be attached to a sign more than once, with different parameters)
23
  sign_to_stream_id int(11) NOT NULL auto_increment, -- primary key, used to identify connections between signs and streams (the same stream can be attached to a sign more than once, with different parameters)
24
  sign_stream_id int(11) NOT NULL,                   -- foreign key from the decks sign_streams table
24
  sign_stream_id int(11) NOT NULL,                   -- foreign key from the decks sign_streams table
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (+3 lines)
Lines 102-107 Link Here
102
    [% IF ( CAN_user_tools_edit_quotes ) %]
102
    [% IF ( CAN_user_tools_edit_quotes ) %]
103
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
103
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
104
    [% END %]
104
    [% END %]
105
    [% IF ( CAN_user_tools_edit_digital_signs ) %]
106
        <li><a href="/cgi-bin/koha/tools/signs.pl">Digital signs</a></li>
107
    [% END %]
105
    [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
108
    [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
106
        <li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool plugins</a></li>
109
        <li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool plugins</a></li>
107
    [% END %]
110
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt (-53 / +50 lines)
Lines 6-36 Link Here
6
[% INCLUDE 'datatables.inc' %]
6
[% INCLUDE 'datatables.inc' %]
7
<script type="text/javascript">
7
<script type="text/javascript">
8
//<![CDATA[
8
//<![CDATA[
9
10
    $(document).ready(function() {
9
    $(document).ready(function() {
11
        $("#table_signs").dataTable($.extend(true, {}, dataTablesDefaults, {
10
        $("#table_signs").dataTable($.extend(true, {}, dataTablesDefaults, {
12
            "aoColumns": [
11
            "aoColumnDefs": [
13
                null,
12
                { "aTargets": [ -1 ], "bSearchable": false, "bSortable": false },
14
                {"bSearchable": false},
15
                {"bSearchable": false},
16
                {"bSearchable": false},
17
                {"bSearchable": false},
18
                {"bSearchable": false},
19
                {"bSearchable": false},
20
                {"bSearchable": false, "bSortable": false},
21
                {"bSearchable": false, "bSortable": false},
22
                {"bSearchable": false, "bSortable": false},
23
                {"bSearchable": false, "bSortable": false}
24
            ],
13
            ],
25
            "sPaginationType": "four_button"
14
            "sPaginationType": "four_button"
26
        } ));
15
        }));
27
        $("#table_streams").dataTable($.extend(true, {}, dataTablesDefaults, {
16
        $("#table_streams").dataTable($.extend(true, {}, dataTablesDefaults, {
28
            "aoColumnDefs": [
17
            "aoColumnDefs": [
29
                { "aTargets": [ -1 ], "bSearchable": false, "bSortable": false },
18
                { "aTargets": [ -1 ], "bSearchable": false, "bSortable": false },
30
            ],
19
            ],
31
            "sPaginationType": "four_button"
20
            "sPaginationType": "four_button"
32
        } ));
21
        }));
33
	 });
22
23
        $(".detach").on("click", function(){
24
            return confirmDelete(_("Are you sure you want to detach this stream from this sign?"));
25
        });
26
    });
34
//]]>
27
//]]>
35
</script>
28
</script>
36
</head>
29
</head>
Lines 76-93 Link Here
76
</div>
69
</div>
77
70
78
<div id="doc3" class="yui-t2">
71
<div id="doc3" class="yui-t2">
79
72
<div id="bd">
80
   <div id="bd">
73
<div id="yui-main">
81
	<div id="yui-main">
74
<div class="yui-b">
82
	<div class="yui-b">
83
75
84
[% UNLESS Koha.Preference( 'OPACDigitalSigns' ) %]
76
[% UNLESS Koha.Preference( 'OPACDigitalSigns' ) %]
85
<div class="dialog alert">
77
<div class="dialog alert">
86
    <p>
78
    <p>Digital signs are not enabled. Please enable <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=OPACDigitalSigns">OPACDigitalSigns</a> for OPAC digital signs to work.</p>
87
    Digital signs are not enabled. Please enable
88
    <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=OPACDigitalSigns">OPACDigitalSigns</a>
89
    for OPAC digital signs to work.
90
    </p>
91
</div>
79
</div>
92
[% END %]
80
[% END %]
93
81
Lines 123-130 Link Here
123
  <fieldset class="rows">
111
  <fieldset class="rows">
124
    <ol>
112
    <ol>
125
    <li><label for="name">Name</label><input type="text" name="name" value="[% stream.name %]" /></li>
113
    <li><label for="name">Name</label><input type="text" name="name" value="[% stream.name %]" /></li>
126
    <li><label for="report">Report</label>
114
    <li><label for="report" class="required">Report</label>
127
      <select name="report" id="report">
115
      <select name="report" id="report" class="required" required="required">
128
        [% UNLESS ( stream.sign_stream_id ) %]
116
        [% UNLESS ( stream.sign_stream_id ) %]
129
        <option value="">Choose report</option>
117
        <option value="">Choose report</option>
130
        [% END %]
118
        [% END %]
Lines 136-141 Link Here
136
          [% END %]
124
          [% END %]
137
        [% END %]
125
        [% END %]
138
      </select>
126
      </select>
127
      <span class="required">Required</span>
139
    </li>
128
    </li>
140
    </ol>
129
    </ol>
141
  </fieldset>
130
  </fieldset>
Lines 219-231 Link Here
219
208
220
  <h1>Edit streams attached to [% sign.name %]</h1>
209
  <h1>Edit streams attached to [% sign.name %]</h1>
221
  <h2>Streams already attached to this sign</h2>
210
  <h2>Streams already attached to this sign</h2>
222
  [% IF ( attached.size ) %]
211
  [% IF ( sts ) %]
223
    <table>
212
    <table>
224
    <thead>
213
    <thead>
225
    <tr><th>Name</th><th>Parameters</th><th>Edit parameters</th><th>Detach</th></tr>
214
        <tr>
215
            <th>Name</th>
216
            <th colspan="2">Parameters</th>
217
            <th>&nbsp;</th>
218
        </tr>
226
    </thead>
219
    </thead>
227
    <tbody>
220
    <tbody>
228
    [% FOREACH s IN attached %]
221
    [% FOREACH s IN sts %]
229
      <tr>
222
      <tr>
230
        <td>[% s.sign_stream.name %]</td>
223
        <td>[% s.sign_stream.name %]</td>
231
        <td>[% IF ( s.params ) %][% s.params %][% ELSE %]None[% END %]</td>
224
        <td>[% IF ( s.params ) %][% s.params %][% ELSE %]None[% END %]</td>
Lines 242-248 Link Here
242
    </tbody>
235
    </tbody>
243
    </table>
236
    </table>
244
  [% ELSE %]
237
  [% ELSE %]
245
    <p>There are no streams attached to this sign, yet.</p>
238
    <p>There are no streams attached to this sign.</p>
246
  [% END %]
239
  [% END %]
247
240
248
  <h2>Attach a new stream to this sign</h2>
241
  <h2>Attach a new stream to this sign</h2>
Lines 266-272 Link Here
266
[% ELSIF op == 'get_params' %]
259
[% ELSIF op == 'get_params' %]
267
260
268
  <h1>Parameters for [% stream.name %]</h1>
261
  <h1>Parameters for [% stream.name %]</h1>
269
  <p>Based on report: [% stream.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
262
  <p>Based on report: [% sql.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
270
263
271
  <form action="[% script_name %]" name="get_params_form" id="get_params_form" method="post">
264
  <form action="[% script_name %]" name="get_params_form" id="get_params_form" method="post">
272
  <input type="hidden" name="op" value="save_params" />
265
  <input type="hidden" name="op" value="save_params" />
Lines 274-287 Link Here
274
  <input type="hidden" name="sign_stream_id" value="[% sign_stream_id %]" />
267
  <input type="hidden" name="sign_stream_id" value="[% sign_stream_id %]" />
275
  <input type="hidden" name="sign_id" value="[% sign_id %]" />
268
  <input type="hidden" name="sign_id" value="[% sign_id %]" />
276
  <fieldset class="rows">
269
  <fieldset class="rows">
277
    [% IF ( params ) %]
270
    [% IF ( params.params ) %]
278
      <legend id="save_params_lgd">Edit parameters</legend>
271
      <legend id="save_params_lgd">Edit parameters</legend>
279
    [% ELSE %]
272
    [% ELSE %]
280
      <legend id="save_params_lgd">Add parameters</legend>
273
      <legend id="save_params_lgd">Add parameters</legend>
281
    [% END %]
274
    [% END %]
282
    <ol>
275
    <ol>
283
    <li><label for="stream">Parameters</label>
276
    <li><label for="stream">Parameters</label>
284
      <input type="text" size="60" name="parameters" id="parameters" value="[% params %]" />
277
      <input type="text" size="60" name="parameters" id="parameters" value="[% params.params %]" />
285
    </li>
278
    </li>
286
    </ol>
279
    </ol>
287
  </fieldset>
280
  </fieldset>
Lines 289-295 Link Here
289
  </form>
282
  </form>
290
283
291
  <h2>Raw SQL</h2>
284
  <h2>Raw SQL</h2>
292
  <pre id="sql_output">[% stream.savedsql | html %]</pre>
285
  <pre id="sql_output">[% sql.savedsql | html %]</pre>
293
286
294
  <h2>SQL with current parameters replaced</h2>
287
  <h2>SQL with current parameters replaced</h2>
295
  <pre id="sql_output">[% newsql | html %]</pre>
288
  <pre id="sql_output">[% newsql | html %]</pre>
Lines 307-316 Link Here
307
    <form action="[% script_name %]" id ="confirm_stream_delete_form" method="post">
300
    <form action="[% script_name %]" id ="confirm_stream_delete_form" method="post">
308
    <input type="hidden" name="op" value="del_stream_ok" />
301
    <input type="hidden" name="op" value="del_stream_ok" />
309
    <input type="hidden" name="sign_stream_id" value="[% stream.sign_stream_id %]" />
302
    <input type="hidden" name="sign_stream_id" value="[% stream.sign_stream_id %]" />
310
    <input type="submit" class="approve" value="Yes, Delete this stream" /></form>
303
    <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this stream</button>
304
    </form>
311
305
312
    <form action="[% script_name %]" id="cancel_stream_delete_form" method="get">
306
    <form action="[% script_name %]" id="cancel_stream_delete_form" method="get">
313
    <input type="submit" value="No, do not delete" class="deny" />
307
    <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i>  No, do not delete</button>
314
    </form>
308
    </form>
315
    </div>
309
    </div>
316
310
Lines 330-339 Link Here
330
    <form action="[% script_name %]" id ="confirm_sign_delete_form" method="post">
324
    <form action="[% script_name %]" id ="confirm_sign_delete_form" method="post">
331
    <input type="hidden" name="op" value="del_sign_ok" />
325
    <input type="hidden" name="op" value="del_sign_ok" />
332
    <input type="hidden" name="sign_id" value="[% sign.sign_id %]" />
326
    <input type="hidden" name="sign_id" value="[% sign.sign_id %]" />
333
    <input type="submit" class="approve" value="Yes, Delete this sign" /></form>
327
    <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this sign</button>
328
    </form>
334
329
335
    <form action="[% script_name %]" id="cancel_sign_delete_form" method="get">
330
    <form action="[% script_name %]" id="cancel_sign_delete_form" method="get">
336
    <input type="submit" value="No, do not delete" class="deny" />
331
    <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
337
    </form>
332
    </form>
338
    </div>
333
    </div>
339
334
Lines 353-359 Link Here
353
348
354
  [% IF ( streams ) %]
349
  [% IF ( streams ) %]
355
    [% FOREACH stream IN streams %]
350
    [% FOREACH stream IN streams %]
356
      <h3>[% stream.name %]</h3>
351
      <h3>[% stream.sign_stream.name %]</h3>
357
      <ul>
352
      <ul>
358
      [% FOREACH record IN stream.records %]
353
      [% FOREACH record IN stream.records %]
359
        <li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.biblionumber %]">[% record.title %]</a></li>
354
        <li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.biblionumber %]">[% record.title %]</a></li>
Lines 367-378 Link Here
367
[% ELSIF op == 'view_stream' %]
362
[% ELSIF op == 'view_stream' %]
368
363
369
  <h1>[% stream.name %]</h1>
364
  <h1>[% stream.name %]</h1>
370
  <p>Based on report: [% stream.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
365
  <p>Based on report: [% stream.saved_sql_id.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
371
  <h2>SQL</h2>
366
  <h2>SQL</h2>
372
  <pre id="sql_output">[% stream.savedsql | html %]</pre>
367
  <pre id="sql_output">[% stream.saved_sql_id.savedsql | html %]</pre>
373
  <h2>Records</h2>
368
  <h2>Records</h2>
374
  [% IF ( has_params ) %]
369
  [% IF ( has_params ) %]
375
    <p>Sorry, the report this stream is based on has parameters and displaying it only makes sense after it has been attached to a sign and parameters have been added.</p>
370
    <p>Unable to display records. Check that this stream has been attached to a sign and any parameters have been filled appropriately.</p>
376
  [% ELSE %]
371
  [% ELSE %]
377
    [% INCLUDE display_records %]
372
    [% INCLUDE display_records %]
378
  [% END %]
373
  [% END %]
Lines 381-388 Link Here
381
376
382
  <h1>Digital signs</h1>
377
  <h1>Digital signs</h1>
383
378
379
  [% IF ( error_on_insert_stream ) %]
380
    <div class="dialog error">Failed to create a new stream.</div>
381
  [% ELSIF ( success_on_insert_stream ) %]
382
    <div class="dialog message">New stream added.</div>
383
  [% END %]
384
385
  <h2>Signs</h2>
384
  [% IF signs %]
386
  [% IF signs %]
385
    <h2>Signs</h2>
386
    <table id="table_signs">
387
    <table id="table_signs">
387
        <thead>
388
        <thead>
388
            <tr>
389
            <tr>
Lines 393-402 Link Here
393
                <th>Idle after</th>
394
                <th>Idle after</th>
394
                <th>Page delay</th>
395
                <th>Page delay</th>
395
                <th>Reload after</th>
396
                <th>Reload after</th>
396
                <th>Edit</th>
397
                <th>&nbsp;</th>
397
                <th>Edit streams</th>
398
                <th>Delete</th>
399
                <th>View sign</th>
400
            </tr>
398
            </tr>
401
        </thead>
399
        </thead>
402
        <tbody>
400
        <tbody>
Lines 426-443 Link Here
426
    </table>
424
    </table>
427
    [% UNLESS ( OPACBaseURL ) %]<p>Please note: Links to view signs in the OPAC will only be displayed if you fill in the OPACBaseURL system preference.</p>[% END %]
425
    [% UNLESS ( OPACBaseURL ) %]<p>Please note: Links to view signs in the OPAC will only be displayed if you fill in the OPACBaseURL system preference.</p>[% END %]
428
  [% ELSE %]
426
  [% ELSE %]
429
    <p>No signs defined!</p>
427
    <div class="dialog message">No signs defined. <a href="/cgi-bin/koha/tools/signs.pl?op=add_sign">Create a new sign.</a></div>
430
  [% END %]
428
  [% END %]
431
429
430
  <h2>Streams</h2>
432
  [% IF streams %]
431
  [% IF streams %]
433
    <h2>Streams</h2>
434
    <table id="table_streams">
432
    <table id="table_streams">
435
        <thead>
433
        <thead>
436
            <tr>
434
            <tr>
437
                <th>Name</th>
435
                <th>Name</th>
438
                <th>Report</th>
436
                <th>Report</th>
439
                <th>Edit</th>
437
                <th>Actions</th>
440
                <th>Delete</th>
441
            </tr>
438
            </tr>
442
        </thead>
439
        </thead>
443
        <tbody>
440
        <tbody>
Lines 454-460 Link Here
454
        </tbody>
451
        </tbody>
455
    </table>
452
    </table>
456
  [% ELSE %]
453
  [% ELSE %]
457
    <p>No streams defined!</p>
454
    <div class="dialog message">No streams defined. <a href="/cgi-bin/koha/tools/signs.pl?op=add_stream">Create a new stream.</a></div>
458
  [% END %]
455
  [% END %]
459
456
460
[% END %]
457
[% END %]
(-)a/opac/opac-signs.pl (-5 / +67 lines)
Lines 20-26 Link Here
20
use CGI;
20
use CGI;
21
use C4::Auth;
21
use C4::Auth;
22
use C4::Output;
22
use C4::Output;
23
use C4::Biblio;
24
use C4::Reports::Guided;
25
use C4::Context;
26
use C4::Koha;
27
use C4::Items;
28
use Koha::AuthorisedValues;
23
use Koha::Signs;
29
use Koha::Signs;
30
use Koha::SignStreams;
31
use Koha::SignsToStreams;
24
use Modern::Perl;
32
use Modern::Perl;
25
33
26
binmode STDOUT, ':encoding(UTF-8)'; # FIXME Non-ASCII is broken without this
34
binmode STDOUT, ':encoding(UTF-8)'; # FIXME Non-ASCII is broken without this
Lines 38-48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user({ Link Here
38
46
39
if ( C4::Context->preference('OPACDigitalSigns') ) {
47
if ( C4::Context->preference('OPACDigitalSigns') ) {
40
    if ( $sign_id ne '' ) { # Display a sign with streams
48
    if ( $sign_id ne '' ) { # Display a sign with streams
41
        $template->{VARS}->{'sign'}    = GetSign( $sign_id );
49
        $template->{VARS}->{'sign'} = Koha::Signs->find( $sign_id );
42
        $template->{VARS}->{'streams'} = GetSignStreamsAttachedToSignWithRecords( $sign_id, 1 );
50
43
    }
51
        # Getting sign streams attached to sign with records
44
    else { # Display a list of all available signs
52
        my $schema = Koha::Database->new()->schema();
45
       $template->{VARS}->{'signs'}  = GetSigns();
53
        my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
54
        my @changedstreams;
55
        my %record_cache = ();
56
        foreach my $s ( @signstostreams ) {
57
            my $stream = Koha::SignStreams->find( $s->sign_stream_id );
58
            my $sql = get_saved_report($stream->saved_sql_id);
59
            my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id });
60
61
            # Generate SQL with added params
62
            my $newsql = $sql->{'savedsql'};
63
            foreach my $param ( split /&/, $params->params ) {
64
                my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself
65
                $newsql =~ s/$key/$value/g;
66
            }
67
68
            # Run query with new sql
69
            my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
70
            if ( ! $error ) {
71
                $records = $records->fetchall_arrayref({});
72
            }
73
            # Include marc
74
            my @processed_records;
75
            foreach my $rec ( @{$records} ) {
76
                unless (defined $record_cache{$rec->{'biblionumber'}}) {
77
                    my $marc = GetMarcBiblio( $rec->{'biblionumber'} );
78
                    if ( ! $marc ) {
79
                        next;
80
                    }
81
82
                    my $isbn = GetNormalizedISBN( undef, $marc, C4::Context->preference("marcflavor") ) || '';
83
                    $rec->{'isbn'} = $isbn;
84
85
                    my $dat = GetBiblioData($rec->{'biblionumber'});
86
                    my @items = GetItemsInfo($rec->{'biblionumber'});
87
                    foreach my $item ( @items ) {
88
                        my $shelflocations = { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
89
                        if ( defined $item->{'location'} ) {
90
                            $item->{'location_description'} = $shelflocations->{ $item->{'location'} };
91
                        }
92
                    }
93
                    $rec->{'items'} = \@items;
94
                    foreach ( keys %{$dat} ) {
95
                        $rec->{"$_"} = defined $dat->{$_} ? $dat->{$_} : '';
96
                    }
97
                    $rec->{'marc'} = $marc;
98
                    $record_cache{$rec->{'biblionumber'}} = $rec;
99
                }
100
                push @processed_records, $record_cache{$rec->{'biblionumber'}};
101
            }
102
            $s->{'records'} = \@processed_records;
103
            push @changedstreams, $s;
104
        }
105
        $template->{VARS}->{'streams'} = \@changedstreams;
106
    } else { # Display a list of all available signs
107
        $template->{VARS}->{'signs'}  = Koha::Signs->search({});
46
    }
108
    }
47
}
109
}
48
110
(-)a/tools/signs.pl (-33 / +75 lines)
Lines 16-24 Link Here
16
# You should have received a copy of the GNU General Public License along
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
#
21
#
22
19
23
=head1 NAME
20
=head1 NAME
24
21
Lines 34-40 Allows authorized users to create and manage digital signs for the OPAC. Link Here
34
31
35
=cut
32
=cut
36
33
34
use Koha::Sign;
37
use Koha::Signs;
35
use Koha::Signs;
36
use Koha::SignStream;
37
use Koha::SignStreams;
38
use Koha::SignsToStreams;
39
38
use CGI;
40
use CGI;
39
use C4::Auth;
41
use C4::Auth;
40
use C4::Context;
42
use C4::Context;
Lines 73-79 if ( $op eq 'add_stream' ) { Link Here
73
75
74
} elsif ( $op eq 'edit_stream' && $sign_stream_id ne '') {
76
} elsif ( $op eq 'edit_stream' && $sign_stream_id ne '') {
75
77
76
    my $stream = GetSignStream( $sign_stream_id );
78
    my $stream = Koha::SignStreams->find( $sign_stream_id );
77
79
78
    $template->param(
80
    $template->param(
79
      'op'          => 'stream_form',
81
      'op'          => 'stream_form',
Lines 84-105 if ( $op eq 'add_stream' ) { Link Here
84
86
85
} elsif ( $op eq 'save_stream' ) {
87
} elsif ( $op eq 'save_stream' ) {
86
88
89
    my $name = $cgi->param('name');
90
    my $report = $cgi->param('report');
87
    if ( $sign_stream_id ne '' ) {
91
    if ( $sign_stream_id ne '' ) {
88
        ModSignStream( $cgi->param('name'), $cgi->param('report'), $cgi->param('sign_stream_id') );
92
        Koha::SignStreams->find( $sign_stream_id )->set({ name => $name, saved_sql_id => $report })->store; # modify
89
    } else {
93
    } else {
90
        AddSignStream( $cgi->param('name'), $cgi->param('report'),  );
94
        Koha::SignStream->new({ name => $name, saved_sql_id => $report })->store; # add new
91
    }
95
    }
92
    print $cgi->redirect($script_name);
96
    print $cgi->redirect($script_name);
93
97
94
} elsif ( $op eq 'view_stream' && $sign_stream_id ne '' ) {
98
} elsif ( $op eq 'view_stream' && $sign_stream_id ne '' ) {
95
99
    my $stream = Koha::SignStreams->find( $sign_stream_id );
96
    my $stream = GetSignStream( $sign_stream_id );
100
    my $report = get_saved_report($stream->saved_sql_id);
97
101
    my $sql = $report->{'savedsql'};
98
    if ( $stream->{'savedsql'} =~ m/<</ ) {
102
    my ( $records, $error ) = execute_query( $sql, 0, 999999 );
99
        $template->param( 'has_params' => 1 );
103
    if ( $records && not $error ) {
104
        $records = $records->fetchall_arrayref({});
105
        $template->param( 'records' => $records );
100
    } else {
106
    } else {
101
        my $records = GetSignStreamRecords( $stream );
107
        $template->param( 'has_params' => 1 );
102
        $template->param( 'records' => $records->{result} );
103
    }
108
    }
104
109
105
    $template->param(
110
    $template->param(
Lines 110-116 if ( $op eq 'add_stream' ) { Link Here
110
115
111
} elsif ( $op eq 'del_stream' ) {
116
} elsif ( $op eq 'del_stream' ) {
112
117
113
    my $stream = GetSignStream( $sign_stream_id );
118
    my $stream = Koha::SignStreams->find( $sign_stream_id );
114
119
115
    $template->param(
120
    $template->param(
116
        'op'          => 'del_stream',
121
        'op'          => 'del_stream',
Lines 119-126 if ( $op eq 'add_stream' ) { Link Here
119
    );
124
    );
120
125
121
} elsif ( $op eq 'del_stream_ok' ) {
126
} elsif ( $op eq 'del_stream_ok' ) {
122
127
    Koha::SignStreams->find( $sign_stream_id )->delete;
123
    DelSignStream( $sign_stream_id );
124
128
125
    $template->param(
129
    $template->param(
126
        'op'          => 'del_stream_ok',
130
        'op'          => 'del_stream_ok',
Lines 139-145 if ( $op eq 'add_stream' ) { Link Here
139
143
140
    $template->param(
144
    $template->param(
141
        'op'          => 'sign_form',
145
        'op'          => 'sign_form',
142
        'sign'        => GetSign( $sign_id ),
146
        'sign'        => Koha::Signs->find( $sign_id ),
143
        'script_name' => $script_name,
147
        'script_name' => $script_name,
144
    );
148
    );
145
149
Lines 170-179 if ( $op eq 'add_stream' ) { Link Here
170
174
171
} elsif ( $op eq 'view_sign' && $sign_id ne '' ) {
175
} elsif ( $op eq 'view_sign' && $sign_id ne '' ) {
172
176
177
    # Getting sign streams attached to sign with records
178
    my $schema = Koha::Database->new()->schema();
179
    my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
180
    my @changedstreams;
181
182
    foreach my $s ( @signstostreams ) {
183
        my $stream = Koha::SignStreams->find( $s->sign_stream_id );
184
        my $sql = get_saved_report($stream->saved_sql_id);
185
        my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id });
186
        # Generate SQL with added params
187
        my $newsql = $sql->{'savedsql'};
188
        foreach my $param ( split /&/, $params->params ) {
189
            my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself
190
            $newsql =~ s/$key/$value/g;
191
        }
192
        # Run query with new sql
193
        my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
194
        if ( $records && not $error ) {
195
            $s->{'records'} = $records->fetchall_arrayref({});
196
            push @changedstreams, $s;
197
        }
198
    }
199
173
    $template->param(
200
    $template->param(
174
        'op'          => 'view_sign',
201
        'op'          => 'view_sign',
175
        'sign'        => GetSign( $sign_id ),
202
        'sign'        => Koha::Signs->find( $sign_id ),
176
        'streams'     => GetSignStreamsAttachedToSignWithRecords( $sign_id, 0 ),
203
        'streams'     => \@changedstreams,
177
        'script_name' => $script_name,
204
        'script_name' => $script_name,
178
    );
205
    );
179
206
Lines 181-193 if ( $op eq 'add_stream' ) { Link Here
181
208
182
    $template->param(
209
    $template->param(
183
        'op'          => 'del_sign',
210
        'op'          => 'del_sign',
184
        'sign'        => GetSign( $sign_id ),
211
        'sign'        => Koha::Signs->find( $sign_id ),
185
        'script_name' => $script_name,
212
        'script_name' => $script_name,
186
    );
213
    );
187
214
188
} elsif ( $op eq 'del_sign_ok' ) {
215
} elsif ( $op eq 'del_sign_ok' ) {
189
216
190
    DelSign( $sign_id );
217
    Koha::Signs->find( $sign_id )->delete;
191
218
192
    $template->param(
219
    $template->param(
193
        'op'          => 'del_sign_ok',
220
        'op'          => 'del_sign_ok',
Lines 198-209 if ( $op eq 'add_stream' ) { Link Here
198
225
199
} elsif ( $op eq 'edit_streams' && $sign_id ne '') {
226
} elsif ( $op eq 'edit_streams' && $sign_id ne '') {
200
227
228
    my $sign = Koha::Signs->find( $sign_id );
229
    my $streams = Koha::SignStreams->search({});
230
231
    my $schema = Koha::Database->new()->schema();
232
    my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
233
201
    $template->param(
234
    $template->param(
202
        'op'          => 'edit_streams',
235
        'op'          => 'edit_streams',
203
        'sign'        => GetSign( $sign_id ),
236
        'sign'        => $sign,
204
        'sign_id'     => $sign_id,
237
        'sign_id'     => $sign_id,
205
        'streams'     => GetSignStreams(),
238
        'streams'     => $streams,
206
        'attached'    => GetSignStreamsAttachedToSign( $sign_id ),
239
        'sts'         => \@signstostreams,
207
        'script_name' => $script_name
240
        'script_name' => $script_name
208
    );
241
    );
209
242
Lines 222-231 if ( $op eq 'add_stream' ) { Link Here
222
255
223
} elsif ( $op eq 'get_params' && $sign_to_stream_id ne '' && $sign_stream_id ne '' && $sign_id ne '' ) {
256
} elsif ( $op eq 'get_params' && $sign_to_stream_id ne '' && $sign_stream_id ne '' && $sign_id ne '' ) {
224
257
225
    my $stream = GetSignStream( $sign_stream_id );
258
    my $stream = Koha::SignStreams->find( $sign_stream_id );
226
    my $records = GetSignStreamRecords($stream, $sign_to_stream_id);
259
    my $sql = get_saved_report($stream->saved_sql_id);
227
    if ( $records ) {
260
    my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $sign_to_stream_id });
228
        $template->param( 'records' => $records->{result} );
261
    # Generate SQL with added params
262
    my $newsql = $sql->{'savedsql'};
263
    foreach my $param ( split /&/, $params->params ) {
264
        my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself
265
        $newsql =~ s/$key/$value/g;
266
    }
267
    # Run query with new sql
268
    my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
269
    if ( $records && not $error) {
270
        $template->param( 'records' => $records->fetchall_arrayref({}) );
229
    } else {
271
    } else {
230
        $template->param( 'has_params' => 1 );
272
        $template->param( 'has_params' => 1 );
231
    }
273
    }
Lines 236-254 if ( $op eq 'add_stream' ) { Link Here
236
        'sign_id'           => $sign_id,
278
        'sign_id'           => $sign_id,
237
        'sign_stream_id'    => $sign_stream_id,
279
        'sign_stream_id'    => $sign_stream_id,
238
        'sign_to_stream_id' => $sign_to_stream_id,
280
        'sign_to_stream_id' => $sign_to_stream_id,
239
        'params'            => GetSignStreamParams( $sign_to_stream_id ),
281
        'params'            => $params,
240
        'newsql'            => $records->{sql},
282
        'sql'               => $sql,
283
        'newsql'            => $newsql,
241
        'script_name'       => $script_name,
284
        'script_name'       => $script_name,
242
    );
285
    );
243
286
244
} elsif ( $op eq 'save_params' && $sign_to_stream_id ne '' && $sign_id ne '' ) {
287
} elsif ( $op eq 'save_params' && $sign_to_stream_id ne '' && $sign_id ne '' ) {
245
288
246
    ModSignStreamParams( $sign_to_stream_id, $parameters );
289
    Koha::SignsToStreams->find( $sign_to_stream_id )->set({ params => $parameters })->store;
247
    print $cgi->redirect( $script_name . '?op=get_params&sign_to_stream_id=' . $sign_to_stream_id . '&sign_stream_id=' . $sign_stream_id . '&sign_id=' . $sign_id );
290
    print $cgi->redirect( $script_name . '?op=get_params&sign_to_stream_id=' . $sign_to_stream_id . '&sign_stream_id=' . $sign_stream_id . '&sign_id=' . $sign_id );
248
291
249
} elsif ( $op eq 'detach_stream_from_sign' && $sign_to_stream_id ne '' ) {
292
} elsif ( $op eq 'detach_stream_from_sign' && $sign_to_stream_id ne '' ) {
250
293
251
    DetachSignStreamFromSign( $sign_to_stream_id );
294
    Koha::SignsToStreams->find( $sign_to_stream_id )->delete;
252
    print $cgi->redirect($script_name . '?op=edit_streams&sign_id=' . $sign_id);
295
    print $cgi->redirect($script_name . '?op=edit_streams&sign_id=' . $sign_id);
253
296
254
} else {
297
} else {
255
- 

Return to bug 8628