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 (+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({ branchcode => $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({ branchcode => $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({ branchcode => $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_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 1562-1567 CREATE TABLE `branches` ( Link Here
1562
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1562
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1563
/*!40101 SET character_set_client = @saved_cs_client */;
1563
/*!40101 SET character_set_client = @saved_cs_client */;
1564
1564
1565
--
1566
-- Table structure for table `branch_hours`
1567
--
1568
DROP TABLE IF EXISTS branch_hours;
1569
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1570
/*!40101 SET character_set_client = utf8 */;
1571
CREATE TABLE branch_hours (
1572
    branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1573
    day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0,
1574
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1575
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1576
    PRIMARY KEY (branchcode, day),
1577
    CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
1578
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1579
/*!40101 SET character_set_client = @saved_cs_client */;
1580
1565
--
1581
--
1566
-- Table structure for table `branches_overdrive`
1582
-- Table structure for table `branches_overdrive`
1567
--
1583
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +73 lines)
Lines 275-280 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
275
                    </select>
275
                    </select>
276
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
276
                    <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
277
                </li>
277
                </li>
278
                <li>
279
                    <label for="opening_hours">Opening hours: </label>
280
                    <table id="opening_hours_table">
281
                        <thead>
282
                            <tr>
283
                                <th>Day</th>
284
                                <th>Open time</th>
285
                                <th>Close time</th>
286
                            </tr>
287
                        </thead>
288
                        <tbody>
289
                            [% IF opening_hours # Existing library %]
290
                                [% daycount = 0 %]
291
                                [% FOREACH hr IN opening_hours %]
292
                                <tr id="hours_[% daycount %]">
293
                                    <td>
294
                                        [% PROCESS dayname day=daycount %]
295
                                        <input type="hidden" value="[% daycount %]" name="day">
296
                                    </td>
297
                                    <td>
298
                                        [% IF hr.day == daycount && hr.open_time %]
299
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
300
                                        [% ELSE %]
301
                                        <input type="time" value="" name="open_time">
302
                                        [% END %]
303
                                    </td>
304
                                    <td>
305
                                        [% IF hr.day == daycount && hr.close_time %]
306
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
307
                                        [% ELSE %]
308
                                        <input type="time" value="" name="close_time">
309
                                        [% END %]
310
                                    </td>
311
                                </tr>
312
                                [% daycount = daycount+1 %]
313
                                [% END %]
314
                            [% ELSE # New library %]
315
                                [% FOREACH daycount IN [0..6] %]
316
                                <tr id="hours_[% day %]">
317
                                    <td>
318
                                        [% PROCESS dayname day=daycount %]
319
                                        <input type="hidden" value="[% daycount %]" name="day">
320
                                    </td>
321
                                    <td>
322
                                        <input type="time" value="" name="open_time">
323
                                    </td>
324
                                    <td>
325
                                        <input type="time" value="" name="close_time">
326
                                    </td>
327
                                </tr>
328
                                [% END %]
329
                            [% END %]
330
                        </tbody>
331
                    </table>
332
                </li>
278
            </ol>
333
            </ol>
279
        </fieldset>
334
        </fieldset>
280
        <fieldset class="action">
335
        <fieldset class="action">
Lines 284-289 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
284
    </form>
339
    </form>
285
[% END %]
340
[% END %]
286
341
342
[% BLOCK dayname %]
343
    [% IF day == 0 %]
344
    Monday
345
    [% ELSIF day == 1 %]
346
    Tuesday
347
    [% ELSIF day == 2 %]
348
    Wednesday
349
    [% ELSIF day == 3 %]
350
    Thursday
351
    [% ELSIF day == 4 %]
352
    Friday
353
    [% ELSIF day == 5 %]
354
    Saturday
355
    [% ELSE %]
356
    Sunday
357
    [% END %]
358
[% END %]
359
287
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
360
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
288
    <div class="dialog alert">
361
    <div class="dialog alert">
289
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
362
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
290
- 

Return to bug 6796