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

(-)a/Koha/Library/Hour.pm (+51 lines)
Line 0 Link Here
1
package Koha::Library::Hour;
2
3
# Copyright 2021 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
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Koha::Database;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::Library::Hour - Koha Library Hour Object class
28
29
=head1 SYNOPSIS
30
31
use Koha::Library::Hour;
32
33
=head1 DESCRIPTION
34
35
Describes the open time and close time for a library on a given day of the week.
36
37
=head1 FUNCTIONS
38
39
=head2 Class Methods
40
41
=head3 _type
42
43
Return type of Object relating to Schema Resultset
44
45
=cut
46
47
sub _type {
48
    return 'LibraryHour';
49
}
50
51
1;
(-)a/Koha/Library/Hours.pm (+56 lines)
Line 0 Link Here
1
package Koha::Library::Hours;
2
3
# Copyright 2021 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
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Koha::Database;
22
use Koha::Library::Hour;
23
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::Library::Hours - Koha Library Hours Object set class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 _type
37
38
Return type of object, relating to Schema Resultset
39
40
=cut
41
42
sub _type {
43
    return 'LibraryHour';
44
}
45
46
=head3 object_class
47
48
Return object class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Library::Hour';
54
}
55
56
1;
(-)a/admin/branches.pl (+34 lines)
Lines 33-38 use Koha::Patrons; Link Here
33
use Koha::Items;
33
use Koha::Items;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::SMTP::Servers;
35
use Koha::SMTP::Servers;
36
use Koha::Library::Hours;
36
37
37
my $input        = CGI->new;
38
my $input        = CGI->new;
38
my $branchcode   = $input->param('branchcode');
39
my $branchcode   = $input->param('branchcode');
Lines 49-57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
49
);
50
);
50
51
51
if ( $op eq 'add_form' ) {
52
if ( $op eq 'add_form' ) {
53
    my @opening_hours = Koha::Library::Hours->search({ library_id => $branchcode }, { order_by => { -asc => 'day' } })->as_list;
54
52
    $template->param(
55
    $template->param(
53
        library      => Koha::Libraries->find($branchcode),
56
        library      => Koha::Libraries->find($branchcode),
54
        smtp_servers => Koha::SMTP::Servers->search,
57
        smtp_servers => Koha::SMTP::Servers->search,
58
        opening_hours => \@opening_hours
55
    );
59
    );
56
} elsif ( $branchcode && $op eq 'view' ) {
60
} elsif ( $branchcode && $op eq 'view' ) {
57
    my $library = Koha::Libraries->find($branchcode);
61
    my $library = Koha::Libraries->find($branchcode);
Lines 114-119 if ( $op eq 'add_form' ) { Link Here
114
                        }
118
                        }
115
                    }
119
                    }
116
120
121
                    my @days = $input->multi_param("day");
122
                    my @open_times = $input->multi_param("open_time");
123
                    my @close_times = $input->multi_param("close_time");
124
125
                    foreach my $day ( @days ) {
126
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
127
                            $open_times[$day] = undef;
128
                        }
129
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
130
                            $close_times[$day] = undef;
131
                        }
132
133
                        my $openday = Koha::Library::Hours->find({ library_id => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] });
134
                    }
135
117
                    push @messages, { type => 'message', code => 'success_on_update' };
136
                    push @messages, { type => 'message', code => 'success_on_update' };
118
                }
137
                }
119
            );
138
            );
Lines 152-157 if ( $op eq 'add_form' ) { Link Here
152
                        }
171
                        }
153
                    }
172
                    }
154
173
174
                    my @days = $input->multi_param("day");
175
                    my @open_times = $input->multi_param("open_time");
176
                    my @close_times = $input->multi_param("close_time");
177
178
                    foreach my $day ( @days ) {
179
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
180
                            $open_times[$day] = undef;
181
                        }
182
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
183
                            $close_times[$day] = undef;
184
                        }
185
186
                        my $openday = Koha::Library::Hour->new({ library_id => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store;
187
                    }
188
155
                    push @messages, { type => 'message', code => 'success_on_insert' };
189
                    push @messages, { type => 'message', code => 'success_on_insert' };
156
                }
190
                }
157
            );
191
            );
