| Lines 27-32
          use Koha::Database;
      
      
        Link Here | 
        
          | 27 |  | 27 |  | 
        
          | 28 | use base qw(Koha::Object); | 28 | use base qw(Koha::Object); | 
        
          | 29 |  | 29 |  | 
            
              |  |  | 30 | use C4::Circulation qw(GetIssuingRule); | 
            
              | 31 | use Koha::Items; | 
            
              | 32 | use Koha::Biblioitems; | 
            
              | 33 | use Koha::ArticleRequests; | 
            
              | 34 | use Koha::ArticleRequest::Status; | 
            
              | 35 |  | 
        
          | 30 | =head1 NAME | 36 | =head1 NAME | 
        
          | 31 |  | 37 |  | 
        
          | 32 | Koha::Biblio - Koha Biblio Object class | 38 | Koha::Biblio - Koha Biblio Object class | 
  
    | Lines 53-58
          sub subtitles {
      
      
        Link Here | 
        
          | 53 |     return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) }; | 59 |     return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) }; | 
        
          | 54 | } | 60 | } | 
        
          | 55 |  | 61 |  | 
            
              |  |  | 62 | =head3 can_article_request | 
            
              | 63 |  | 
            
              | 64 | my $bool = $biblio->can_article_request( $borrower ); | 
            
              | 65 |  | 
            
              | 66 | Returns true if article requests can be made for this record | 
            
              | 67 |  | 
            
              | 68 | $borrower must be a Koha::Borrower object | 
            
              | 69 |  | 
            
              | 70 | =cut | 
            
              | 71 |  | 
            
              | 72 | sub can_article_request { | 
            
              | 73 |     my ( $self, $borrower ) = @_; | 
            
              | 74 |  | 
            
              | 75 |     my $rule = $self->article_request_type($borrower); | 
            
              | 76 |     return q{} if $rule eq 'item_only' && !$self->items()->count(); | 
            
              | 77 |     return 1 if $rule && $rule ne 'no'; | 
            
              | 78 |  | 
            
              | 79 |     return q{}; | 
            
              | 80 | } | 
            
              | 81 |  | 
            
              | 82 | =head3 article_request_type | 
            
              | 83 |  | 
            
              | 84 | my $type = $biblio->article_request_type( $borrower ); | 
            
              | 85 |  | 
            
              | 86 | Returns the article request type based on items, or on the record | 
            
              | 87 | itself if there are no items. | 
            
              | 88 |  | 
            
              | 89 | $borrower must be a Koha::Borrower object | 
            
              | 90 |  | 
            
              | 91 | =cut | 
            
              | 92 |  | 
            
              | 93 | sub article_request_type { | 
            
              | 94 |     my ( $self, $borrower ) = @_; | 
            
              | 95 |  | 
            
              | 96 |     return q{} unless $borrower; | 
            
              | 97 |  | 
            
              | 98 |     my $rule = $self->article_request_type_for_items( $borrower ); | 
            
              | 99 |     return $rule if $rule; | 
            
              | 100 |  | 
            
              | 101 |     # If the record has no items that are requestable, go by the record itemtype | 
            
              | 102 |     $rule = $self->article_request_type_for_bib($borrower); | 
            
              | 103 |     return $rule if $rule; | 
            
              | 104 |  | 
            
              | 105 |     return q{}; | 
            
              | 106 | } | 
            
              | 107 |  | 
            
              | 108 | =head3 article_request_type_for_bib | 
            
              | 109 |  | 
            
              | 110 | my $type = $biblio->article_request_type_for_bib | 
            
              | 111 |  | 
            
              | 112 | Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record | 
            
              | 113 |  | 
            
              | 114 | =cut | 
            
              | 115 |  | 
            
              | 116 | sub article_request_type_for_bib { | 
            
              | 117 |     my ( $self, $borrower ) = @_; | 
            
              | 118 |  | 
            
              | 119 |     return q{} unless $borrower; | 
            
              | 120 |  | 
            
              | 121 |     my $borrowertype = $borrower->categorycode; | 
            
              | 122 |     my $itemtype     = $self->itemtype(); | 
            
              | 123 |  | 
            
              | 124 |     my $rules        = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype ); | 
            
              | 125 |  | 
            
              | 126 |     return $rules->{article_requests} || q{}; | 
            
              | 127 | } | 
            
              | 128 |  | 
            
              | 129 | =head3 article_request_type_for_items | 
            
              | 130 |  | 
            
              | 131 | my $type = $biblio->article_request_type_for_items | 
            
              | 132 |  | 
            
              | 133 | Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items | 
            
              | 134 |  | 
            
              | 135 | If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned. | 
            
              | 136 |  | 
            
              | 137 | =cut | 
            
              | 138 |  | 
            
              | 139 | sub article_request_type_for_items { | 
            
              | 140 |     my ( $self, $borrower ) = @_; | 
            
              | 141 |  | 
            
              | 142 |     my $counts; | 
            
              | 143 |     foreach my $item ( $self->items()->as_list() ) { | 
            
              | 144 |         my $rule = $item->article_request_type($borrower); | 
            
              | 145 |         return $rule if $rule eq 'bib_only';    # we don't need to go any further | 
            
              | 146 |         $counts->{$rule}++; | 
            
              | 147 |     } | 
            
              | 148 |  | 
            
              | 149 |     return 'item_only' if $counts->{item_only}; | 
            
              | 150 |     return 'yes'       if $counts->{yes}; | 
            
              | 151 |     return 'no'        if $counts->{no}; | 
            
              | 152 |     return q{}; | 
            
              | 153 | } | 
            
              | 154 |  | 
            
              | 155 | =head3 article_requests | 
            
              | 156 |  | 
            
              | 157 | my @requests = $biblio->article_requests | 
            
              | 158 |  | 
            
              | 159 | Returns the article requests associated with this Biblio | 
            
              | 160 |  | 
            
              | 161 | =cut | 
            
              | 162 |  | 
            
              | 163 | sub article_requests { | 
            
              | 164 |     my ( $self, $borrower ) = @_; | 
            
              | 165 |  | 
            
              | 166 |     $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } ); | 
            
              | 167 |  | 
            
              | 168 |     return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests}; | 
            
              | 169 | } | 
            
              | 170 |  | 
            
              | 171 | =head3 article_requests_current | 
            
              | 172 |  | 
            
              | 173 | my @requests = $biblio->article_requests_current | 
            
              | 174 |  | 
            
              | 175 | Returns the article requests associated with this Biblio that are incomplete | 
            
              | 176 |  | 
            
              | 177 | =cut | 
            
              | 178 |  | 
            
              | 179 | sub article_requests_current { | 
            
              | 180 |     my ( $self, $borrower ) = @_; | 
            
              | 181 |  | 
            
              | 182 |     $self->{_article_requests_current} ||= Koha::ArticleRequests->search( | 
            
              | 183 |         { | 
            
              | 184 |             biblionumber => $self->biblionumber(), | 
            
              | 185 |             -or          => [ | 
            
              | 186 |                 { status => Koha::ArticleRequest::Status::Pending }, | 
            
              | 187 |                 { status => Koha::ArticleRequest::Status::Processing } | 
            
              | 188 |             ] | 
            
              | 189 |         } | 
            
              | 190 |     ); | 
            
              | 191 |  | 
            
              | 192 |     return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current}; | 
            
              | 193 | } | 
            
              | 194 |  | 
            
              | 195 | =head3 article_requests_finished | 
            
              | 196 |  | 
            
              | 197 | my @requests = $biblio->article_requests_finished | 
            
              | 198 |  | 
            
              | 199 | Returns the article requests associated with this Biblio that are completed | 
            
              | 200 |  | 
            
              | 201 | =cut | 
            
              | 202 |  | 
            
              | 203 | sub article_requests_finished { | 
            
              | 204 |     my ( $self, $borrower ) = @_; | 
            
              | 205 |  | 
            
              | 206 |     $self->{_article_requests_finished} ||= Koha::ArticleRequests->search( | 
            
              | 207 |         { | 
            
              | 208 |             biblionumber => $self->biblionumber(), | 
            
              | 209 |             -or          => [ | 
            
              | 210 |                 { status => Koha::ArticleRequest::Status::Completed }, | 
            
              | 211 |                 { status => Koha::ArticleRequest::Status::Canceled } | 
            
              | 212 |             ] | 
            
              | 213 |         } | 
            
              | 214 |     ); | 
            
              | 215 |  | 
            
              | 216 |     return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished}; | 
            
              | 217 | } | 
            
              | 218 |  | 
            
              | 219 | =head3 items | 
            
              | 220 |  | 
            
              | 221 | my @items = $biblio->items(); | 
            
              | 222 | my $items = $biblio->items(); | 
            
              | 223 |  | 
            
              | 224 | Returns a list of Koha::Item objects or a Koha::Items object of | 
            
              | 225 | items associated with this bib | 
            
              | 226 |  | 
            
              | 227 | =cut | 
            
              | 228 |  | 
            
              | 229 | sub items { | 
            
              | 230 |     my ( $self ) = @_; | 
            
              | 231 |  | 
            
              | 232 |     $self->{_items} ||= Koha::Items->search({ biblionumber => $self->biblionumber() }); | 
            
              | 233 |  | 
            
              | 234 |     return $self->{_items}; | 
            
              | 235 | } | 
            
              | 236 |  | 
            
              | 237 | =head3 itemtype | 
            
              | 238 |  | 
            
              | 239 | my $itemtype = $biblio->itemtype(); | 
            
              | 240 |  | 
            
              | 241 | Returns the itemtype for this record. | 
            
              | 242 |  | 
            
              | 243 | =cut | 
            
              | 244 |  | 
            
              | 245 | sub itemtype { | 
            
              | 246 |     my ( $self ) = @_; | 
            
              | 247 |  | 
            
              | 248 |     return $self->_biblioitem()->itemtype(); | 
            
              | 249 | } | 
            
              | 250 |  | 
            
              | 251 | =head3 _biblioitem | 
            
              | 252 |  | 
            
              | 253 | my $field = $self->_biblioitem()->itemtype | 
            
              | 254 |  | 
            
              | 255 | Returns the related Koha::Biblioitem object for this Biblio object | 
            
              | 256 |  | 
            
              | 257 | =cut | 
            
              | 258 |  | 
            
              | 259 | sub _biblioitem { | 
            
              | 260 |     my ($self) = @_; | 
            
              | 261 |  | 
            
              | 262 |     $self->{_biblioitem} ||= Koha::Biblioitems->find( { biblionumber => $self->biblionumber() } ); | 
            
              | 263 |  | 
            
              | 264 |     return $self->{_biblioitem}; | 
            
              | 265 | } | 
        
          | 56 |  | 266 |  | 
        
          | 57 | =head3 type | 267 | =head3 type | 
        
          | 58 |  | 268 |  |