View | Details | Raw Unified | Return to bug 14962
Collapse All | Expand All

(-)a/Koha/Display.pm (+204 lines)
Line 0 Link Here
1
package Koha::Display;
2
3
# Copyright 2025-2026 Open Fifth Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use C4::Context;
25
use C4::Log qw( logaction );
26
use Koha::Database;
27
use Koha::Displays;
28
use Koha::DisplayItems;
29
use Koha::Library;
30
use Koha::ItemType;
31
32
use base qw(Koha::Object);
33
34
=head1 NAME
35
36
Koha::Display - Koha Display Object class
37
38
=head1 API
39
40
=head2 Class methods
41
42
=cut
43
44
=head3 display_items
45
46
    my $display_items = $display->display_items;
47
48
Returns the related Koha::DisplayItems object for this display.
49
50
=cut
51
52
sub display_items {
53
    my ( $self, $display_items ) = @_;
54
55
    if ($display_items) {
56
        my $schema = $self->_result->result_source->schema;
57
        $schema->txn_do(
58
            sub {
59
                my $existing_items = $self->display_items;
60
                my %existing_map   = map { $_->itemnumber   => $_ } $existing_items->as_list;
61
                my %new_map        = map { $_->{itemnumber} => $_ } @$display_items;
62
63
                for my $existing_item ( values %existing_map ) {
64
                    unless ( exists $new_map{ $existing_item->itemnumber } ) {
65
                        $existing_item->delete;
66
                    }
67
                }
68
69
                for my $new_item (@$display_items) {
70
                    unless ( exists $existing_map{ $new_item->{itemnumber} } ) {
71
                        Koha::DisplayItem->new(
72
                            {
73
                                display_id   => $self->display_id,
74
                                itemnumber   => $new_item->{itemnumber},
75
                                biblionumber => $new_item->{biblionumber},
76
                                date_remove  => $new_item->{date_remove},
77
                            }
78
                        )->store;
79
                    }
80
                }
81
            }
82
        );
83
    }
84
85
    my $display_items_rs = $self->_result->display_items;
86
    return Koha::DisplayItems->_new_from_dbic($display_items_rs);
87
}
88
89
=head3 home_library
90
91
    my $home_library = $display->home_library;
92
93
Returns the related Koha::Library object for this display's home branch.
94
95
=cut
96
97
sub home_library {
98
    my ($self) = @_;
99
    my $rs = $self->_result->display_branch;
100
    return unless $rs;
101
    return Koha::Library->_new_from_dbic($rs);
102
}
103
104
=head3 holding_library
105
106
    my $holding_library = $display->holding_library;
107
108
Returns the related Koha::Library object for this display's holding branch.
109
110
=cut
111
112
sub holding_library {
113
    my ($self) = @_;
114
    my $rs = $self->_result->display_holding_branch;
115
    return unless $rs;
116
    return Koha::Library->_new_from_dbic($rs);
117
}
118
119
=head3 item_type
120
121
    my $item_type = $display->item_type;
122
123
Returns the related Koha::ItemType object for this display's item type.
124
125
=cut
126
127
sub item_type {
128
    my ($self) = @_;
129
    my $rs = $self->_result->display_itype;
130
    return unless $rs;
131
    return Koha::ItemType->_new_from_dbic($rs);
132
}
133
134
=head3 store
135
136
    $display->store();
137
138
Overloaded store method to add action logging.
139
140
=cut
141
142
sub store {
143
    my ($self) = @_;
144
145
    my $action   = $self->in_storage ? 'update'                                  : 'create';
146
    my $original = $self->in_storage ? Koha::Displays->find( $self->display_id ) : undef;
147
148
    my $enabled_before = $original ? $original->enabled : undef;
149
    my $enabled_after  = $self->enabled;
150
151
    my $result = $self->SUPER::store;
152
153
    if ( C4::Context->preference("DisplayItemsLog") ) {
154
        if ( $action eq 'create' ) {
155
            logaction( "DISPLAYS", "CREATE", $self->display_id, undef, undef, $self );
156
        } else {
157
            logaction( "DISPLAYS", "MODIFY", $self->display_id, $self, undef, $original );
158
159
            if ( defined $enabled_before && defined $enabled_after && $enabled_before != $enabled_after ) {
160
                my $enable_action = $enabled_after ? "ENABLE" : "DISABLE";
161
                logaction( "DISPLAYS", $enable_action, $self->display_id, undef, undef, $self );
162
            }
163
        }
164
    }
165
166
    return $result;
167
}
168
169
=head3 delete
170
171
    $display->delete();
