Bug 21111: Add --exclude-indexes to koha-run-backups
[koha-ffzg.git] / Koha / Biblio.pm
index 28609dc..29c7d1e 100644 (file)
@@ -4,18 +4,18 @@ package Koha::Biblio;
 #
 # 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 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.
+# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# 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;
 
@@ -37,7 +37,7 @@ use Koha::ArticleRequest::Status;
 use Koha::ArticleRequests;
 use Koha::Biblio::Metadatas;
 use Koha::Biblioitems;
-use Koha::IssuingRules;
+use Koha::CirculationRules;
 use Koha::Item::Transfer::Limits;
 use Koha::Items;
 use Koha::Libraries;
@@ -98,20 +98,20 @@ sub orders {
     return Koha::Acquisition::Orders->_new_from_dbic($orders);
 }
 
-=head3 active_orders_count
+=head3 active_orders
 
-my $orders_count = $biblio->active_orders_count();
+my $active_orders = $biblio->active_orders();
 
-Returns the number of active acquisition orders related to this biblio.
+Returns the active acquisition orders related to this biblio.
 An order is considered active when it is not cancelled (i.e. when datecancellation
 is not undef).
 
 =cut
 
-sub active_orders_count {
+sub active_orders {
     my ( $self ) = @_;
 
-    return $self->orders->search({ datecancellationprinted => undef })->count;
+    return $self->orders->search({ datecancellationprinted => undef });
 }
 
 =head3 can_article_request
@@ -205,10 +205,11 @@ sub can_be_transferred {
 
 =head3 pickup_locations
 
-@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
+    my $pickup_locations = $biblio->pickup_locations( {patron => $patron } );
 
-Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
-and if item can be transferred to each pickup location.
+Returns an I<arrayref> of possible pickup locations for this biblio's items,
+according to patron's home library (if patron is defined and holds are allowed
+only from hold groups) and if item can be transferred to each pickup location.
 
 =cut
 
@@ -219,14 +220,14 @@ sub pickup_locations {
 
     my @pickup_locations;
     foreach my $item_of_bib ($self->items->as_list) {
-        push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} );
+        push @pickup_locations, @{ $item_of_bib->pickup_locations( {patron => $patron} ) };
     }
 
     my %seen;
     @pickup_locations =
       grep { !$seen{ $_->branchcode }++ } @pickup_locations;
 
-    return wantarray ? @pickup_locations : \@pickup_locations;
+    return \@pickup_locations;
 }
 
 =head3 hidden_in_opac
@@ -299,10 +300,16 @@ sub article_request_type_for_bib {
     my $borrowertype = $borrower->categorycode;
     my $itemtype     = $self->itemtype();
 
-    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype });
+    my $rule = Koha::CirculationRules->get_effective_rule(
+        {
+            rule_name    => 'article_requests',
+            categorycode => $borrowertype,
+            itemtype     => $itemtype,
+        }
+    );
 
-    return q{} unless $issuing_rule;
-    return $issuing_rule->article_requests || q{}
+    return q{} unless $rule;
+    return $rule->rule_value || q{}
 }
 
 =head3 article_request_type_for_items
@@ -411,20 +418,6 @@ sub items {
     return Koha::Items->_new_from_dbic( $items_rs );
 }
 
-=head3 items_count
-
-my $items_count = $biblio->items();
-
-Returns the count of the the related Koha::Items object for this biblio
-
-=cut
-
-sub items_count {
-    my ($self) = @_;
-
-    return $self->_result->items->count;
-}
-
 =head3 itemtype
 
 my $itemtype = $biblio->itemtype();
@@ -517,20 +510,6 @@ sub subscriptions {
     return $self->{_subscriptions};
 }
 
-=head3 subscriptions_count
-
-my $subscriptions_count = $self->subscriptions_count
-
-Returns the count of the the related Koha::Subscriptions object for this biblio
-
-=cut
-
-sub subscriptions_count {
-    my ($self) = @_;
-
-    return $self->subscriptions->count;
-}
-
 =head3 has_items_waiting_or_intransit
 
 my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
@@ -663,7 +642,8 @@ sub get_coins {
                 push @authors, $au;
             }
         }
-        $title = $record->field('245')->as_string('ab');
+        $title = $record->field('245');
+        $title &&= $title->as_string('ab');
         if ($titletype eq 'a') {
             $pubyear   = $record->field('008') || '';
             $pubyear   = substr($pubyear->data(), 7, 4) if $pubyear;
@@ -800,6 +780,21 @@ sub custom_cover_image_url {
     return $url;
 }
 
+=head3 cover_images
+
+Return the cover images associated with this biblio.
+
+=cut
+
+sub cover_images {
+    my ( $self ) = @_;
+
+    my $cover_images_rs = $self->_result->cover_images;
+    return unless $cover_images_rs;
+    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
+}
+
+
 =head3 to_api
 
     my $json = $biblio->to_api;
@@ -813,16 +808,8 @@ on the API.
 sub to_api {
     my ($self, $args) = @_;
 
-    my @embeds = keys %{ $args->{embed} };
-    my $remaining_embeds = {};
-
-    foreach my $embed (@embeds) {
-        $remaining_embeds = delete $args->{embed}->{$embed}
-            unless $self->can($embed);
-    }
-
     my $response = $self->SUPER::to_api( $args );
-    my $biblioitem = $self->biblioitem->to_api({ embed => $remaining_embeds });
+    my $biblioitem = $self->biblioitem->to_api;
 
     return { %$response, %$biblioitem };
 }