Line 0
Link Here
|
0 |
- |
1 |
use utf8; |
|
|
2 |
package Koha::Schema::Result::AccountlineLink; |
3 |
|
4 |
# Created by DBIx::Class::Schema::Loader |
5 |
# DO NOT MODIFY THE FIRST PART OF THIS FILE |
6 |
|
7 |
=head1 NAME |
8 |
|
9 |
Koha::Schema::Result::AccountlineLink |
10 |
|
11 |
=cut |
12 |
|
13 |
use strict; |
14 |
use warnings; |
15 |
|
16 |
use base 'DBIx::Class::Core'; |
17 |
|
18 |
=head1 TABLE: C<accountline_links> |
19 |
|
20 |
=cut |
21 |
|
22 |
__PACKAGE__->table("accountline_links"); |
23 |
|
24 |
=head1 ACCESSORS |
25 |
|
26 |
=head2 link_id |
27 |
|
28 |
data_type: 'integer' |
29 |
is_auto_increment: 1 |
30 |
is_nullable: 0 |
31 |
|
32 |
=head2 accountlines_id |
33 |
|
34 |
data_type: 'integer' |
35 |
is_foreign_key: 1 |
36 |
is_nullable: 0 |
37 |
|
38 |
foreign key to accountlines.accountlines_id |
39 |
|
40 |
=head2 link_type |
41 |
|
42 |
data_type: 'varchar' |
43 |
is_nullable: 0 |
44 |
size: 32 |
45 |
|
46 |
Type of linked entity: hold, old_hold, checkout, old_checkout, article_request, etc. |
47 |
|
48 |
=head2 linked_id |
49 |
|
50 |
data_type: 'integer' |
51 |
is_nullable: 0 |
52 |
|
53 |
ID of the linked entity |
54 |
|
55 |
=head2 created_on |
56 |
|
57 |
data_type: 'timestamp' |
58 |
datetime_undef_if_invalid: 1 |
59 |
default_value: current_timestamp |
60 |
is_nullable: 0 |
61 |
|
62 |
=cut |
63 |
|
64 |
__PACKAGE__->add_columns( |
65 |
"link_id", |
66 |
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, |
67 |
"accountlines_id", |
68 |
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, |
69 |
"link_type", |
70 |
{ data_type => "varchar", is_nullable => 0, size => 32 }, |
71 |
"linked_id", |
72 |
{ data_type => "integer", is_nullable => 0 }, |
73 |
"created_on", |
74 |
{ |
75 |
data_type => "timestamp", |
76 |
datetime_undef_if_invalid => 1, |
77 |
default_value => \"current_timestamp", |
78 |
is_nullable => 0, |
79 |
}, |
80 |
); |
81 |
|
82 |
=head1 PRIMARY KEY |
83 |
|
84 |
=over 4 |
85 |
|
86 |
=item * L</link_id> |
87 |
|
88 |
=back |
89 |
|
90 |
=cut |
91 |
|
92 |
__PACKAGE__->set_primary_key("link_id"); |
93 |
|
94 |
=head1 UNIQUE CONSTRAINTS |
95 |
|
96 |
=head2 C<accountline_link_unique> |
97 |
|
98 |
=over 4 |
99 |
|
100 |
=item * L</accountlines_id> |
101 |
|
102 |
=item * L</link_type> |
103 |
|
104 |
=item * L</linked_id> |
105 |
|
106 |
=back |
107 |
|
108 |
=cut |
109 |
|
110 |
__PACKAGE__->add_unique_constraint( |
111 |
"accountline_link_unique", |
112 |
["accountlines_id", "link_type", "linked_id"], |
113 |
); |
114 |
|
115 |
=head1 RELATIONS |
116 |
|
117 |
=head2 accountline |
118 |
|
119 |
Type: belongs_to |
120 |
|
121 |
Related object: L<Koha::Schema::Result::Accountline> |
122 |
|
123 |
=cut |
124 |
|
125 |
__PACKAGE__->belongs_to( |
126 |
"accountline", |
127 |
"Koha::Schema::Result::Accountline", |
128 |
{ accountlines_id => "accountlines_id" }, |
129 |
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, |
130 |
); |
131 |
|
132 |
|
133 |
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-09-15 11:50:54 |
134 |
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xnOrV5Pdyzk+lMWHm8S1XQ |
135 |
|
136 |
=head2 linked_object |
137 |
|
138 |
Returns the linked object based on link_type and linked_id. |
139 |
This is a polymorphic relationship. |
140 |
|
141 |
=cut |
142 |
|
143 |
sub linked_object { |
144 |
my ($self) = @_; |
145 |
|
146 |
my $type_map = { |
147 |
'hold' => ['Reserve', 'reserve_id'], |
148 |
'old_hold' => ['OldReserve', 'reserve_id'], |
149 |
'checkout' => ['Issue', 'issue_id'], |
150 |
'old_checkout' => ['OldIssue', 'issue_id'], |
151 |
'article_request' => ['ArticleRequest', 'id'], |
152 |
}; |
153 |
|
154 |
my ($result_class, $key_field) = @{$type_map->{$self->link_type} || []}; |
155 |
return unless $result_class; |
156 |
|
157 |
return $self->result_source->schema->resultset($result_class)->find({ |
158 |
$key_field => $self->linked_id |
159 |
}); |
160 |
} |
161 |
|
162 |
=head2 linked_object_class |
163 |
|
164 |
Returns the Koha::Object class name for the linked object |
165 |
|
166 |
=cut |
167 |
|
168 |
sub linked_object_class { |
169 |
my ($self) = @_; |
170 |
|
171 |
my $class_map = { |
172 |
'hold' => 'Koha::Hold', |
173 |
'old_hold' => 'Koha::Old::Hold', |
174 |
'checkout' => 'Koha::Checkout', |
175 |
'old_checkout' => 'Koha::Old::Checkout', |
176 |
'article_request' => 'Koha::ArticleRequest', |
177 |
}; |
178 |
|
179 |
return $class_map->{$self->link_type}; |
180 |
} |
181 |
|
182 |
=head2 validate_link_integrity |
183 |
|
184 |
Validates that the linked entity actually exists |
185 |
|
186 |
=cut |
187 |
|
188 |
sub validate_link_integrity { |
189 |
my ($self) = @_; |
190 |
|
191 |
my $linked_object = $self->linked_object; |
192 |
return defined($linked_object) ? 1 : 0; |
193 |
} |
194 |
|
195 |
# You can replace this text with custom code or comments, and it will be preserved on regeneration |
196 |
1; |