172
173
Overloaded delete method to add action logging.
174
175
=cut
176
177
sub delete {
178
    my ($self) = @_;
179
180
    my $result = $self->SUPER::delete;
181
182
    logaction( "DISPLAYS", "DELETE", $self->display_id, undef, undef, $self )
183
        if C4::Context->preference("DisplayItemsLog");
184
185
    return $result;
186
}
187
188
=head2 Internal methods
189
190
=head3 _type
191
192
=cut
193
194
sub _type {
195
    return 'Display';
196
}
197
198
=head1 AUTHOR
199
200
Koha Development Team <https://koha-community.org/>
201
202
=cut
203
204
1;
(-)a/Koha/DisplayItem.pm (+157 lines)
Line 0 Link Here
1
package Koha::DisplayItem;
2
3
# Copyright 2025-2026 Open Fifth Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use C4::Context;
25
use C4::Log qw( logaction );
26
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Display;
29
use Koha::Item;
30
use Koha::Biblio;
31
32
use base qw(Koha::Object);
33
34
=head1 NAME
35
36
Koha::DisplayItem - Koha Display Item Object class
37
38
=head1 API
39
40
=head2 Class methods
41
42
=cut
43
44
=head3 display
45
46
    my $display = $display_item->display;
47
48
Returns the related Koha::Display object for this display item.
49
50
=cut
51
52
sub display {
53
    my ($self) = @_;
54
    my $rs = $self->_result->display;
55
    return Koha::Display->_new_from_dbic($rs);
56
}
57
58
=head3 item
59
60
    my $item = $display_item->item;
61
62
Returns the related Koha::Item object for this display item.
63
64
=cut
65
66
sub item {
67
    my ($self) = @_;
68
    my $rs = $self->_result->itemnumber;
69
    return unless $rs;
70
    return Koha::Item->_new_from_dbic($rs);
71
}
72
73
=head3 biblio
74
75
    my $biblio = $display_item->biblio;
76
77
Returns the related Koha::Biblio object for this display item.
78
79
=cut
80
81
sub biblio {
82
    my ($self) = @_;
83
    my $rs = $self->_result->biblionumber;
84
    return unless $rs;
85
    return Koha::Biblio->_new_from_dbic($rs);
86
}
87
88
=head3 store
89
90
    $display_item->store();
91
92
Overloaded store method to add action logging.
93
94
=cut
95
96
sub store {
97
    my ($self) = @_;
98
99
    my $action = $self->in_storage ? 'update' : 'create';
100
101
    if ( $action eq 'create' && !$self->date_remove ) {
102
        my $display = $self->display;
103
        if ( $display && $display->display_days ) {
104
            my $dt = dt_from_string();
105
            $dt->add( days => $display->display_days );
106
            $self->date_remove( $dt->ymd );
107
        }
108
    }
109
110
    my $result = $self->SUPER::store;
111
112
    if ( C4::Context->preference("DisplayItemsLog") && $action eq 'create' ) {
113
        logaction( "DISPLAYS", "ADD_ITEM", $self->display_id, "Item " . $self->itemnumber, undef, $self );
114
    }
115
116
    return $result;
117
}
118
119
=head3 delete
120
121
    $display_item->delete();
122
123
Overloaded delete method to add action logging.
124
125
=cut
126
127
sub delete {
128
    my ($self) = @_;
129
130
    my $display_id = $self->display_id;
131
    my $itemnumber = $self->itemnumber;
132
133
    my $result = $self->SUPER::delete;
134
135
    logaction( "DISPLAYS", "REMOVE_ITEM", $display_id, "Item " . $itemnumber, undef, $self )
136
        if C4::Context->preference("DisplayItemsLog");
137
138
    return $result;
139
}
140
141
=head2 Internal methods
142
143
=head3 _type
144
145
=cut
146
147
sub _type {
148
    return 'DisplayItem';
149
}
150
151
=head1 AUTHOR
152
153
Koha Development Team <https://koha-community.org/>
154
155
=cut
156
157
1;
(-)a/Koha/DisplayItems.pm (+118 lines)
Line 0 Link Here
1
package Koha::DisplayItems;
2
3
# Copyright 2025-2026 Open Fifth Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Carp;
23
use DateTime;
24
25
use Koha::Database;
26
use Koha::DisplayItem;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::DisplayItems - Koha Display Items Object set class
33
34
=head1 API
35
36
=head2 Class methods
37
38
=cut
39
40
=head3 for_display
41
42
    my $display_items = $display_items->for_display($display_id);
