Bugzilla – Attachment 134323 Details for
Bug 6796
Overnight checkouts taking into account opening and closing hours
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 6796: Add branch_hours table and set opening hours for library
Bug-6796-Add-branchhours-table-and-set-opening-hou.patch (text/plain), 12.97 KB, created by
Hayley Pelham
on 2022-04-29 00:44:15 UTC
(
hide
)
Description:
Bug 6796: Add branch_hours table and set opening hours for library
Filename:
MIME Type:
Creator:
Hayley Pelham
Created:
2022-04-29 00:44:15 UTC
Size:
12.97 KB
patch
obsolete
>From 3691af086afa2f3cf6dd81e8cf21a56758e164ee Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Tue, 7 Sep 2021 15:22:25 +1200 >Subject: [PATCH] Bug 6796: Add branch_hours table and set opening hours for > library > >--- > Koha/Library/Hour.pm | 43 +++++++++++ > Koha/Library/Hours.pm | 52 ++++++++++++++ > admin/branches.pl | 45 +++++++++++- > .../bug_6796_-_add_branch_hours_table.perl | 20 ++++++ > installer/data/mysql/kohastructure.sql | 16 +++++ > .../prog/en/modules/admin/branches.tt | 72 +++++++++++++++++++ > 6 files changed, 246 insertions(+), 2 deletions(-) > create mode 100644 Koha/Library/Hour.pm > create mode 100644 Koha/Library/Hours.pm > create mode 100644 installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl > >diff --git a/Koha/Library/Hour.pm b/Koha/Library/Hour.pm >new file mode 100644 >index 00000000000..1b77de07246 >--- /dev/null >+++ b/Koha/Library/Hour.pm >@@ -0,0 +1,43 @@ >+package Koha::Library::Hour; >+ >+# Copyright 2021 Aleisha Amohia <aleisha@catalyst.net.nz> >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Library::Hour - Koha Library Hour Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'BranchHour'; >+} >+ >+1; >diff --git a/Koha/Library/Hours.pm b/Koha/Library/Hours.pm >new file mode 100644 >index 00000000000..22e709b8c62 >--- /dev/null >+++ b/Koha/Library/Hours.pm >@@ -0,0 +1,52 @@ >+package Koha::Library::Hours; >+ >+# Copyright 2021 Aleisha Amohia <aleisha@catalyst.net.nz> >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+use Koha::Library::Hour; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Library::Hours - Koha Library Hours Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'BranchHour'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::Library::Hour'; >+} >+ >+1; >diff --git a/admin/branches.pl b/admin/branches.pl >index 08a73f6571f..d5cecfb78c7 100755 >--- a/admin/branches.pl >+++ b/admin/branches.pl >@@ -33,6 +33,7 @@ use Koha::Patrons; > use Koha::Items; > use Koha::Libraries; > use Koha::SMTP::Servers; >+use Koha::Library::Hours; > > my $input = CGI->new; > my $branchcode = $input->param('branchcode'); >@@ -49,9 +50,19 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > ); > > if ( $op eq 'add_form' ) { >+ my $library; >+ if ($branchcode) { >+ $library = Koha::Libraries->find($branchcode); >+ $template->param( selected_smtp_server => $library->smtp_server ); >+ } >+ >+ my @smtp_servers = Koha::SMTP::Servers->search; >+ my @opening_hours = Koha::Library::Hours->search({ branchcode => $branchcode }, { order_by => { -asc => 'day' } }); >+ > $template->param( >- library => Koha::Libraries->find($branchcode), >- smtp_servers => Koha::SMTP::Servers->search, >+ library => $library, >+ smtp_servers => \@smtp_servers, >+ opening_hours => \@opening_hours > ); > } elsif ( $op eq 'add_validate' ) { > my @fields = qw( >@@ -110,6 +121,21 @@ if ( $op eq 'add_form' ) { > } > } > >+ my @days = $input->multi_param("day"); >+ my @open_times = $input->multi_param("open_time"); >+ my @close_times = $input->multi_param("close_time"); >+ >+ foreach my $day ( @days ) { >+ if ( $open_times[$day] and $open_times[$day] eq '' ) { >+ $open_times[$day] = undef; >+ } >+ if ( $close_times[$day] and $close_times[$day] eq '' ) { >+ $close_times[$day] = undef; >+ } >+ >+ my $openday = Koha::Library::Hours->find({ branchcode => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] }); >+ } >+ > push @messages, { type => 'message', code => 'success_on_update' }; > } > ); >@@ -148,6 +174,21 @@ if ( $op eq 'add_form' ) { > } > } > >+ my @days = $input->multi_param("day"); >+ my @open_times = $input->multi_param("open_time"); >+ my @close_times = $input->multi_param("close_time"); >+ >+ foreach my $day ( @days ) { >+ if ( $open_times[$day] and $open_times[$day] eq '' ) { >+ $open_times[$day] = undef; >+ } >+ if ( $close_times[$day] and $close_times[$day] eq '' ) { >+ $close_times[$day] = undef; >+ } >+ >+ my $openday = Koha::Library::Hour->new({ branchcode => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store; >+ } >+ > push @messages, { type => 'message', code => 'success_on_insert' }; > } > ); >diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl b/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl >new file mode 100644 >index 00000000000..964da04c610 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl >@@ -0,0 +1,20 @@ >+$DBversion = 'XXX'; >+if ( CheckVersion( $DBversion ) ) { >+ $dbh->do(q{ DROP TABLE IF EXISTS branch_hours }); >+ $dbh->do(q{ >+ CREATE TABLE branch_hours ( >+ branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, >+ day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0, >+ open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, >+ close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, >+ PRIMARY KEY (branchcode, day), >+ CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE >+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+ }); >+ >+ my @indexes = (0..6); >+ for my $i (@indexes) { >+ $dbh->do(q{ INSERT INTO branch_hours (branchcode, day) SELECT branchcode, ? FROM branches }, undef, $i); >+ } >+ NewVersion( $DBversion, 6796, "Add branch_hours table" ); >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index f7ec7186b92..f99082dfddc 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1525,6 +1525,22 @@ CREATE TABLE `branches` ( > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > /*!40101 SET character_set_client = @saved_cs_client */; > >+-- >+-- Table structure for table `branch_hours` >+-- >+DROP TABLE IF EXISTS branch_hours; >+/*!40101 SET @saved_cs_client = @@character_set_client */; >+/*!40101 SET character_set_client = utf8 */; >+CREATE TABLE branch_hours ( >+ branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, >+ day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0, >+ open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, >+ close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, >+ PRIMARY KEY (branchcode, day), >+ CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+/*!40101 SET character_set_client = @saved_cs_client */; >+ > -- > -- Table structure for table `branches_overdrive` > -- >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >index eb3b8f92a39..dbc863d3874 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >@@ -276,6 +276,60 @@ Libraries › Administration › Koha > [% END %] > </select> > <div class="hint">Set to 'yes' to show this library on the Libraries page in the OPAC.</div> >+ <li> >+ <label for="opening_hours">Opening hours: </label> >+ <table id="opening_hours_table"> >+ <thead> >+ <tr> >+ <th>Day</th> >+ <th>Open time</th> >+ <th>Close time</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% IF opening_hours # Existing library %] >+ [% daycount = 0 %] >+ [% FOREACH hr IN opening_hours %] >+ <tr id="hours_[% daycount %]"> >+ <td> >+ [% PROCESS dayname day=daycount %] >+ <input type="hidden" value="[% daycount %]" name="day"> >+ </td> >+ <td> >+ [% IF hr.day == daycount && hr.open_time %] >+ <input type="time" value="[% hr.open_time %]" name="open_time"> >+ [% ELSE %] >+ <input type="time" value="" name="open_time"> >+ [% END %] >+ </td> >+ <td> >+ [% IF hr.day == daycount && hr.close_time %] >+ <input type="time" value="[% hr.close_time %]" name="close_time"> >+ [% ELSE %] >+ <input type="time" value="" name="close_time"> >+ [% END %] >+ </td> >+ </tr> >+ [% daycount = daycount+1 %] >+ [% END %] >+ [% ELSE # New library %] >+ [% FOREACH daycount IN [0..6] %] >+ <tr id="hours_[% day %]"> >+ <td> >+ [% PROCESS dayname day=daycount %] >+ <input type="hidden" value="[% daycount %]" name="day"> >+ </td> >+ <td> >+ <input type="time" value="" name="open_time"> >+ </td> >+ <td> >+ <input type="time" value="" name="close_time"> >+ </td> >+ </tr> >+ [% END %] >+ [% END %] >+ </tbody> >+ </table> > </li> > </ol> > </fieldset> >@@ -286,6 +340,24 @@ Libraries › Administration › Koha > </form> > [% END %] > >+[% BLOCK dayname %] >+ [% IF day == 0 %] >+ Monday >+ [% ELSIF day == 1 %] >+ Tuesday >+ [% ELSIF day == 2 %] >+ Wednesday >+ [% ELSIF day == 3 %] >+ Thursday >+ [% ELSIF day == 4 %] >+ Friday >+ [% ELSIF day == 5 %] >+ Saturday >+ [% ELSE %] >+ Sunday >+ [% END %] >+[% END %] >+ > [% IF op == 'delete_confirm' and not ( items_count or patrons_count )%] > <div class="dialog alert"> > <form action="/cgi-bin/koha/admin/branches.pl" method="post"> >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 6796
:
124669
|
124670
|
124671
|
124672
|
134323
|
134324
|
134325
|
134326
|
134327
|
145669
|
145670
|
145671
|
145672
|
145673
|
146988
|
146989
|
146990
|
146991
|
146992
|
150442
|
150443
|
150444
|
150445
|
150446
|
150447
|
150448
|
150477
|
150478
|
153252
|
153253
|
153254
|
153255
|
153256
|
153257
|
153258
|
153259
|
153260
|
153261
|
153271
|
153272
|
153273
|
153274
|
153275
|
153276
|
153277
|
153278
|
153279
|
153280
|
156772
|
156773
|
156774
|
156775
|
156776
|
156777
|
156778
|
156779
|
156780
|
161970
|
161971
|
161972
|
161973
|
161974
|
161975
|
161976
|
161977
|
161978
|
161979
|
161980
|
161986
|
161987
|
161988
|
161989
|
162043
|
162044
|
162045
|
162046
|
162047
|
162048
|
162049
|
162050
|
162051
|
162052
|
162053
|
162054
|
162055
|
162056
|
162090
|
162091
|
162092
|
162093
|
162094
|
162095
|
162096
|
162097
|
162098
|
162099
|
162100
|
162101
|
162102
|
162103
|
162104
|
164511
|
164512
|
164513
|
164514
|
164515
|
164516
|
164517
|
164518
|
164538
|
164539
|
164540
|
164541
|
164542
|
164543
|
164544
|
164545
|
164546
|
164547
|
164548
|
164549
|
164550
|
164551
|
164552