Bug 18591: Allow any number of comments on ILLs
[koha.git] / Koha / Illrequest.pm
index cc61a87..cc8e321 100644 (file)
@@ -29,6 +29,7 @@ use Try::Tiny;
 use Koha::Database;
 use Koha::Email;
 use Koha::Exceptions::Ill;
+use Koha::Illcomments;
 use Koha::Illrequestattributes;
 use Koha::Patron;
 
@@ -119,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
@@ -1024,6 +1036,10 @@ sub TO_JSON {
                 $self->branchcode
             )->TO_JSON;
         }
+        # Augment the request response with the number of comments if appropriate
+        if ( $embed->{comments} ) {
+            $object->{comments} = $self->illcomments->count;
+        }
     }
 
     return $object;