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 (-2 / +73 lines)
Lines 289-294 Link Here
289
                    </select>
289
                    </select>
290
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
290
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
291
                </li>
291
                </li>
292
                <li>
293
                    <label for="opening_hours">Opening hours: </label>
294
                    <table id="opening_hours_table">
295
                        <thead>
296
                            <tr>
297
                                <th>Day</th>
298
                                <th>Open time</th>
299
                                <th>Close time</th>
300
                            </tr>
301
                        </thead>
302
                        <tbody>
303
                            [% IF opening_hours # Existing library %]
304
                                [% daycount = 0 %]
305
                                [% FOREACH hr IN opening_hours %]
306
                                <tr id="hours_[% daycount %]">
307
                                    <td>
308
                                        [% PROCESS dayname day=daycount %]
309
                                        <input type="hidden" value="[% daycount %]" name="day">
310
                                    </td>
311
                                    <td>
312
                                        [% IF hr.day == daycount && hr.open_time %]
313
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
314
                                        [% ELSE %]
315
                                        <input type="time" value="" name="open_time">
316
                                        [% END %]
317
                                    </td>
318
                                    <td>
319
                                        [% IF hr.day == daycount && hr.close_time %]
320
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
321
                                        [% ELSE %]
322
                                        <input type="time" value="" name="close_time">
323
                                        [% END %]
324
                                    </td>
325
                                </tr>
326
                                [% daycount = daycount+1 %]
327
                                [% END %]
328
                            [% ELSE # New library %]
329
                                [% FOREACH daycount IN [0..6] %]
330
                                <tr id="hours_[% day %]">
331
                                    <td>
332
                                        [% PROCESS dayname day=daycount %]
333
                                        <input type="hidden" value="[% daycount %]" name="day">
334
                                    </td>
335
                                    <td>
336
                                        <input type="time" value="" name="open_time">
337
                                    </td>
338
                                    <td>
339
                                        <input type="time" value="" name="close_time">
340
                                    </td>
341
                                </tr>
342
                                [% END %]
343
                            [% END %]
344
                        </tbody>
345
                    </table>
346
                </li>
292
                <li>
347
                <li>
293
                    <label for="opacuserjs">Specific OPAC JS: </label>
348
                    <label for="opacuserjs">Specific OPAC JS: </label>
294
                    <div style="display:flex; flex-direction:column;">
349
                    <div style="display:flex; flex-direction:column;">
Lines 305-311 Link Here
305
                        <a class="collapse-textarea" id="collapse_opacusercss" data-target="opacusercss" data-syntax="css" style="display:none" href="#">Collapse</br></a>
360
                        <a class="collapse-textarea" id="collapse_opacusercss" data-target="opacusercss" data-syntax="css" style="display:none" href="#">Collapse</br></a>
306
                    </div>
361
                    </div>
307
                </li>
362
                </li>
308
                </li>
309
            </ol>
363
            </ol>
310
        </fieldset>
364
        </fieldset>
311
        <fieldset class="action">
365
        <fieldset class="action">
Lines 315-320 Link Here
315
    </form>
369
    </form>
316
[% END %]
370
[% END %]
317
371
372
[% BLOCK dayname %]
373
    [% IF day == 0 %]
374
    <span>Monday</span>
375
    [% ELSIF day == 1 %]
376
    <span>Tuesday</span>
377
    [% ELSIF day == 2 %]
378
    <span>Wednesday</span>
379
    [% ELSIF day == 3 %]
380
    <span>Thursday</span>
381
    [% ELSIF day == 4 %]
382
    <span>Friday</span>
383
    [% ELSIF day == 5 %]
384
    <span>Saturday</span>
385
    [% ELSE %]
386
    <span>Sunday</span>
387
    [% END %]
388
[% END %]
389
318
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
390
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
319
    <div class="dialog alert">
391
    <div class="dialog alert">
320
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
392
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
321
- 

Return to bug 6796