43
44
Returns display items for a specific display.
45
46
=cut
47
48
sub for_display {
49
    my ( $self, $display_id ) = @_;
50
    return $self->search( { display_id => $display_id } );
51
}
52
53
=head3 for_item
54
55
    my $display_items = $display_items->for_item($itemnumber);
56
57
Returns display items for a specific item.
58
59
=cut
60
61
sub for_item {
62
    my ( $self, $itemnumber ) = @_;
63
    return $self->search( { itemnumber => $itemnumber } );
64
}
65
66
=head3 for_biblio
67
68
    my $display_items = $display_items->for_biblio($biblionumber);
69
70
Returns display items for a specific biblio.
71
72
=cut
73
74
sub for_biblio {
75
    my ( $self, $biblionumber ) = @_;
76
    return $self->search( { biblionumber => $biblionumber } );
77
}
78
79
=head3 due_for_removal
80
81
    my $items_to_remove = $display_items->due_for_removal;
82
83
Returns display items that are due for removal based on date_remove.
84
85
=cut
86
87
sub due_for_removal {
88
    my ($self) = @_;
89
    my $today = DateTime->today->ymd;
90
91
    return $self->search( { date_remove => { '<=' => $today } } );
92
}
93
94
=head2 Internal methods
95
96
=head3 _type
97
98
=cut
99
100
sub _type {
101
    return 'DisplayItem';
102
}
103
104
=head3 object_class
105
106
=cut
107
108
sub object_class {
109
    return 'Koha::DisplayItem';
110
}
111
112
=head1 AUTHOR
113
114
Koha Development Team <https://koha-community.org/>
115
116
=cut
117
118
1;
(-)a/Koha/Displays.pm (-1 / +119 lines)
Line 0 Link Here
0
- 
1
package Koha::Displays;
2
3
# Copyright 2025-2026 Open Fifth Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Carp;
23
use DateTime;
24
25
use Koha::Database;
26
use Koha::Display;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Displays - Koha Display Object set class
33
34
=head1 API
35
36
=head2 Class methods
37
38
=cut
39
40
=head3 enabled
41
42
    my $enabled_displays = $displays->enabled;
43
44
Returns only the enabled displays.
45
46
=cut
47
48
sub enabled {
49
    my ($self) = @_;
50
    return $self->search( { enabled => 1 } );
51
}
52
53
=head3 for_branch
54
55
    my $branch_displays = $displays->for_branch($branchcode);
56
57
Returns displays for a specific branch.
58
59
=cut
60
61
sub for_branch {
62
    my ( $self, $branchcode ) = @_;
63
    return $self->search( { display_branch => $branchcode } );
64
}
65
66
=head3 active
67
68
    my $active_displays = $displays->active;
69
70
Returns displays that are currently active (enabled and within date range if specified).
71
72
=cut
73
74
sub active {
75
    my ($self) = @_;
76
    my $today = DateTime->today->ymd;
77
78
    return $self->search(
79
        {
80
            enabled => 1,
81
            -or     => [
82
                { start_date => undef },
83
                { start_date => { '<=' => $today } }
84
            ],
85
            -and => [
86
                -or => [
87
                    { end_date => undef },
88
                    { end_date => { '>=' => $today } }
89
                ]
90
            ]
91
        }
92
    );
93
}
94
95
=head2 Internal methods
96
97
=head3 _type
98
99
=cut
100
101
sub _type {
102
    return 'Display';
103
}
104
105
=head3 object_class
106
107
=cut
108
109
sub object_class {
110
    return 'Koha::Display';
111
}
112
113
=head1 AUTHOR
114
115
Koha Development Team <https://koha-community.org/>
116
117
=cut
118
119
1;

Return to bug 14962