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 ( $op eq 'add_validate' ) {
67
} elsif ( $op eq 'add_validate' ) {
57
    my @fields = qw(
68
    my @fields = qw(
Lines 110-115 if ( $op eq 'add_form' ) { Link Here
110
                        }
121
                        }
111
                    }
122
                    }
112
123
124
                    my @days = $input->multi_param("day");
125
                    my @open_times = $input->multi_param("open_time");
126
                    my @close_times = $input->multi_param("close_time");
127
128
                    foreach my $day ( @days ) {
129
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
130
                            $open_times[$day] = undef;
131
                        }
132
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
133
                            $close_times[$day] = undef;
134
                        }
135
136
                        my $openday = Koha::Library::Hours->find({ branchcode => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] });
137
                    }
138
113
                    push @messages, { type => 'message', code => 'success_on_update' };
139
                    push @messages, { type => 'message', code => 'success_on_update' };
114
                }
140
                }
115
            );
141
            );
Lines 148-153 if ( $op eq 'add_form' ) { Link Here
148
                        }
174
                        }
149
                    }
175
                    }
150
176
177
                    my @days = $input->multi_param("day");
178
                    my @open_times = $input->multi_param("open_time");
179
                    my @close_times = $input->multi_param("close_time");
180
181
                    foreach my $day ( @days ) {
182
                        if ( $open_times[$day] and $open_times[$day] eq '' ) {
183
                            $open_times[$day] = undef;
184
                        }
185
                        if ( $close_times[$day] and $close_times[$day] eq '' ) {
186
                            $close_times[$day] = undef;
187
                        }
188
189
                        my $openday = Koha::Library::Hour->new({ branchcode => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store;
190
                    }
191
151
                    push @messages, { type => 'message', code => 'success_on_insert' };
192
                    push @messages, { type => 'message', code => 'success_on_insert' };
152
                }
193
                }
153
            );
194
            );
(-)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 1525-1530 CREATE TABLE `branches` ( Link Here
1525
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1525
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1526
/*!40101 SET character_set_client = @saved_cs_client */;
1526
/*!40101 SET character_set_client = @saved_cs_client */;
1527
1527
1528
--
1529
-- Table structure for table `branch_hours`
1530
--
1531
DROP TABLE IF EXISTS branch_hours;
1532
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1533
/*!40101 SET character_set_client = utf8 */;
1534
CREATE TABLE branch_hours (
1535
    branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1536
    day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0,
1537
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1538
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1539
    PRIMARY KEY (branchcode, day),
1540
    CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
1541
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1542
/*!40101 SET character_set_client = @saved_cs_client */;
1543
1528
--
1544
--
1529
-- Table structure for table `branches_overdrive`
1545
-- Table structure for table `branches_overdrive`
1530
--
1546
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +72 lines)
Lines 276-281 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
276
                        [% END %]
276
                        [% END %]
277
                    </select>
277
                    </select>
278
                    <div class="hint">Set to 'yes' to show this library on the Libraries page in the OPAC.</div>
278
                    <div class="hint">Set to 'yes' to show this library on the Libraries page in the OPAC.</div>
279
                <li>
280
                    <label for="opening_hours">Opening hours: </label>
281
                    <table id="opening_hours_table">
282
                        <thead>
283
                            <tr>
284
                                <th>Day</th>
285
                                <th>Open time</th>
286
                                <th>Close time</th>
287
                            </tr>
288
                        </thead>
289
                        <tbody>
290
                            [% IF opening_hours # Existing library %]
291
                                [% daycount = 0 %]
292
                                [% FOREACH hr IN opening_hours %]
293
                                <tr id="hours_[% daycount %]">
294
                                    <td>
295
                                        [% PROCESS dayname day=daycount %]
296
                                        <input type="hidden" value="[% daycount %]" name="day">
297
                                    </td>
298
                                    <td>
299
                                        [% IF hr.day == daycount && hr.open_time %]
300
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
301
                                        [% ELSE %]
302
                                        <input type="time" value="" name="open_time">
303
                                        [% END %]
304
                                    </td>
305
                                    <td>
306
                                        [% IF hr.day == daycount && hr.close_time %]
307
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
308
                                        [% ELSE %]
309
                                        <input type="time" value="" name="close_time">
310
                                        [% END %]
311
                                    </td>
312
                                </tr>
313
                                [% daycount = daycount+1 %]
314
                                [% END %]
315
                            [% ELSE # New library %]
316
                                [% FOREACH daycount IN [0..6] %]
317
                                <tr id="hours_[% day %]">
318
                                    <td>
319
                                        [% PROCESS dayname day=daycount %]
320
                                        <input type="hidden" value="[% daycount %]" name="day">
321
                                    </td>
322
                                    <td>
323
                                        <input type="time" value="" name="open_time">
324
                                    </td>
325
                                    <td>
326
                                        <input type="time" value="" name="close_time">
327
                                    </td>
328
                                </tr>
329
                                [% END %]
330
                            [% END %]
331
                        </tbody>
332
                    </table>
279
                </li>
333
                </li>
280
            </ol>
334
            </ol>
281
        </fieldset>
335
        </fieldset>
Lines 286-291 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
286
    </form>
340
    </form>
287
[% END %]
341
[% END %]
288
342
343
[% BLOCK dayname %]
344
    [% IF day == 0 %]
345
    Monday
346
    [% ELSIF day == 1 %]
347
    Tuesday
348
    [% ELSIF day == 2 %]
349
    Wednesday
350
    [% ELSIF day == 3 %]
351
    Thursday
352
    [% ELSIF day == 4 %]
353
    Friday
354
    [% ELSIF day == 5 %]
355
    Saturday
356
    [% ELSE %]
357
    Sunday
358
    [% END %]
359
[% END %]
360
289
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
361
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
290
    <div class="dialog alert">
362
    <div class="dialog alert">
291
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
363
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
292
- 

Return to bug 6796