(-)a/installer/data/mysql/atomicupdate/bug_6796_-_add_library_hours_table.pl (+35 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "6796",
5
    description => "Overnight checkouts taking into account opening and closing hours",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        unless ( TableExists('library_hours') ) {
11
            $dbh->do(
12
                q{
13
                CREATE TABLE library_hours (
14
                    library_id varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
15
                    day enum('0','1','2','3','4','5','6') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0',
16
                    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
17
                    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
18
                    PRIMARY KEY (library_id, day),
19
                    CONSTRAINT library_hours FOREIGN KEY (library_id) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
20
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
21
            }
22
            );
23
24
            my @indexes = ( 0 .. 6 );
25
            for my $i (@indexes) {
26
                $dbh->do(
27
                    q{ INSERT INTO library_hours (library_id, day) SELECT branchcode, ? FROM branches }, undef,
28
                    $i
29
                );
30
            }
31
32
            say $out "Added table `library_hours`";
33
        }
34
    },
35
};
(-)a/installer/data/mysql/kohastructure.sql (+13 lines)
Lines 3933-3938 CREATE TABLE `letter` ( Link Here
3933
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3933
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3934
/*!40101 SET character_set_client = @saved_cs_client */;
3934
/*!40101 SET character_set_client = @saved_cs_client */;
3935
3935
3936
--
3937
-- Table structure for table `library_hours`
3938
--
3939
DROP TABLE IF EXISTS library_hours;
3940
CREATE TABLE library_hours (
3941
    library_id varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
3942
    day enum('0','1','2','3','4','5','6') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0',
3943
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
3944
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
3945
    PRIMARY KEY (library_id, day),
3946
    CONSTRAINT library_hours_ibfk_1 FOREIGN KEY (library_id) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
3947
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3948
3936
--
3949
--
3937
-- Table structure for table `library_groups`
3950
-- Table structure for table `library_groups`
3938
--
3951
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +73 lines)
Lines 286-291 Link Here
286
                    </select>
286
                    </select>
287
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
287
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
288
                </li>
288
                </li>
289
                <li>
290
                    <label for="opening_hours">Opening hours: </label>
291
                    <table id="opening_hours_table">
292
                        <thead>
293
                            <tr>
294
                                <th>Day</th>
295
                                <th>Open time</th>
296
                                <th>Close time</th>
297
                            </tr>
298
                        </thead>
299
                        <tbody>
300
                            [% IF opening_hours # Existing library %]
301
                                [% daycount = 0 %]
302
                                [% FOREACH hr IN opening_hours %]
303
                                <tr id="hours_[% daycount %]">
304
                                    <td>
305
                                        [% PROCESS dayname day=daycount %]
306
                                        <input type="hidden" value="[% daycount %]" name="day">
307
                                    </td>
308
                                    <td>
309
                                        [% IF hr.day == daycount && hr.open_time %]
310
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
311
                                        [% ELSE %]
312
                                        <input type="time" value="" name="open_time">
313
                                        [% END %]
314
                                    </td>
315
                                    <td>
316
                                        [% IF hr.day == daycount && hr.close_time %]
317
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
318
                                        [% ELSE %]
319
                                        <input type="time" value="" name="close_time">
320
                                        [% END %]
321
                                    </td>
322
                                </tr>
323
                                [% daycount = daycount+1 %]
324
                                [% END %]
325
                            [% ELSE # New library %]
326
                                [% FOREACH daycount IN [0..6] %]
327
                                <tr id="hours_[% day %]">
328
                                    <td>
329
                                        [% PROCESS dayname day=daycount %]
330
                                        <input type="hidden" value="[% daycount %]" name="day">
331
                                    </td>
332
                                    <td>
333
                                        <input type="time" value="" name="open_time">
334
                                    </td>
335
                                    <td>
336
                                        <input type="time" value="" name="close_time">
337
                                    </td>
338
                                </tr>
339
                                [% END %]
340
                            [% END %]
341
                        </tbody>
342
                    </table>
343
                </li>
289
            </ol>
344
            </ol>
290
        </fieldset>
345
        </fieldset>
291
        <fieldset class="action">
346
        <fieldset class="action">
Lines 295-300 Link Here
295
    </form>
350
    </form>
296
[% END %]
351
[% END %]
297
352
353
[% BLOCK dayname %]
354
    [% IF day == 0 %]
355
    <span>Monday</span>
356
    [% ELSIF day == 1 %]
357
    <span>Tuesday</span>
358
    [% ELSIF day == 2 %]
359
    <span>Wednesday</span>
360
    [% ELSIF day == 3 %]
361
    <span>Thursday</span>
362
    [% ELSIF day == 4 %]
363
    <span>Friday</span>
364
    [% ELSIF day == 5 %]
365
    <span>Saturday</span>
366
    [% ELSE %]
367
    <span>Sunday</span>
368
    [% END %]
369
[% END %]
370
298
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
371
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
299
    <div class="dialog alert">
372
    <div class="dialog alert">
300
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
373
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
301
- 

Return to bug 6796