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

(-)a/Koha/Library/Hour.pm (+43 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 API
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 _type
36
37
=cut
38
39
sub _type {
40
    return 'BranchHour';
41
}
42
43
1;
(-)a/Koha/Library/Hours.pm (+52 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
=cut
39
40
sub _type {
41
    return 'BranchHour';
42
}
43
44
=head3 object_class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::Library::Hour';
50
}
51
52
1;
(-)a/admin/branches.pl (-2 / +43 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 $library;
54
    if ($branchcode) {
55
        $library = Koha::Libraries->find($branchcode);
56
        $template->param( selected_smtp_server => $library->smtp_server );
57
    }
58
59
    my @smtp_servers = Koha::SMTP::Servers->search;
60
    my @opening_hours = Koha::Library::Hours->search({ branchcode => $branchcode }, { order_by => { -asc => 'day' } });
61
52
    $template->param(
62
    $template->param(
53
        library      => Koha::Libraries->find($branchcode),
63
        library      => $library,
54
        smtp_servers => Koha::SMTP::Servers->search,
64
        smtp_servers => \@smtp_servers,
65
        opening_hours => \@opening_hours
55
    );
66
    );
56
} elsif ( $branchcode && $op eq 'view' ) {
67
} elsif ( $branchcode && $op eq 'view' ) {
57
    my $library = Koha::Libraries->find($branchcode);
68
    my $library = Koha::Libraries->find($branchcode);
Lines 114-119 if ( $op eq 'add_form' ) { Link Here
114
                        }
125
                        }
115
                    }
126
                    }
116
127
128
                    my @days = $input->multi_param("day");
129
                    my @open_times = $input->multi_param("open_time");
130
                    my @close_times = $input->multi_param("close_time");
131
132
                    foreach my $day ( @days ) {
133
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
134
                            $open_times[$day] = undef;
135
                        }
136
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
137
                            $close_times[$day] = undef;
138
                        }
139
140
                        my $openday = Koha::Library::Hours->find({ branchcode => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] });
141
                    }
142
117
                    push @messages, { type => 'message', code => 'success_on_update' };
143
                    push @messages, { type => 'message', code => 'success_on_update' };
118
                }
144
                }
119
            );
145
            );
Lines 152-157 if ( $op eq 'add_form' ) { Link Here
152
                        }
178
                        }
153
                    }
179
                    }
154
180
181
                    my @days = $input->multi_param("day");
182
                    my @open_times = $input->multi_param("open_time");
183
                    my @close_times = $input->multi_param("close_time");
184
185
                    foreach my $day ( @days ) {
186
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
187
                            $open_times[$day] = undef;
188
                        }
189
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
190
                            $close_times[$day] = undef;
191
                        }
192
193
                        my $openday = Koha::Library::Hour->new({ branchcode => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store;
194
                    }
195
155
                    push @messages, { type => 'message', code => 'success_on_insert' };
196
                    push @messages, { type => 'message', code => 'success_on_insert' };
156
                }
197
                }
157
            );
198
            );
