Lines 20-26
use vars qw($VERSION @EXPORT);
Link Here
|
20 |
|
20 |
|
21 |
use Carp; |
21 |
use Carp; |
22 |
|
22 |
|
23 |
use Koha::Database; |
23 |
use C4::Context; |
24 |
|
24 |
|
25 |
our ( @ISA, @EXPORT ); |
25 |
our ( @ISA, @EXPORT ); |
26 |
|
26 |
|
Lines 66-75
sub GetSingleEvents {
Link Here
|
66 |
|
66 |
|
67 |
return C4::Context->dbh->selectall_arrayref( q{ |
67 |
return C4::Context->dbh->selectall_arrayref( q{ |
68 |
SELECT |
68 |
SELECT |
69 |
CONCAT(LPAD(year, 4, '0'), '-', LPAD(month, 2, '0'), '-', LPAD(day, 2, '0')) as event_date, |
69 |
event_date, open_hour, open_minute, close_hour, close_minute, title, description, |
70 |
0 as open_hour, 0 as open_minute, IF(isexception, 24, 0) as close_hour, |
70 |
(open_hour = 0 AND open_minute = 0 AND close_hour = 0 AND close_minute = 0) AS closed |
71 |
0 as close_minute, title, description, IF(isexception, 0, 1) as closed |
71 |
FROM calendar_events |
72 |
FROM special_holidays |
|
|
73 |
WHERE branchcode = ? |
72 |
WHERE branchcode = ? |
74 |
}, { Slice => {} }, $branchcode ); |
73 |
}, { Slice => {} }, $branchcode ); |
75 |
} |
74 |
} |
Lines 87-97
sub GetWeeklyEvents {
Link Here
|
87 |
|
86 |
|
88 |
return C4::Context->dbh->selectall_arrayref( q{ |
87 |
return C4::Context->dbh->selectall_arrayref( q{ |
89 |
SELECT |
88 |
SELECT |
90 |
weekday, 0 as open_hour, 0 as open_minute, 0 as close_hour, |
89 |
weekday, open_hour, open_minute, close_hour, close_minute, title, description, |
91 |
0 as close_minute, title, description, 1 as closed |
90 |
(open_hour = 0 AND open_minute = 0 AND close_hour = 0 AND close_minute = 0) AS closed |
92 |
FROM repeatable_holidays |
91 |
FROM calendar_repeats |
93 |
WHERE branchcode = ? AND weekday IS NOT NULL |
92 |
WHERE branchcode = ? AND weekday IS NOT NULL |
94 |
}, { Slice => {} }, $branchcode ); |
93 |
}, { Slice => {} }, $branchcode ); |
95 |
} |
94 |
} |
96 |
|
95 |
|
97 |
=head2 GetYearlyEvents |
96 |
=head2 GetYearlyEvents |
Lines 107-236
sub GetYearlyEvents {
Link Here
|
107 |
|
106 |
|
108 |
return C4::Context->dbh->selectall_arrayref( q{ |
107 |
return C4::Context->dbh->selectall_arrayref( q{ |
109 |
SELECT |
108 |
SELECT |
110 |
month, day, 0 as open_hour, 0 as open_minute, 0 as close_hour, |
109 |
month, day, open_hour, open_minute, close_hour, close_minute, title, description, |
111 |
0 as close_minute, title, description, 1 as closed |
110 |
(open_hour = 0 AND open_minute = 0 AND close_hour = 0 AND close_minute = 0) AS closed |
112 |
FROM repeatable_holidays |
111 |
FROM calendar_repeats |
113 |
WHERE branchcode = ? AND weekday IS NULL |
112 |
WHERE branchcode = ? AND weekday IS NULL |
114 |
}, { Slice => {} }, $branchcode ); |
113 |
}, { Slice => {} }, $branchcode ); |
115 |
} |
114 |
} |
116 |
|
115 |
|
117 |
=head2 ModSingleEvent |
116 |
=head2 ModSingleEvent |
118 |
|
117 |
|
119 |
ModSingleEvent( $branchcode, \%info ) |
118 |
ModSingleEvent( $branchcode, $date, \%info ) |
120 |
|
119 |
|
121 |
Creates or updates an event for a single date. $info->{date} should be an |
120 |
Creates or updates an event for a single date. $date should be an ISO-formatted |
122 |
ISO-formatted date string, and \%info should also contain the following keys: |
121 |
date string, and \%info should contain the following keys: open_hour, |
123 |
open_hour, open_minute, close_hour, close_minute, title and description. |
122 |
open_minute, close_hour, close_minute, title and description. |
124 |
|
123 |
|
125 |
=cut |
124 |
=cut |
126 |
|
125 |
|
127 |
sub ModSingleEvent { |
126 |
sub ModSingleEvent { |
128 |
my ( $branchcode, $info ) = @_; |
127 |
my ( $branchcode, $date, $info ) = @_; |
129 |
|
128 |
|
130 |
my ( $year, $month, $day ) = ( $info->{date} =~ /(\d+)-(\d+)-(\d+)/ ); |
129 |
C4::Context->dbh->do( q{ |
131 |
return unless ( $year && $month && $day ); |
130 |
INSERT INTO calendar_events(branchcode, event_date, open_hour, open_minute, close_hour, close_minute, title, description) |
132 |
|
131 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?) |
133 |
my $dbh = C4::Context->dbh; |
132 |
ON DUPLICATE KEY UPDATE open_hour = ?, open_minute = ?, close_hour = ?, close_minute = ?, title = ?, description = ? |
134 |
my @args = ( ( map { $info->{$_} } qw(title description) ), $info->{close_hour} != 0, $branchcode, $year, $month, $day ); |
133 |
}, {}, $branchcode, $date, ( map { $info->{$_} } qw(open_hour open_minute close_hour close_minute title description) ) x 2 ); |
135 |
|
|
|
136 |
# The code below relies on $dbh->do returning 0 when the update affects no rows |
137 |
my $affected = $dbh->do( q{ |
138 |
UPDATE special_holidays |
139 |
SET |
140 |
title = ?, description = ?, isexception = ? |
141 |
WHERE branchcode = ? AND year = ? AND month = ? AND day = ? |
142 |
}, {}, @args ); |
143 |
|
144 |
$dbh->do( q{ |
145 |
INSERT |
146 |
INTO special_holidays(title, description, isexception, branchcode, year, month, day) |
147 |
VALUES (?, ?, ?, ?, ?, ?, ?) |
148 |
}, {}, @args ) unless ( $affected > 0 ); |
149 |
} |
134 |
} |
150 |
|
135 |
|
151 |
=head2 ModRepeatingEvent |
136 |
=head2 ModRepeatingEvent |
152 |
|
137 |
|
153 |
ModRepeatingEvent( $branchcode, \%info ) |
138 |
ModRepeatingEvent( $branchcode, $weekday, $month, $day, \%info ) |
154 |
|
139 |
|
155 |
Creates or updates a weekly- or yearly-repeating event. Either $info->{weekday}, |
140 |
Creates or updates a weekly- or yearly-repeating event. Either $weekday, |
156 |
or $info->{month} and $info->{day} should be set, for a weekly or yearly event, |
141 |
or $month and $day should be set, for a weekly or yearly event, respectively. |
157 |
respectively. |
|
|
158 |
|
142 |
|
159 |
=cut |
143 |
=cut |
160 |
|
144 |
|
161 |
sub _get_compare { |
|
|
162 |
my ( $colname, $value ) = @_; |
163 |
|
164 |
return ' AND ' . $colname . ' ' . ( defined( $value ) ? '=' : 'IS' ) . ' ?'; |
165 |
} |
166 |
|
167 |
sub ModRepeatingEvent { |
145 |
sub ModRepeatingEvent { |
168 |
my ( $branchcode, $info ) = @_; |
146 |
my ( $branchcode, $weekday, $month, $day, $info ) = @_; |
169 |
|
147 |
|
170 |
my $dbh = C4::Context->dbh; |
148 |
C4::Context->dbh->do( q{ |
171 |
my $open = ( $info->{close_hour} != 0 ); |
149 |
INSERT INTO calendar_repeats(branchcode, weekday, month, day, open_hour, open_minute, close_hour, close_minute, title, description) |
172 |
|
150 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
173 |
if ($open) { |
151 |
ON DUPLICATE KEY UPDATE open_hour = ?, open_minute = ?, close_hour = ?, close_minute = ?, title = ?, description = ? |
174 |
$dbh->do( q{ |
152 |
}, {}, $branchcode, $weekday, $month, $day, ( map { $info->{$_} } qw(open_hour open_minute close_hour close_minute title description) ) x 2 ); |
175 |
DELETE FROM repeatable_holidays |
|
|
176 |
WHERE branchcode = ? |
177 |
} . _get_compare( 'weekday', $info->{weekday} ) . _get_compare( 'month', $info->{month} ) . _get_compare( 'day', $info->{day} ), {}, $branchcode, $info->{weekday}, $info->{month}, $info->{day} ); |
178 |
} else { |
179 |
my @args = ( ( map { $info->{$_} } qw(title description) ), $branchcode, $info->{weekday}, $info->{month}, $info->{day} ); |
180 |
|
181 |
# The code below relies on $dbh->do returning 0 when the update affects no rows |
182 |
my $affected = $dbh->do( q{ |
183 |
UPDATE repeatable_holidays |
184 |
SET |
185 |
title = ?, description = ? |
186 |
WHERE branchcode = ? |
187 |
} . _get_compare( 'weekday', $info->{weekday} ) . _get_compare( 'month', $info->{month} ) . _get_compare( 'day', $info->{day} ), {}, @args ); |
188 |
|
189 |
$dbh->do( q{ |
190 |
INSERT |
191 |
INTO repeatable_holidays(title, description, branchcode, weekday, month, day) |
192 |
VALUES (?, ?, ?, ?, ?, ?) |
193 |
}, {}, @args ) unless ( $affected > 0 ); |
194 |
} |
195 |
} |
153 |
} |
196 |
|
154 |
|
197 |
=head2 DelSingleEvent |
155 |
=head2 DelSingleEvent |
198 |
|
156 |
|
199 |
DelSingleEvent( $branchcode, \%info ) |
157 |
DelSingleEvent( $branchcode, $date, \%info ) |
200 |
|
158 |
|
201 |
Deletes an event for a single date. $info->{date} should be an ISO-formatted date string. |
159 |
Deletes an event for a single date. $date should be an ISO-formatted date string. |
202 |
|
160 |
|
203 |
=cut |
161 |
=cut |
204 |
|
162 |
|
205 |
sub DelSingleEvent { |
163 |
sub DelSingleEvent { |
206 |
my ( $branchcode, $info ) = @_; |
164 |
my ( $branchcode, $date ) = @_; |
207 |
|
|
|
208 |
my ( $year, $month, $day ) = ( $info->{date} =~ /(\d+)-(\d+)-(\d+)/ ); |
209 |
return unless ( $year && $month && $day ); |
210 |
|
165 |
|
211 |
C4::Context->dbh->do( q{ |
166 |
C4::Context->dbh->do( q{ |
212 |
DELETE FROM special_holidays |
167 |
DELETE FROM calendar_events |
213 |
WHERE branchcode = ? AND year = ? AND month = ? AND day = ? |
168 |
WHERE branchcode = ? AND event_date = ? |
214 |
}, {}, $branchcode, $year, $month, $day ); |
169 |
}, {}, $branchcode, $date ); |
|
|
170 |
} |
171 |
|
172 |
sub _get_compare { |
173 |
my ( $colname, $value ) = @_; |
174 |
|
175 |
return ' AND ' . $colname . ' ' . ( defined( $value ) ? '=' : 'IS' ) . ' ?'; |
215 |
} |
176 |
} |
216 |
|
177 |
|
217 |
=head2 DelRepeatingEvent |
178 |
=head2 DelRepeatingEvent |
218 |
|
179 |
|
219 |
DelRepeatingEvent( $branchcode, \%info ) |
180 |
DelRepeatingEvent( $branchcode, $weekday, $month, $day ) |
220 |
|
181 |
|
221 |
Deletes a weekly- or yearly-repeating event. Either $info->{weekday}, or |
182 |
Deletes a weekly- or yearly-repeating event. Either $weekday, or $month and |
222 |
$info->{month} and $info->{day} should be set, for a weekly or yearly event, |
183 |
$day should be set, for a weekly or yearly event, respectively. |
223 |
respectively. |
|
|
224 |
|
184 |
|
225 |
=cut |
185 |
=cut |
226 |
|
186 |
|
227 |
sub DelRepeatingEvent { |
187 |
sub DelRepeatingEvent { |
228 |
my ( $branchcode, $info ) = @_; |
188 |
my ( $branchcode, $weekday, $month, $day ) = @_; |
229 |
|
189 |
|
230 |
C4::Context->dbh->do( q{ |
190 |
C4::Context->dbh->do( q{ |
231 |
DELETE FROM repeatable_holidays |
191 |
DELETE FROM calendar_repeats |
232 |
WHERE branchcode = ? |
192 |
WHERE branchcode = ? |
233 |
} . _get_compare( 'weekday', $info->{weekday} ) . _get_compare( 'month', $info->{month} ) . _get_compare( 'day', $info->{day} ), {}, $branchcode, $info->{weekday}, $info->{month}, $info->{day} ); |
193 |
} . _get_compare( 'weekday', $weekday ) . _get_compare( 'month', $month ) . _get_compare( 'day', $day ), {}, $branchcode, $weekday, $month, $day ); |
234 |
} |
194 |
} |
235 |
|
195 |
|
236 |
=head2 CopyAllEvents |
196 |
=head2 CopyAllEvents |
Lines 245-260
sub CopyAllEvents {
Link Here
|
245 |
my ( $from_branchcode, $to_branchcode ) = @_; |
205 |
my ( $from_branchcode, $to_branchcode ) = @_; |
246 |
|
206 |
|
247 |
C4::Context->dbh->do( q{ |
207 |
C4::Context->dbh->do( q{ |
248 |
INSERT IGNORE INTO special_holidays(branchcode, year, month, day, isexception, title, description) |
208 |
INSERT IGNORE INTO calendar_events(branchcode, event_date, open_hour, open_minute, close_hour, close_minute, title, description) |
249 |
SELECT ?, year, month, day, isexception, title, description |
209 |
SELECT ?, event_date, open_hour, open_minute, close_hour, close_minute, title, description |
250 |
FROM special_holidays |
210 |
FROM calendar_events |
251 |
WHERE branchcode = ? |
211 |
WHERE branchcode = ? |
252 |
}, {}, $to_branchcode, $from_branchcode ); |
212 |
}, {}, $to_branchcode, $from_branchcode ); |
253 |
|
213 |
|
254 |
C4::Context->dbh->do( q{ |
214 |
C4::Context->dbh->do( q{ |
255 |
INSERT IGNORE INTO repeatable_holidays(branchcode, weekday, month, day, title, description) |
215 |
INSERT IGNORE INTO calendar_repeats(branchcode, weekday, month, day, open_hour, open_minute, close_hour, close_minute, title, description) |
256 |
SELECT ?, weekday, month, day, title, description |
216 |
SELECT ?, weekday, month, day, open_hour, open_minute, close_hour, close_minute, title, description |
257 |
FROM repeatable_holidays |
217 |
FROM calendar_repeats |
258 |
WHERE branchcode = ? |
218 |
WHERE branchcode = ? |
259 |
}, {}, $to_branchcode, $from_branchcode ); |
219 |
}, {}, $to_branchcode, $from_branchcode ); |
260 |
} |
220 |
} |
Lines 267-272
__END__
Link Here
|
267 |
=head1 AUTHOR |
227 |
=head1 AUTHOR |
268 |
|
228 |
|
269 |
Koha Physics Library UNLP <matias_veleda@hotmail.com> |
229 |
Koha Physics Library UNLP <matias_veleda@hotmail.com> |
270 |
Jesse Weaver <jweaver@bywatersolutions.com> |
|
|
271 |
|
230 |
|
272 |
=cut |
231 |
=cut |