From bb52c9fae84070caa9331c97a36cfd33eb1c6217 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 10 Oct 2023 04:06:48 +0000 Subject: [PATCH] Bug 6796: (follow-up) Displaying library hours This patch shows the set library hours on a library's view page. Still to be done: - show on the Libraries summary page - write tests - consider time format settings - fix translateability of day names in Libraries summary page Sponsored-by: Catalyst IT Sponsored-by: Auckland University of Technology Sponsored-by: PTFS Europe Signed-off-by: Sam Lau Signed-off-by: Martin Renvoize --- Koha/Library.pm | 13 ++++ admin/branches.pl | 8 +-- admin/columns_settings.yml | 2 + api/v1/swagger/definitions/library.yaml | 5 ++ api/v1/swagger/paths/libraries.yaml | 5 ++ .../prog/en/modules/admin/branches.tt | 63 +++++++++++++++++-- 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index decfa136170..de174e2230d 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -26,6 +26,7 @@ use Koha::Caches; use Koha::Database; use Koha::StockRotationStages; use Koha::SMTP::Servers; +use Koha::Library::Hours; use base qw(Koha::Object); @@ -420,6 +421,18 @@ sub validate_float_sibling { return $self->get_float_libraries->search( { branchcode => $branchcode } )->count > 0; } +=head3 library_hours + +Returns the open and close times for a library. + +=cut + +sub library_hours { + my $self = shift; + my $library_hours_rs = $self->_result->library_hours; + return Koha::Library::Hours->_new_from_dbic($library_hours_rs); +} + =head2 Internal methods =head3 _type diff --git a/admin/branches.pl b/admin/branches.pl index 3b621b4f0e8..228838b7352 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -50,13 +50,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); if ( $op eq 'add_form' ) { - my @opening_hours = - Koha::Library::Hours->search( { library_id => $branchcode }, { order_by => { -asc => 'day' } } )->as_list; - $template->param( - library => Koha::Libraries->find($branchcode), - smtp_servers => Koha::SMTP::Servers->search, - opening_hours => \@opening_hours + library => Koha::Libraries->find($branchcode), + smtp_servers => Koha::SMTP::Servers->search, ); } elsif ( $branchcode && $op eq 'view' ) { my $library = Koha::Libraries->find($branchcode); diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index dd6396671fe..ba2184f29c9 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -361,6 +361,8 @@ modules: columnname: public - columnname: smtp_server + - + columnname: library_hours - columnname: actions cannot_be_toggled: 1 diff --git a/api/v1/swagger/definitions/library.yaml b/api/v1/swagger/definitions/library.yaml index de010c50d30..789d8b6bdfa 100644 --- a/api/v1/swagger/definitions/library.yaml +++ b/api/v1/swagger/definitions/library.yaml @@ -115,6 +115,11 @@ properties: needs_override: type: boolean description: If the library needs an override to act as pickup location for a hold + library_hours: + type: + - object + - "null" + description: The open and close times for a library on any given day additionalProperties: false required: - library_id diff --git a/api/v1/swagger/paths/libraries.yaml b/api/v1/swagger/paths/libraries.yaml index af452c59072..ead9798d60b 100644 --- a/api/v1/swagger/paths/libraries.yaml +++ b/api/v1/swagger/paths/libraries.yaml @@ -87,6 +87,11 @@ description: Case insensitive 'starts_with' search on notes required: false type: string + - name: library_hours + in: query + description: Case insensitive 'starts_with' search on notes + required: false + type: string - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" - $ref: "../swagger.yaml#/parameters/page" 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 d8452725af7..64ed6f3200b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -290,8 +290,8 @@
Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.
  • - - + +
    @@ -300,9 +300,9 @@ - [% IF opening_hours # Existing library %] + [% IF library.library_hours # Existing library %] [% daycount = 0 %] - [% FOREACH hr IN opening_hours %] + [% FOREACH hr IN library.library_hours %] + @@ -547,6 +548,39 @@ No [% END %] +
  • + Opening hours: + [% IF library.library_hours # Existing library %] +
  • Day
    [% PROCESS dayname day=daycount %] @@ -417,6 +417,7 @@ Pickup location Public SMTP serverLibrary hours Actions
    + + + + + + + + + [% daycount = 0 %] + [% FOREACH hr IN library.library_hours %] + + + + + + [% daycount = daycount+1 %] + [% END %] + +
    DayOpen timeClose time
    + [% PROCESS dayname day=daycount %] + + [% hr.open_time | html %] + + [% hr.close_time | html %] +
    + [% ELSE %] + No opening hours have been set. + [% END %] +
  • @@ -616,7 +650,7 @@ 'emptyTable': '
    '+_("There are no libraries defined.")+' '+_("Start defining libraries")+'.
    ', "stateSave": true, "columnDefs": [ { - "targets": [0,1,3,4,7,9,10,11,12,13,14,15,16], + "targets": [0,1,3,4,7,9,10,11,12,13,14,15,16,17], "render": function (data, type, row, meta) { if ( type == 'display' ) { if ( data != null ) { @@ -711,6 +745,25 @@ "visible": true, "orderable": false }, + { + "data": function( row, type, val, meta ) { + const daynames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']; + var daycount = 0; + var result = ''; + while ( row.library_hours[daycount] ) { + result += ''; + result += ''; + result += ''; + result += ''; + result += ''; + daycount++; + } + result += '
    DayOpen timeClose time
    '+daynames[daycount]+''+row.open_time+''+row.close_time+'
    '; + return result; + }, + "searchable": false, + "orderable": false + }, { "data": function( row, type, val, meta ) { -- 2.43.0