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 <samalau@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Aleisha Amohia 2023-10-10 04:06:48 +00:00 committed by Katrin Fischer
parent 41edb937df
commit 3db1a76a62
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
6 changed files with 85 additions and 11 deletions

View File

@ -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

View File

@ -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);

View File

@ -361,6 +361,8 @@ modules:
columnname: public
-
columnname: smtp_server
-
columnname: library_hours
-
columnname: actions
cannot_be_toggled: 1

View File

@ -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

View File

@ -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"

View File

@ -291,8 +291,8 @@
<div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
</li>
<li>
<label for="opening_hours">Opening hours: </label>
<table id="opening_hours_table">
<label for="library_hours">Opening hours: </label>
<table id="library_hours_table">
<thead>
<tr>
<th>Day</th>
@ -301,9 +301,9 @@
</tr>
</thead>
<tbody>
[% IF opening_hours # Existing library %]
[% IF library.library_hours # Existing library %]
[% daycount = 0 %]
[% FOREACH hr IN opening_hours %]
[% FOREACH hr IN library.library_hours %]
<tr id="hours_[% daycount | html %]">
<td>
[% PROCESS dayname day=daycount %]
@ -419,6 +419,7 @@
<th>Pickup location</th>
<th>Public</th>
<th>SMTP server</th>
<th>Library hours</th>
<th data-class-name="actions noExport">Actions</th>
</tr>
</thead>
@ -549,6 +550,39 @@
<span>No</span>
[% END %]
</li>
<li>
<span class="label">Opening hours: </span>
[% IF library.library_hours # Existing library %]
<table id="library_hours_table">
<thead>
<tr>
<th>Day</th>
<th>Open time</th>
<th>Close time</th>
</tr>
</thead>
<tbody>
[% daycount = 0 %]
[% FOREACH hr IN library.library_hours %]
<tr id="hours_[% daycount | html %]">
<td>
<span>[% PROCESS dayname day=daycount %]</span>
</td>
<td>
<span>[% hr.open_time | html %]</span>
</td>
<td>
<span>[% hr.close_time | html %]</span>
</td>
</tr>
[% daycount = daycount+1 %]
[% END %]
</tbody>
</table>
[% ELSE %]
<span>No opening hours have been set.</span>
[% END %]
</li>
</ol>
</div> <!-- /.rows -->
</div> <!-- /.col-sm-6 -->
@ -618,7 +652,7 @@
'emptyTable': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>',
"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 ) {
@ -713,6 +747,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 = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
while ( row.library_hours[daycount] ) {
result += '<tr id="hours_"'+daycount+'>';
result += '<td>'+daynames[daycount]+'</td>';
result += '<td><span>'+row.open_time+'</span></td>';
result += '<td><span>'+row.close_time+'</span></td>';
result += '</tr>';
daycount++;
}
result += '</tbody></table>';
return result;
},
"searchable": false,
"orderable": false
},
{
"data": function( row, type, val, meta ) {