(-)a/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl (+20 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if ( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{ DROP TABLE IF EXISTS branch_hours });
4
    $dbh->do(q{
5
        CREATE TABLE branch_hours (
6
            branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
7
            day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0,
8
            open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
9
            close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
10
            PRIMARY KEY (branchcode, day),
11
            CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
12
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
13
    });
14
15
    my @indexes = (0..6);
16
    for my $i (@indexes) {
17
        $dbh->do(q{ INSERT INTO branch_hours (branchcode, day) SELECT branchcode, ? FROM branches }, undef, $i);
18
    }
19
    NewVersion( $DBversion, 6796, "Add branch_hours table" );
20
}
(-)a/installer/data/mysql/kohastructure.sql (+16 lines)
Lines 1543-1548 CREATE TABLE `branches` ( Link Here
1543
/*!40101 SET character_set_client = @saved_cs_client */;
1543
/*!40101 SET character_set_client = @saved_cs_client */;
1544
1544
1545
--
1545
--
1546
-- Table structure for table `branch_hours`
1547
--
1548
DROP TABLE IF EXISTS branch_hours;
1549
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1550
/*!40101 SET character_set_client = utf8 */;
1551
CREATE TABLE branch_hours (
1552
    branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1553
    day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0,
1554
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1555
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1556
    PRIMARY KEY (branchcode, day),
1557
    CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
1558
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1559
/*!40101 SET character_set_client = @saved_cs_client */;
1560
1561
--
1546
-- Table structure for table `branches_overdrive`
1562
-- Table structure for table `branches_overdrive`
1547
--
1563
--
1548
1564
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +73 lines)
Lines 288-293 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
288
                    </select>
288
                    </select>
289
                    <div class="hint">Set to 'yes' to show this library as a search option and on the Libraries page in the OPAC.</div>
289
                    <div class="hint">Set to 'yes' to show this library as a search option and on the Libraries page in the OPAC.</div>
290
                </li>
290
                </li>
291
                <li>
292
                    <label for="opening_hours">Opening hours: </label>
293
                    <table id="opening_hours_table">
294
                        <thead>
295
                            <tr>
296
                                <th>Day</th>
297
                                <th>Open time</th>
298
                                <th>Close time</th>
299
                            </tr>
300
                        </thead>
301
                        <tbody>
302
                            [% IF opening_hours # Existing library %]
303
                                [% daycount = 0 %]
304
                                [% FOREACH hr IN opening_hours %]
305
                                <tr id="hours_[% daycount %]">
306
                                    <td>
307
                                        [% PROCESS dayname day=daycount %]
308
                                        <input type="hidden" value="[% daycount %]" name="day">
309
                                    </td>
310
                                    <td>
311
                                        [% IF hr.day == daycount && hr.open_time %]
312
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
313
                                        [% ELSE %]
314
                                        <input type="time" value="" name="open_time">
315
                                        [% END %]
316
                                    </td>
317
                                    <td>
318
                                        [% IF hr.day == daycount && hr.close_time %]
319
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
320
                                        [% ELSE %]
321
                                        <input type="time" value="" name="close_time">
322
                                        [% END %]
323
                                    </td>
324
                                </tr>
325
                                [% daycount = daycount+1 %]
326
                                [% END %]
327
                            [% ELSE # New library %]
328
                                [% FOREACH daycount IN [0..6] %]
329
                                <tr id="hours_[% day %]">
330
                                    <td>
331
                                        [% PROCESS dayname day=daycount %]
332
                                        <input type="hidden" value="[% daycount %]" name="day">
333
                                    </td>
334
                                    <td>
335
                                        <input type="time" value="" name="open_time">
336
                                    </td>
337
                                    <td>
338
                                        <input type="time" value="" name="close_time">
339
                                    </td>
340
                                </tr>
341
                                [% END %]
342
                            [% END %]
343
                        </tbody>
344
                    </table>
345
                </li>
291
            </ol>
346
            </ol>
292
        </fieldset>
347
        </fieldset>
293
        <fieldset class="action">
348
        <fieldset class="action">
Lines 297-302 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
297
    </form>
352
    </form>
298
[% END %]
353
[% END %]
299
354
355
[% BLOCK dayname %]
356
    [% IF day == 0 %]
357
    Monday
358
    [% ELSIF day == 1 %]
359
    Tuesday
360
    [% ELSIF day == 2 %]
361
    Wednesday
362
    [% ELSIF day == 3 %]
363
    Thursday
364
    [% ELSIF day == 4 %]
365
    Friday
366
    [% ELSIF day == 5 %]
367
    Saturday
368
    [% ELSE %]
369
    Sunday
370
    [% END %]
371
[% END %]
372
300
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
373
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
301
    <div class="dialog alert">
374
    <div class="dialog alert">
302
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
375
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
303
- 

Return to bug 6796