OPAC Catalog Result Course Column
authorKyle Huckins <khuckins@catalyte.io>
Fri, 6 Dec 2019 23:12:25 +0000 (23:12 +0000)
committerJane Sandberg <sandbej@linnbenton.edu>
Mon, 7 Sep 2020 18:11:25 +0000 (11:11 -0700)
- Implement Course column to view Course Numbers of classes associated
with individual copies.

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm
modified:   Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
modified:   Open-ILS/src/templates/opac/parts/record/copy_table.tt2

Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/templates/opac/parts/record/copy_table.tt2

index bb4412b..4543301 100644 (file)
@@ -1044,6 +1044,44 @@ sub delete_copy_note {
     $e->commit;
     return 1;
 }
+__PACKAGE__->register_method(
+    method          => 'fetch_course_materials',
+    autoritative    => 1,
+    api_name        => 'open-ils.circ.course_materials.retrieve',
+    signature       => q/
+        Returns an array of course materials.
+        @params copy_id     : The id of the item who's materials we want to retrieve
+    /);
+
+__PACKAGE__->register_method(
+    method          => 'fetch_courses',
+    autoritative    => 1,
+    api_name        => 'open-ils.circ.courses.retrieve',
+    signature       => q/
+        Returns an array of course materials.
+        @params course_id: The id of the course we want to retrieve
+    /);
+
+sub fetch_course_materials {
+    my ($self, $conn, $copy_id) = @_;
+    my $e = new_editor();
+
+    return $e->search_asset_course_module_course_materials({item => $copy_id});
+}
+
+sub fetch_courses {
+    my ($self, $conn, @course_ids) = @_;
+    my $e = new_editor();
+    return unless @course_ids;
+
+    my $targets = ();
+    foreach my $course_id (@course_ids) {
+        my $target = $e->retrieve_asset_course_module_course($course_id);
+        push @$targets, $target;
+    }
+
+    return $targets;
+}
 
 __PACKAGE__->register_method(
     method      => 'fetch_copy_tags',
index bc3972b..9057258 100644 (file)
@@ -102,8 +102,13 @@ sub load_record {
 
     $ctx->{copies} = $copy_rec->gather(1);
 
+    my $course_module_opt_in = 0;
+    if ($ctx->{get_org_setting}->($org, "circ.course_materials_opt_in")) {
+        $course_module_opt_in = 1;
+    }
+
     # Add public copy notes to each copy - and while we're in there, grab peer bib records
-    # and copy tags
+    # and copy tags. Oh and if we're working with course materials, those too.
     my %cached_bibs = ();
     foreach my $copy (@{$ctx->{copies}}) {
         $copy->{notes} = $U->simplereq(
@@ -111,6 +116,23 @@ sub load_record {
             'open-ils.circ.copy_note.retrieve.all',
             {itemid => $copy->{id}, pub => 1 }
         );
+        if ($course_module_opt_in) {
+            $copy->{course_materials} = $U->simplereq(
+                'open-ils.circ',
+                'open-ils.circ.course_materials.retrieve',
+                $copy->{id}
+            );
+            my %course_ids;
+            for my $material (@{$copy->{course_materials}}) {
+                $course_ids{$material->course} = 1;
+            }
+
+            $copy->{courses} = $U->simplereq(
+                'open-ils.circ',
+                'open-ils.circ.courses.retrieve',
+                keys %course_ids
+            );
+        }
         $self->timelog("past copy note retrieval call");
         my $meth = 'open-ils.circ.copy_tags.retrieve';
         $meth .= ".staff" if $ctx->{is_staff};
index 9d126f6..f09e37b 100644 (file)
@@ -54,6 +54,9 @@ IF has_copies or ctx.foreign_copies;
             [%- END %]
             <th scope='col'>[% l("Status") %]</th>
             <th scope='col'>[% l("Due Date") %]</th>
+            [%- IF ctx.get_org_setting(ctx.aou_tree.id, 'circ.course_materials_opt_in') == 1 %]
+            <th scope='col'>[% l("Courses") %]</th>
+            [%- END %]
         </tr>
     </thead>
     <tbody class="copy_details_table">
@@ -75,6 +78,10 @@ IF has_copies or ctx.foreign_copies;
     <td>[% bib.target_copy.location.name | html %]</td>
     <td>[% bib.target_copy.status.name | html %]</td>
     <td>[% date.format(ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),DATE_FORMAT) %]</td>
+    [%- IF ctx.get_org_setting(CGI.param('loc') 
+        OR ctx.aou_tree.id, 'circ.course_materials_opt_in') == 1 %]
+    <td></td>
+    [%- END %]
 </tr>
    [%- END; # FOREACH peer
 END; # FOREACH bib
@@ -223,6 +230,11 @@ END; # FOREACH bib
                 ELSE;
                     '-';
                 END %]</td>
+            [%- IF ctx.get_org_setting(ctx.aou_tree.id, 'circ.course_materials_opt_in') == 1 %]
+            <td>[%- FOREACH course IN copy_info.courses %]
+                <div>[% course.course_number %]</div>
+            [% END %]</td>
+            [% END %]
         </tr>
 
         [% IF copy_info.notes; %]