Bugzilla – Attachment 193725 Details for
Bug 14962
Temp Shelving Location / On Display Module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14962: On Display code for new Koha modules
34e3646.patch (text/plain), 14.56 KB, created by
Martin Renvoize (ashimema)
on 2026-02-24 13:35:25 UTC
(
hide
)
Description:
Bug 14962: On Display code for new Koha modules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-24 13:35:25 UTC
Size:
14.56 KB
patch
obsolete
>From 34e3646aac2e733c35ce1bba9efd86a96cba6b92 Mon Sep 17 00:00:00 2001 >From: Jake Deery <jake.deery@openfifth.co.uk> >Date: Mon, 1 Dec 2025 13:16:04 +0000 >Subject: [PATCH] Bug 14962: On Display code for new Koha modules > >This patch contains new code found in the On Display module. Be sure to rebuild the DBIC modules, prior to pushing. >Please see the test files commit for instructions on how to test this bundle of patches. > >Sponsored-by: ByWater Solutions >Signed-of-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> >--- > Koha/Display.pm | 204 +++++++++++++++++++++++++++++++++++++++++++ > Koha/DisplayItem.pm | 157 +++++++++++++++++++++++++++++++++ > Koha/DisplayItems.pm | 118 +++++++++++++++++++++++++ > Koha/Displays.pm | 119 +++++++++++++++++++++++++ > 4 files changed, 598 insertions(+) > create mode 100644 Koha/Display.pm > create mode 100644 Koha/DisplayItem.pm > create mode 100644 Koha/DisplayItems.pm > create mode 100644 Koha/Displays.pm > >diff --git a/Koha/Display.pm b/Koha/Display.pm >new file mode 100644 >index 00000000000..17415853ffd >--- /dev/null >+++ b/Koha/Display.pm >@@ -0,0 +1,204 @@ >+package Koha::Display; >+ >+# Copyright 2025-2026 Open Fifth Ltd >+# >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use C4::Context; >+use C4::Log qw( logaction ); >+use Koha::Database; >+use Koha::Displays; >+use Koha::DisplayItems; >+use Koha::Library; >+use Koha::ItemType; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Display - Koha Display Object class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=cut >+ >+=head3 display_items >+ >+ my $display_items = $display->display_items; >+ >+Returns the related Koha::DisplayItems object for this display. >+ >+=cut >+ >+sub display_items { >+ my ( $self, $display_items ) = @_; >+ >+ if ($display_items) { >+ my $schema = $self->_result->result_source->schema; >+ $schema->txn_do( >+ sub { >+ my $existing_items = $self->display_items; >+ my %existing_map = map { $_->itemnumber => $_ } $existing_items->as_list; >+ my %new_map = map { $_->{itemnumber} => $_ } @$display_items; >+ >+ for my $existing_item ( values %existing_map ) { >+ unless ( exists $new_map{ $existing_item->itemnumber } ) { >+ $existing_item->delete; >+ } >+ } >+ >+ for my $new_item (@$display_items) { >+ unless ( exists $existing_map{ $new_item->{itemnumber} } ) { >+ Koha::DisplayItem->new( >+ { >+ display_id => $self->display_id, >+ itemnumber => $new_item->{itemnumber}, >+ biblionumber => $new_item->{biblionumber}, >+ date_remove => $new_item->{date_remove}, >+ } >+ )->store; >+ } >+ } >+ } >+ ); >+ } >+ >+ my $display_items_rs = $self->_result->display_items; >+ return Koha::DisplayItems->_new_from_dbic($display_items_rs); >+} >+ >+=head3 home_library >+ >+ my $home_library = $display->home_library; >+ >+Returns the related Koha::Library object for this display's home branch. >+ >+=cut >+ >+sub home_library { >+ my ($self) = @_; >+ my $rs = $self->_result->display_branch; >+ return unless $rs; >+ return Koha::Library->_new_from_dbic($rs); >+} >+ >+=head3 holding_library >+ >+ my $holding_library = $display->holding_library; >+ >+Returns the related Koha::Library object for this display's holding branch. >+ >+=cut >+ >+sub holding_library { >+ my ($self) = @_; >+ my $rs = $self->_result->display_holding_branch; >+ return unless $rs; >+ return Koha::Library->_new_from_dbic($rs); >+} >+ >+=head3 item_type >+ >+ my $item_type = $display->item_type; >+ >+Returns the related Koha::ItemType object for this display's item type. >+ >+=cut >+ >+sub item_type { >+ my ($self) = @_; >+ my $rs = $self->_result->display_itype; >+ return unless $rs; >+ return Koha::ItemType->_new_from_dbic($rs); >+} >+ >+=head3 store >+ >+ $display->store(); >+ >+Overloaded store method to add action logging. >+ >+=cut >+ >+sub store { >+ my ($self) = @_; >+ >+ my $action = $self->in_storage ? 'update' : 'create'; >+ my $original = $self->in_storage ? Koha::Displays->find( $self->display_id ) : undef; >+ >+ my $enabled_before = $original ? $original->enabled : undef; >+ my $enabled_after = $self->enabled; >+ >+ my $result = $self->SUPER::store; >+ >+ if ( C4::Context->preference("DisplayItemsLog") ) { >+ if ( $action eq 'create' ) { >+ logaction( "DISPLAYS", "CREATE", $self->display_id, undef, undef, $self ); >+ } else { >+ logaction( "DISPLAYS", "MODIFY", $self->display_id, $self, undef, $original ); >+ >+ if ( defined $enabled_before && defined $enabled_after && $enabled_before != $enabled_after ) { >+ my $enable_action = $enabled_after ? "ENABLE" : "DISABLE"; >+ logaction( "DISPLAYS", $enable_action, $self->display_id, undef, undef, $self ); >+ } >+ } >+ } >+ >+ return $result; >+} >+ >+=head3 delete >+ >+ $display->delete(); >+ >+Overloaded delete method to add action logging. >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ my $result = $self->SUPER::delete; >+ >+ logaction( "DISPLAYS", "DELETE", $self->display_id, undef, undef, $self ) >+ if C4::Context->preference("DisplayItemsLog"); >+ >+ return $result; >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'Display'; >+} >+ >+=head1 AUTHOR >+ >+Koha Development Team <https://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/DisplayItem.pm b/Koha/DisplayItem.pm >new file mode 100644 >index 00000000000..7416cb6879e >--- /dev/null >+++ b/Koha/DisplayItem.pm >@@ -0,0 +1,157 @@ >+package Koha::DisplayItem; >+ >+# Copyright 2025-2026 Open Fifth Ltd >+# >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use C4::Context; >+use C4::Log qw( logaction ); >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); >+use Koha::Display; >+use Koha::Item; >+use Koha::Biblio; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::DisplayItem - Koha Display Item Object class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=cut >+ >+=head3 display >+ >+ my $display = $display_item->display; >+ >+Returns the related Koha::Display object for this display item. >+ >+=cut >+ >+sub display { >+ my ($self) = @_; >+ my $rs = $self->_result->display; >+ return Koha::Display->_new_from_dbic($rs); >+} >+ >+=head3 item >+ >+ my $item = $display_item->item; >+ >+Returns the related Koha::Item object for this display item. >+ >+=cut >+ >+sub item { >+ my ($self) = @_; >+ my $rs = $self->_result->itemnumber; >+ return unless $rs; >+ return Koha::Item->_new_from_dbic($rs); >+} >+ >+=head3 biblio >+ >+ my $biblio = $display_item->biblio; >+ >+Returns the related Koha::Biblio object for this display item. >+ >+=cut >+ >+sub biblio { >+ my ($self) = @_; >+ my $rs = $self->_result->biblionumber; >+ return unless $rs; >+ return Koha::Biblio->_new_from_dbic($rs); >+} >+ >+=head3 store >+ >+ $display_item->store(); >+ >+Overloaded store method to add action logging. >+ >+=cut >+ >+sub store { >+ my ($self) = @_; >+ >+ my $action = $self->in_storage ? 'update' : 'create'; >+ >+ if ( $action eq 'create' && !$self->date_remove ) { >+ my $display = $self->display; >+ if ( $display && $display->display_days ) { >+ my $dt = dt_from_string(); >+ $dt->add( days => $display->display_days ); >+ $self->date_remove( $dt->ymd ); >+ } >+ } >+ >+ my $result = $self->SUPER::store; >+ >+ if ( C4::Context->preference("DisplayItemsLog") && $action eq 'create' ) { >+ logaction( "DISPLAYS", "ADD_ITEM", $self->display_id, "Item " . $self->itemnumber, undef, $self ); >+ } >+ >+ return $result; >+} >+ >+=head3 delete >+ >+ $display_item->delete(); >+ >+Overloaded delete method to add action logging. >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ my $display_id = $self->display_id; >+ my $itemnumber = $self->itemnumber; >+ >+ my $result = $self->SUPER::delete; >+ >+ logaction( "DISPLAYS", "REMOVE_ITEM", $display_id, "Item " . $itemnumber, undef, $self ) >+ if C4::Context->preference("DisplayItemsLog"); >+ >+ return $result; >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'DisplayItem'; >+} >+ >+=head1 AUTHOR >+ >+Koha Development Team <https://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/DisplayItems.pm b/Koha/DisplayItems.pm >new file mode 100644 >index 00000000000..a1479dd6920 >--- /dev/null >+++ b/Koha/DisplayItems.pm >@@ -0,0 +1,118 @@ >+package Koha::DisplayItems; >+ >+# Copyright 2025-2026 Open Fifth Ltd >+# >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Carp; >+use DateTime; >+ >+use Koha::Database; >+use Koha::DisplayItem; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::DisplayItems - Koha Display Items Object set class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=cut >+ >+=head3 for_display >+ >+ my $display_items = $display_items->for_display($display_id); >+ >+Returns display items for a specific display. >+ >+=cut >+ >+sub for_display { >+ my ( $self, $display_id ) = @_; >+ return $self->search( { display_id => $display_id } ); >+} >+ >+=head3 for_item >+ >+ my $display_items = $display_items->for_item($itemnumber); >+ >+Returns display items for a specific item. >+ >+=cut >+ >+sub for_item { >+ my ( $self, $itemnumber ) = @_; >+ return $self->search( { itemnumber => $itemnumber } ); >+} >+ >+=head3 for_biblio >+ >+ my $display_items = $display_items->for_biblio($biblionumber); >+ >+Returns display items for a specific biblio. >+ >+=cut >+ >+sub for_biblio { >+ my ( $self, $biblionumber ) = @_; >+ return $self->search( { biblionumber => $biblionumber } ); >+} >+ >+=head3 due_for_removal >+ >+ my $items_to_remove = $display_items->due_for_removal; >+ >+Returns display items that are due for removal based on date_remove. >+ >+=cut >+ >+sub due_for_removal { >+ my ($self) = @_; >+ my $today = DateTime->today->ymd; >+ >+ return $self->search( { date_remove => { '<=' => $today } } ); >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'DisplayItem'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::DisplayItem'; >+} >+ >+=head1 AUTHOR >+ >+Koha Development Team <https://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/Displays.pm b/Koha/Displays.pm >new file mode 100644 >index 00000000000..e91483a55e5 >--- /dev/null >+++ b/Koha/Displays.pm >@@ -0,0 +1,119 @@ >+package Koha::Displays; >+ >+# Copyright 2025-2026 Open Fifth Ltd >+# >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Carp; >+use DateTime; >+ >+use Koha::Database; >+use Koha::Display; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Displays - Koha Display Object set class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=cut >+ >+=head3 enabled >+ >+ my $enabled_displays = $displays->enabled; >+ >+Returns only the enabled displays. >+ >+=cut >+ >+sub enabled { >+ my ($self) = @_; >+ return $self->search( { enabled => 1 } ); >+} >+ >+=head3 for_branch >+ >+ my $branch_displays = $displays->for_branch($branchcode); >+ >+Returns displays for a specific branch. >+ >+=cut >+ >+sub for_branch { >+ my ( $self, $branchcode ) = @_; >+ return $self->search( { display_branch => $branchcode } ); >+} >+ >+=head3 active >+ >+ my $active_displays = $displays->active; >+ >+Returns displays that are currently active (enabled and within date range if specified). >+ >+=cut >+ >+sub active { >+ my ($self) = @_; >+ my $today = DateTime->today->ymd; >+ >+ return $self->search( >+ { >+ enabled => 1, >+ -or => [ >+ { start_date => undef }, >+ { start_date => { '<=' => $today } } >+ ], >+ -and => [ >+ -or => [ >+ { end_date => undef }, >+ { end_date => { '>=' => $today } } >+ ] >+ ] >+ } >+ ); >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'Display'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::Display'; >+} >+ >+=head1 AUTHOR >+ >+Koha Development Team <https://koha-community.org/> >+ >+=cut >+ >+1; >-- >2.53.0 >
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 14962
:
190216
|
190217
|
190218
|
190219
|
190220
|
190221
|
190222
|
190223
|
190224
|
190225
|
190226
|
190227
|
190228
|
190229
|
190230
|
190231
|
190232
|
190571
|
190572
|
193719
|
193720
|
193721
|
193722
|
193723
|
193724
|
193725
|
193726
|
193727
|
193728
|
193729
|
193730
|
193731
|
193732
|
193733
|
193734
|
193735
|
193736
|
193737
|
193738
|
193739
|
193740
|
193741
|
193742
|
193743
|
193744
|
193745
|
193746
|
193747
|
193748
|
193749
|
193750
|
193751
|
193752
|
193753
|
193754
|
193755
|
194285
|
194286
|
194287
|
194288
|
194289
|
194290
|
194291
|
194292
|
194293
|
194294
|
194295
|
194296
|
194297
|
194298
|
194299
|
194300
|
194301
|
194302
|
194303
|
194304
|
194305
|
194306
|
194307
|
194308
|
194309
|
194310
|
194311
|
194312
|
194313
|
194314
|
194315
|
194316
|
194317
|
194318
|
194320
|
194321
|
194322