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

(-)a/Koha/Library/Hour.pm (+44 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;
44
(-)a/Koha/Library/Hours.pm (+53 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;
53
(-)a/admin/branches.pl (-1 / +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 56-65 if ( $op eq 'add_form' ) { Link Here
56
    }
57
    }
57
58
58
    my @smtp_servers = Koha::SMTP::Servers->search;
59
    my @smtp_servers = Koha::SMTP::Servers->search;
60
    my @opening_hours = Koha::Library::Hours->search({ branchcode => $branchcode }, { order_by => { -asc => 'day' } });
59
61
60
    $template->param(
62
    $template->param(
61
        library      => $library,
63
        library      => $library,
62
        smtp_servers => \@smtp_servers
64
        smtp_servers => \@smtp_servers,
65
        opening_hours => \@opening_hours
63
    );
66
    );
64
} elsif ( $op eq 'add_validate' ) {
67
} elsif ( $op eq 'add_validate' ) {
65
    my @fields = qw(
68
    my @fields = qw(
Lines 117-122 if ( $op eq 'add_form' ) { Link Here
117
                        }
120
                        }
118
                    }
121
                    }
119
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({ branchcode => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] });
136
                    }
137
120
                    push @messages, { type => 'message', code => 'success_on_update' };
138
                    push @messages, { type => 'message', code => 'success_on_update' };
121
                }
139
                }
122
            );
140
            );
Lines 155-160 if ( $op eq 'add_form' ) { Link Here
155
                        }
173
                        }
156
                    }
174
                    }
157
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({ branchcode => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store;
189
                    }
190
158
                    push @messages, { type => 'message', code => 'success_on_insert' };
191
                    push @messages, { type => 'message', code => 'success_on_insert' };
159
                }
192
                }
160
            );
193
            );
(-)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 1488-1493 CREATE TABLE `branches` ( Link Here
1488
/*!40101 SET character_set_client = @saved_cs_client */;
1488
/*!40101 SET character_set_client = @saved_cs_client */;
1489
1489
1490
--
1490
--
1491
-- Table structure for table `branch_hours`
1492
--
1493
DROP TABLE IF EXISTS branch_hours;
1494
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1495
/*!40101 SET character_set_client = utf8 */;
1496
CREATE TABLE branch_hours (
1497
    branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1498
    day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0,
1499
    open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1500
    close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1501
    PRIMARY KEY (branchcode, day),
1502
    CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
1503
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1504
/*!40101 SET character_set_client = @saved_cs_client */;
1505
1506
--
1491
-- Table structure for table `branches_overdrive`
1507
-- Table structure for table `branches_overdrive`
1492
--
1508
--
1493
1509
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +73 lines)
Lines 265-270 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
265
                        [% END %]
265
                        [% END %]
266
                    </select>
266
                    </select>
267
                </li>
267
                </li>
268
                <li>
269
                    <label for="opening_hours">Opening hours: </label>
270
                    <table id="opening_hours_table">
271
                        <thead>
272
                            <tr>
273
                                <th>Day</th>
274
                                <th>Open time</th>
275
                                <th>Close time</th>
276
                            </tr>
277
                        </thead>
278
                        <tbody>
279
                            [% IF opening_hours # Existing library %]
280
                                [% daycount = 0 %]
281
                                [% FOREACH hr IN opening_hours %]
282
                                <tr id="hours_[% daycount %]">
283
                                    <td>
284
                                        [% PROCESS dayname day=daycount %]
285
                                        <input type="hidden" value="[% daycount %]" name="day">
286
                                    </td>
287
                                    <td>
288
                                        [% IF hr.day == daycount && hr.open_time %]
289
                                        <input type="time" value="[% hr.open_time %]" name="open_time">
290
                                        [% ELSE %]
291
                                        <input type="time" value="" name="open_time">
292
                                        [% END %]
293
                                    </td>
294
                                    <td>
295
                                        [% IF hr.day == daycount && hr.close_time %]
296
                                        <input type="time" value="[% hr.close_time %]" name="close_time">
297
                                        [% ELSE %]
298
                                        <input type="time" value="" name="close_time">
299
                                        [% END %]
300
                                    </td>
301
                                </tr>
302
                                [% daycount = daycount+1 %]
303
                                [% END %]
304
                            [% ELSE # New library %]
305
                                [% FOREACH daycount IN [0..6] %]
306
                                <tr id="hours_[% day %]">
307
                                    <td>
308
                                        [% PROCESS dayname day=daycount %]
309
                                        <input type="hidden" value="[% daycount %]" name="day">
310
                                    </td>
311
                                    <td>
312
                                        <input type="time" value="" name="open_time">
313
                                    </td>
314
                                    <td>
315
                                        <input type="time" value="" name="close_time">
316
                                    </td>
317
                                </tr>
318
                                [% END %]
319
                            [% END %]
320
                        </tbody>
321
                    </table>
322
                </li>
268
            </ol>
323
            </ol>
269
        </fieldset>
324
        </fieldset>
270
        <fieldset class="action">
325
        <fieldset class="action">
Lines 274-279 Libraries &rsaquo; Administration &rsaquo; Koha Link Here
274
    </form>
329
    </form>
275
[% END %]
330
[% END %]
276
331
332
[% BLOCK dayname %]
333
    [% IF day == 0 %]
334
    Monday
335
    [% ELSIF day == 1 %]
336
    Tuesday
337
    [% ELSIF day == 2 %]
338
    Wednesday
339
    [% ELSIF day == 3 %]
340
    Thursday
341
    [% ELSIF day == 4 %]
342
    Friday
343
    [% ELSIF day == 5 %]
344
    Saturday
345
    [% ELSE %]
346
    Sunday
347
    [% END %]
348
[% END %]
349
277
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
350
[% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
278
    <div class="dialog alert">
351
    <div class="dialog alert">
279
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
352
        <form action="/cgi-bin/koha/admin/branches.pl" method="post">
280
- 

Return to bug 6796