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 116-121 if ( $op eq 'add_form' ) { Link Here
116
                        }
120
                        }
117
                    }
121
                    }
118
122
123
                    my @days = $input->multi_param("day");
124
                    my @open_times = $input->multi_param("open_time");
125
                    my @close_times = $input->multi_param("close_time");
126
127
                    foreach my $day ( @days ) {
128
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
129
                            $open_times[$day] = undef;
130
                        }
131
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
132
                            $close_times[$day] = undef;
133
                        }
134
135
                        my $openday = Koha::Library::Hours->find({ library_id => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] });
136
                    }
137
119
                    push @messages, { type => 'message', code => 'success_on_update' };
138
                    push @messages, { type => 'message', code => 'success_on_update' };
120
                }
139
                }
121
            );
140
            );
Lines 154-159 if ( $op eq 'add_form' ) { Link Here
154
                        }
173
                        }
155
                    }
174
                    }
156
175
176
                    my @days = $input->multi_param("day");
177
                    my @open_times = $input->multi_param("open_time");
178
                    my @close_times = $input->multi_param("close_time");
179
180
                    foreach my $day ( @days ) {
181
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
182
                            $open_times[$day] = undef;
183
                        }
184
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
185
                            $close_times[$day] = undef;
186
                        }
187
188
                        my $openday = Koha::Library::Hour->new({ library_id => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store;
189
                    }
190
157
                    push @messages, { type => 'message', code => 'success_on_insert' };
191
                    push @messages, { type => 'message', code => 'success_on_insert' };
158
                }
192
                }
159
            );
193
            );
(-)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 4270-4275 CREATE TABLE `letter` ( Link Here
4270
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4270
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4271
/*!40101 SET character_set_client = @saved_cs_client */;
4271
/*!40101 SET character_set_client = @saved_cs_client */;
4272
4272
4273
--
4274
-- Table structure for table `library_hours`
4275
--
4276
DROP TABLE IF EXISTS library_hours;
4277
CREATE TABLE library_hours (
4278
    library_id varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
4279
    day enum('0','1','2','3','4','5','6') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0',
4280
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4281
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4282
    PRIMARY KEY (library_id, day),
4283
    CONSTRAINT library_hours_ibfk_1 FOREIGN KEY (library_id) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
4284
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4285
4273
--
4286
--
4274
-- Table structure for table `library_groups`
4287
-- Table structure for table `library_groups`
4275
--
4288
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +72 lines)
Lines 306-311 Link Here
306
                        <a class="collapse-textarea" id="collapse_opacusercss" data-target="opacusercss" data-syntax="css" style="display:none" href="#">Collapse</br></a>
306
                        <a class="collapse-textarea" id="collapse_opacusercss" data-target="opacusercss" data-syntax="css" style="display:none" href="#">Collapse</br></a>
307
                    </div>
307
                    </div>
308
                </li>
308
                </li>
309
                <li>
310
                    <label for="opening_hours">Opening hours: </label>
311
                    <table id="opening_hours_table">
312
                        <thead>
313
                            <tr>
314
                                <th>Day</th>
315
                                <th>Open time</th>
316
                                <th>Close time</th>
317
                            </tr>
318
                        </thead>
319
                        <tbody>
320
                            [% IF opening_hours # Existing library %]
321
                                [% daycount = 0 %]
322
                                [% FOREACH hr IN opening_hours %]
323
                                <tr id="hours_[% daycount %]">
324
                                    <td>
325
                                        [% PROCESS dayname day=daycount %]
326
                                        <input type="hidden" value="[% daycount %]" name="day">
327
                                    </td>
328
                                    <td>
329
                                        [% IF hr.day == daycount && hr.open_time %]
330
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
331
                                        [% ELSE %]
332
                                        <input type="time" value="" name="open_time">
333
                                        [% END %]
334
                                    </td>
335
                                    <td>
336
                                        [% IF hr.day == daycount && hr.close_time %]
337
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
338
                                        [% ELSE %]
339
                                        <input type="time" value="" name="close_time">
340
                                        [% END %]
341
                                    </td>
342
                                </tr>
343
                                [% daycount = daycount+1 %]
344
                                [% END %]
345
                            [% ELSE # New library %]
346
                                [% FOREACH daycount IN [0..6] %]
347
                                <tr id="hours_[% day %]">
348
                                    <td>
349
                                        [% PROCESS dayname day=daycount %]
350
                                        <input type="hidden" value="[% daycount %]" name="day">
351
                                    </td>
352
                                    <td>
353
                                        <input type="time" value="" name="open_time">
354
                                    </td>
355
                                    <td>
356
                                        <input type="time" value="" name="close_time">
357
                                    </td>
358
                                </tr>
359
                                [% END %]
360
                            [% END %]
361
                        </tbody>
362
                    </table>
309
                </li>
363
                </li>
310
            </ol>
364
            </ol>
311
        </fieldset>
365
        </fieldset>
Lines 316-321 Link Here
316
    </form>
370
    </form>
317
[% END %]
371
[% END %]
318
372
373
[% BLOCK dayname %]
374
    [% IF day == 0 %]
375
    <span>Monday</span>
376
    [% ELSIF day == 1 %]
377
    <span>Tuesday</span>
378
    [% ELSIF day == 2 %]
379
    <span>Wednesday</span>
380
    [% ELSIF day == 3 %]
381
    <span>Thursday</span>
382
    [% ELSIF day == 4 %]
383
    <span>Friday</span>
384
    [% ELSIF day == 5 %]
385
    <span>Saturday</span>
386
    [% ELSE %]
387
    <span>Sunday</span>
388
    [% END %]
389
[% END %]
390
319
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
391
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
320
    <div class="dialog alert">
392
    <div class="dialog alert">
321
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
393
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
322
- 

Return to bug 6796