Bug 20996: (follow-up) Fix merge problems
[srvgit] / Koha / Illrequest.pm
index 53e9ddc..0b4d71c 100644 (file)
@@ -21,14 +21,17 @@ package Koha::Illrequest;
 use Modern::Perl;
 
 use Clone 'clone';
-use File::Basename qw/basename/;
+use File::Basename qw( basename );
+use Encode qw( encode );
+use Mail::Sendmail;
+use Try::Tiny;
+
 use Koha::Database;
 use Koha::Email;
 use Koha::Exceptions::Ill;
+use Koha::Illcomments;
 use Koha::Illrequestattributes;
 use Koha::Patron;
-use Mail::Sendmail;
-use Try::Tiny;
 
 use base qw(Koha::Object);
 
@@ -117,6 +120,17 @@ sub illrequestattributes {
     );
 }
 
+=head3 illcomments
+
+=cut
+
+sub illcomments {
+    my ( $self ) = @_;
+    return Koha::Illcomments->_new_from_dbic(
+        scalar $self->_result->illcomments
+    );
+}
+
 =head3 patron
 
 =cut
@@ -476,8 +490,8 @@ Return a list of available backends.
 
 sub available_backends {
     my ( $self ) = @_;
-    my @backends = $self->_config->available_backends;
-    return \@backends;
+    my $backends = $self->_config->available_backends;
+    return $backends;
 }
 
 =head3 available_actions
@@ -598,23 +612,24 @@ sub backend_create {
     my ( $self, $params ) = @_;
 
     # Establish whether we need to do a generic copyright clearance.
-    if ( ( !$params->{stage} || $params->{stage} eq 'init' )
-             && C4::Context->preference("ILLModuleCopyrightClearance") ) {
-        return {
-            error   => 0,
-            status  => '',
-            message => '',
-            method  => 'create',
-            stage   => 'copyrightclearance',
-            value   => {
-                backend => $self->_backend->name
-            }
-        };
-    } elsif (     defined $params->{stage}
-               && $params->{stage} eq 'copyrightclearance' ) {
-        $params->{stage} = 'init';
+    if ($params->{opac}) {
+        if ( ( !$params->{stage} || $params->{stage} eq 'init' )
+                && C4::Context->preference("ILLModuleCopyrightClearance") ) {
+            return {
+                error   => 0,
+                status  => '',
+                message => '',
+                method  => 'create',
+                stage   => 'copyrightclearance',
+                value   => {
+                    backend => $self->_backend->name
+                }
+            };
+        } elsif (     defined $params->{stage}
+                && $params->{stage} eq 'copyrightclearance' ) {
+            $params->{stage} = 'init';
+        }
     }
-
     # First perform API action, then...
     my $args = {
         request => $self,
@@ -702,8 +717,7 @@ sub getLimits {
 =head3 getPrefix
 
     my $prefix = $abstract->getPrefix( {
-        brw_cat => $brw_cat,
-        branch  => $branch_code,
+        branch  => $branch_code
     } );
 
 Return the ILL prefix as defined by our $params: either per borrower category,
@@ -713,15 +727,25 @@ per branch or the default.
 
 sub getPrefix {
     my ( $self, $params ) = @_;
-    my $brn_prefixes = $self->_config->getPrefixes('branch');
-    my $brw_prefixes = $self->_config->getPrefixes('brw_cat');
-
-    return $brw_prefixes->{$params->{brw_cat}}
-        || $brn_prefixes->{$params->{branch}}
-        || $brw_prefixes->{default}
-        || "";                  # "the empty prefix"
+    my $brn_prefixes = $self->_config->getPrefixes();
+    return $brn_prefixes->{$params->{branch}} || ""; # "the empty prefix"
 }
 
+=head3 get_type
+
+    my $type = $abstract->get_type();
+
+Return a string representing the material type of this request or undef
+
+=cut
+
+sub get_type {
+    my ($self) = @_;
+    my $attr = $self->illrequestattributes->find({ type => 'type'});
+    return if !$attr;
+    return $attr->value;
+};
+
 #### Illrequests Imports
 
 =head3 check_limits
@@ -952,12 +976,7 @@ file.
 
 sub id_prefix {
     my ( $self ) = @_;
-    my $brw = $self->patron;
-    my $brw_cat = "dummy";
-    $brw_cat = $brw->categorycode
-        unless ( 'HASH' eq ref($brw) && $brw->{deleted} );
     my $prefix = $self->getPrefix( {
-        brw_cat => $brw_cat,
         branch  => $self->branchcode,
     } );
     $prefix .= "-" if ( $prefix );
@@ -989,6 +1008,10 @@ sub _censor {
 Overloaded I<TO_JSON> method that takes care of inserting calculated values
 into the unblessed representation of the object.
 
+TODO: This method does nothing and is not called anywhere. However, bug 74325
+touches it, so keeping this for now until both this and bug 74325 are merged,
+at which point we can sort it out and remove it completely
+
 =cut
 
 sub TO_JSON {
@@ -997,32 +1020,6 @@ sub TO_JSON {
     my $object = $self->SUPER::TO_JSON();
     $object->{id_prefix} = $self->id_prefix;
 
-    if ( scalar (keys %$embed) ) {
-        # Augment the request response with patron details if appropriate
-        if ( $embed->{patron} ) {
-            my $patron = $self->patron;
-            $object->{patron} = {
-                firstname  => $patron->firstname,
-                surname    => $patron->surname,
-                cardnumber => $patron->cardnumber
-            };
-        }
-        # Augment the request response with metadata details if appropriate
-        if ( $embed->{metadata} ) {
-            $object->{metadata} = $self->metadata;
-        }
-        # Augment the request response with status details if appropriate
-        if ( $embed->{capabilities} ) {
-            $object->{capabilities} = $self->capabilities;
-        }
-        # Augment the request response with library details if appropriate
-        if ( $embed->{branch} ) {
-            $object->{branch} = Koha::Libraries->find(
-                $self->branchcode
-            )->TO_JSON;
-        }
-    }
-
     return $object;
 }