From f319dcf9862627fda8981276d0d69f0ebd5c6371 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Apr 2023 08:35:48 +0200 Subject: [PATCH] Bug 33568: Course reserves MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit FIXME We need tests here FIXME/TODO - Isn't it possible to replace all this mess with the following Koha::Item method and a new DBIC rs? sub courses { my ($self) = @_; return Koha::Courses->search( { 'ci.itemnumber' => $self->itemnumber }, { join => { course_reserves => 'ci' } } ); } Signed-off-by: Owen Leonard Signed-off-by: Laurence Rault Signed-off-by: Emily Lamancusa Signed-off-by: Tomás Cohen Arazi Signed-off-by: Katrin Fischer --- Koha/Course/Reserve.pm | 19 +++++++- Koha/Item.pm | 17 +++++++ api/v1/swagger/definitions/item.yaml | 4 ++ api/v1/swagger/paths/biblios.yaml | 1 + .../prog/en/modules/catalogue/detail.tt | 45 +++++++++++-------- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/Koha/Course/Reserve.pm b/Koha/Course/Reserve.pm index 963a2ee272..6493ba90a3 100644 --- a/Koha/Course/Reserve.pm +++ b/Koha/Course/Reserve.pm @@ -17,15 +17,32 @@ package Koha::Course::Reserve; use Modern::Perl; - use base qw(Koha::Object); +use Koha::Courses; + =head1 NAME Koha::Course::Reserve - Koha Course Reserve Object class =head1 API +=head2 Methods + +=head3 course + + my $course = $course_reserve->course; + +Return the course for this course reserve. + +=cut + +sub course { + my ($self) = @_; + my $rs = $self->_result->course; + return Koha::Course->_new_from_dbic($rs); +} + =head2 Internal methods =cut diff --git a/Koha/Item.pm b/Koha/Item.pm index b3fc8d5652..42897cfb1c 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -35,6 +35,8 @@ use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; use Koha::Biblio::ItemGroups; use Koha::Checkouts; use Koha::CirculationRules; +use Koha::Courses; +use Koha::Course::Items; use Koha::CoverImages; use Koha::Exceptions; use Koha::Exceptions::Checkin; @@ -1787,6 +1789,21 @@ sub tracked_links { return Koha::TrackedLinks->_new_from_dbic($tracked_links); } +=head3 course_item + + my $course_item = $item->course_item; + +Returns a Koha::Course::Item object + +=cut + +sub course_item { + my ($self) = @_; + my $rs = $self->_result->course_item; + return unless $rs; + return Koha::Course::Item->_new_from_dbic($rs); +} + =head3 move_to_biblio $item->move_to_biblio($to_biblio[, $params]); diff --git a/api/v1/swagger/definitions/item.yaml b/api/v1/swagger/definitions/item.yaml index 1c816f21b2..d3a035b514 100644 --- a/api/v1/swagger/definitions/item.yaml +++ b/api/v1/swagger/definitions/item.yaml @@ -270,6 +270,10 @@ properties: type: - object - "null" + course_item: + type: + - object + - "null" _strings: type: - object diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index 101fa172ed..3ba4be8d20 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -433,6 +433,7 @@ - item_type - in_bundle - bundle_host + - course_item.course_reserves.course - cover_image_ids - item_group_item.item_group.description - serialitem.serial diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index d9851e03c8..bff8e66ac2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -19,19 +19,6 @@ [% AmazonAssocTag = '' %] [% END %] -[% ShowCourseReserves = 0 | html %] -[% IF UseCourseReserves %] - [% FOREACH item IN itemloop %] - [% IF item.course_reserves %] - [% FOREACH r IN item.course_reserves %] - [% IF r.course.enabled == 'yes' %] - [% ShowCourseReserves = 1 | html %] - [% END %] - [% END %] - [% END %] - [% END %] -[% END %] - [% SET plugins_intranet_catalog_biblio_tabs = KohaPlugins.get_plugins_intranet_catalog_biblio_tab({ biblio => biblio, biblio_id => biblionumber }) %] [% SET footerjs = 1 %] @@ -379,7 +366,7 @@ Non-public notes [% IF ( hostrecords ) %]Host records[% END %] [% IF ( analyze ) %]Used in[% END %] - [% IF ( ShowCourseReserves ) %]Course reserves[% END %] + [% IF Koha.Preference('UseCourseReserves') %]Course reserves[% END %] [% IF ( SpineLabelShowPrintOnBibDetails ) %]Spine label[% END %] [% IF ( CAN_user_editcatalogue_edit_items ) %] [% END %] @@ -2174,6 +2161,9 @@ const av_damaged = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.damaged' })) | $raw %].map( av => [av.authorised_value, av.lib])); const av_not_for_loan= new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.notforloan' })) | $raw %].map( av => [av.authorised_value, av.lib])); const av_restricted = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.restricted' })) | $raw %].map( av => [av.authorised_value, av.lib])); + [% IF Koha.Preference('UseCourseReserves') %] + const av_courses_term = new Map([% To.json(AuthorisedValues.Get('TERM')) | $raw %].map( av => [av.authorised_value, av.lib])); + [% END %] [% IF Koha.Preference('URLLinkText') %] const url_link_text = "[% Koha.Preference('URLLinkText') | html %]"; [% ELSE %] @@ -2197,6 +2187,9 @@ embed.push('recall', 'recall.patron') [% END %] embed.push('in_bundle', 'bundle_host'); + [% IF Koha.Preference('UseCourseReserves') %] + embed.push('course_item.course_reserves.course'); + [% END %] function build_table (table_id, table_settings, filters) { [% IF hidden_count %] @@ -2586,13 +2579,29 @@ } }, [% END %] - [% IF ( ShowCourseReserves ) %] + [% IF Koha.Preference('UseCourseReserves') %] { - data: "", - searchable: false, // FIXME + data: "course_item.course_reserves.course.course_name", + searchable: true, orderable: true, render: function (data, type, row, meta) { - return ""; // FIXME Display course reserves + let nodes = ''; + if (!row.course_item) return nodes; + row.course_item.course_reserves.forEach((cr, i) => { + let c = cr.course; + if ( c.enabled != 'yes' ) return; + nodes += '

'; + nodes += ''.format(c.course_id); + nodes += c.course_name; + if ( c.section ) { + nodes += ' ' + c.section; + } + if ( c.term ) { + nodes += ' ' + av_courses_term.get(c.term.toString()); + } + nodes += '

'; + }); + return nodes; } }, [% END %] -- 2.39.5