Bugzilla – Attachment 190220 Details for
Bug 14962
Temp Shelving Location
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
Bug-14962-On-Display-code-for-new-Koha-modules.patch (text/plain), 13.96 KB, created by
Jake Deery
on 2025-12-05 14:51:21 UTC
(
hide
)
Description:
Bug 14962: On Display code for new Koha modules
Filename:
MIME Type:
Creator:
Jake Deery
Created:
2025-12-05 14:51:21 UTC
Size:
13.96 KB
patch
obsolete
>From d7f0eb79d7fba2cdc05e1fefbfe9d7825cdde917 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. >--- > Koha/Display.pm | 187 +++++++++++++++++++++++++++++++++++++++++++ > Koha/DisplayItem.pm | 155 +++++++++++++++++++++++++++++++++++ > Koha/DisplayItems.pm | 116 +++++++++++++++++++++++++++ > Koha/Displays.pm | 117 +++++++++++++++++++++++++++ > 4 files changed, 575 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..9df7485e864 >--- /dev/null >+++ b/Koha/Display.pm >@@ -0,0 +1,187 @@ >+package Koha::Display; >+ >+# 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 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 library >+ >+ my $library = $display->library; >+ >+Returns the related Koha::Library object for this display's branch. >+ >+=cut >+ >+sub library { >+ my ($self) = @_; >+ my $rs = $self->_result->display_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 <http://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/DisplayItem.pm b/Koha/DisplayItem.pm >new file mode 100644 >index 00000000000..40eca474e47 >--- /dev/null >+++ b/Koha/DisplayItem.pm >@@ -0,0 +1,155 @@ >+package Koha::DisplayItem; >+ >+# 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 Carp; >+use DateTime; >+ >+use C4::Context; >+use C4::Log qw( logaction ); >+use Koha::Database; >+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 = DateTime->now( time_zone => C4::Context->tz() ); >+ $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 <http://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/DisplayItems.pm b/Koha/DisplayItems.pm >new file mode 100644 >index 00000000000..d9b18e8d049 >--- /dev/null >+++ b/Koha/DisplayItems.pm >@@ -0,0 +1,116 @@ >+package Koha::DisplayItems; >+ >+# 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 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 <http://koha-community.org/> >+ >+=cut >+ >+1; >diff --git a/Koha/Displays.pm b/Koha/Displays.pm >new file mode 100644 >index 00000000000..be53abe73ef >--- /dev/null >+++ b/Koha/Displays.pm >@@ -0,0 +1,117 @@ >+package Koha::Displays; >+ >+# 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 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 <http://koha-community.org/> >+ >+=cut >+ >+1; >-- >2.50.1 (Apple Git-155)
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