|
Lines 19-24
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use base qw(Koha::Object); |
20 |
use base qw(Koha::Object); |
| 21 |
|
21 |
|
|
|
22 |
use Koha::Biblio::Volume::Items; |
| 23 |
use Koha::Exceptions::Object; |
| 24 |
use Koha::Items; |
| 25 |
|
| 22 |
=head1 NAME |
26 |
=head1 NAME |
| 23 |
|
27 |
|
| 24 |
Koha::Volume - Koha Volume Object class |
28 |
Koha::Volume - Koha Volume Object class |
|
Lines 27-34
Koha::Volume - Koha Volume Object class
Link Here
|
| 27 |
|
31 |
|
| 28 |
=head2 Class methods |
32 |
=head2 Class methods |
| 29 |
|
33 |
|
|
|
34 |
=head3 store |
| 35 |
|
| 36 |
$volume->store; |
| 37 |
|
| 38 |
Overloaded I<store> method that takes care of creation date handling. |
| 39 |
|
| 40 |
=cut |
| 41 |
|
| 42 |
sub store { |
| 43 |
my ($self) = @_; |
| 44 |
|
| 45 |
unless ( $self->in_storage ) { |
| 46 |
# new entry |
| 47 |
$self->set( |
| 48 |
{ |
| 49 |
created_on => \'NOW()' |
| 50 |
} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
return $self->SUPER::store(); |
| 55 |
} |
| 56 |
|
| 57 |
=head3 items |
| 58 |
|
| 59 |
my $items = $volume->items; |
| 60 |
|
| 61 |
Returns all the items linked to the volume. |
| 62 |
|
| 63 |
=cut |
| 64 |
|
| 65 |
sub items { |
| 66 |
my ($self) = @_; |
| 67 |
|
| 68 |
my $items_rs = $self->_result->volume_items; |
| 69 |
my @item_numbers = $items_rs->get_column('itemnumber')->all; |
| 70 |
|
| 71 |
return unless @item_numbers; |
| 72 |
|
| 73 |
return Koha::Items->search( |
| 74 |
{ |
| 75 |
itemnumber => { |
| 76 |
-in => \@item_numbers |
| 77 |
} |
| 78 |
} |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
=head3 add_item |
| 83 |
|
| 84 |
$volume->add_item({ item_id => $item_id }); |
| 85 |
|
| 30 |
=cut |
86 |
=cut |
| 31 |
|
87 |
|
|
|
88 |
sub add_item { |
| 89 |
my ($self, $params) = @_; |
| 90 |
|
| 91 |
my $item_id = $params->{item_id}; |
| 92 |
|
| 93 |
my $item = Koha::Items->find( $item_id ); |
| 94 |
unless ( $item->biblionumber == $self->biblionumber ) { |
| 95 |
Koha::Exceptions::Object::FKConstraint->throw( |
| 96 |
broken_fk => 'biblionumber' |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
Koha::Biblio::Volume::Item->new( |
| 101 |
{ |
| 102 |
itemnumber => $item_id, |
| 103 |
volume_id => $self->id |
| 104 |
} |
| 105 |
)->store; |
| 106 |
|
| 107 |
return $self; |
| 108 |
} |
| 109 |
|
| 110 |
=head3 to_api_mapping |
| 111 |
|
| 112 |
This method returns the mapping for representing a Koha::Biblio::Volume object |
| 113 |
on the API. |
| 114 |
|
| 115 |
=cut |
| 116 |
|
| 117 |
sub to_api_mapping { |
| 118 |
return { |
| 119 |
id => 'volume_id', |
| 120 |
biblionumber => 'biblio_id', |
| 121 |
created_on => 'creation_date', |
| 122 |
updated_on => 'modification_date' |
| 123 |
}; |
| 124 |
} |
| 125 |
|
| 32 |
=head2 Internal methods |
126 |
=head2 Internal methods |
| 33 |
|
127 |
|
| 34 |
=head3 _type |
128 |
=head3 _type |
| 35 |
- |
|
|