LP1849212: OPAC course browse, search, display improvements
authorJane Sandberg <sandbej@linnbenton.edu>
Thu, 3 Sep 2020 16:00:18 +0000 (09:00 -0700)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 14 Sep 2020 22:17:42 +0000 (18:17 -0400)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Courses.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm
Open-ILS/src/templates/opac/course/results.tt2
Open-ILS/src/templates/opac/parts/course/body.tt2

index 3dc33be..11dcf07 100644 (file)
@@ -3910,6 +3910,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Preferred Suffix" name="pref_suffix" reporter:datatype="text"/>
                        <field reporter:label="Parent/Guardian" name="guardian" reporter:datatype="text"/>
                        <field reporter:label="Name Keywords" name="name_keywords" reporter:datatype="text"/>
+                       <field reporter:label="Name Keyword internal tsvector" name="name_kw_tsvector" reporter:datatype="text"/>
                        <field reporter:label="Additional Permission Groups" name="groups" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field reporter:label="Is Deleted" name="deleted" reporter:datatype="bool"/>
                        <field reporter:label="User Notes" name="notes" oils_persist:virtual="true" reporter:datatype="link"/>
index a68ce6b..577807a 100644 (file)
@@ -186,43 +186,23 @@ __PACKAGE__->register_method(
 sub fetch_course_users {
     my ($self, $conn, $course_id) = @_;
     my $e = new_editor();
-    my $filter = {};
-    my $users = {};
-    my %patrons;
 
-    $filter->{course} = $course_id;
-    $filter->{usr_role}->{is_public} = 't'
-        unless ($self->api_name =~ /\.staff/) and $e->allowed('MANAGE_RESERVES');
-    $users->{list} =  $e->search_asset_course_module_course_users($filter, {flesh => 1, flesh_fields => {acmcu => ['usr_role']}, order_by => {acmcu => 'id'}});
-    for my $course_user (@{$users->{list}}) {
-        my $patron = {};
-        $patron->{id} = $course_user->id;
-        $patron->{usr_role} = $course_user->usr_role;
-        $patron->{patron_data} = $e->retrieve_actor_user($course_user->usr);
-        $patrons{$course_user->usr} = $patron;
-    }
-
-    my $targets = ();
-    for my $user (values %patrons) {
-        my $final_user = {};
-        $final_user->{id} = $user->{id};
-        $final_user->{usr_role} = $user->{usr_role};
-        $final_user->{patron_id} = $user->{patron_data}->id;
-        $final_user->{first_given_name} = $user->{patron_data}->first_given_name;
-        $final_user->{second_given_name} = $user->{patron_data}->second_given_name;
-        $final_user->{family_name} = $user->{patron_data}->family_name;
-        $final_user->{pref_first_given_name} = $user->{patron_data}->pref_first_given_name;
-        $final_user->{pref_family_name} = $user->{patron_data}->pref_family_name;
-        $final_user->{pref_second_given_name} = $user->{patron_data}->pref_second_given_name;
-        $final_user->{pref_suffix} = $user->{patron_data}->pref_suffix;
-        $final_user->{pref_prefix} = $user->{patron_data}->pref_prefix;
-
-        push @$targets, $final_user;
-    }
-
-    return $targets;
+    return $e->json_query({
+        select => {
+            acmcu => ['id'],
+            acmr => [{column => 'name', alias => 'usr_role'}],
+            au => [{column => 'id', alias => 'patron_id'},
+                'first_given_name', 'second_given_name',
+                'family_name', 'pref_first_given_name',
+                'pref_second_given_name', 'pref_family_name',
+                'pref_suffix', 'pref_prefix'],
+        },
+        from => { acmcu => {'acmr' => {}, 'au' => {}} },
+        where => {
+            '+acmcu' => { course => $course_id },
+            '+acmr' => {'is_public' => 't'}
+        },
+    });
 
 }
 
index 88c35aa..46c4521 100644 (file)
@@ -66,7 +66,7 @@ sub load_course_browse {
                     'usr',
                 ]},
                 # TODO: We need to support the chosen library as well...
-                "where" => {'usr_role' => {'in' => {'select' => {'acmr' => ['id']}, 'where' => {'+acmr' => 'is_public'}}}}
+                "where" => {'usr_role' => {'in' => {'from' => 'acmr', 'select' => {'acmr' => ['id']}, 'where' => {'+acmr' => 'is_public'}}}}
             });
             $results = $e->json_query({
                 "from" => "au",
@@ -266,14 +266,9 @@ sub load_cresults {
                     'from' => 'au',
                     'select' => {'au' => ['id']},
                     'where' => {
-                        '-or' => [
-                            {'pref_first_given_name' => {'~*' => $query}},
-                            {'first_given_name' => {'~*' => $query}},
-                            {'pref_second_given_name' => {'~*' => $query}},
-                            {'second_given_name' => {'~*' => $query}},
-                            {'pref_family_name' => {'~*' => $query}},
-                            {'family_name' => {'~*' => $query}}
-                        ]
+                        'name_kw_tsvector' => {
+                            '@@' => {'value' => [ 'plainto_tsquery', $query ] }
+                        }
                     }
                 }}}
             }}};
index d2d68ca..41966bf 100644 (file)
@@ -86,7 +86,7 @@
                     href="[%
                        mkurl(ctx.opac_root _ '/results', {qtype => 'instructor', query => instructorString})
                     %]" rel="nofollow" vocab="">
-                  [% instructorString %] ([% l(instructor.usr_role.name) %])</a>.
+                  [% instructorString %] ([% l(instructor.usr_role) %])</a>.
                   [% END %]
                 </div>
                 <div>
index 7f6333a..2d80caf 100644 (file)
@@ -24,7 +24,7 @@
           ELSE;
             instructorString = instructorString _ instructor.first_given_name;
           END;
-          instructorString = instructorString _ ' (' _ l(instructor.usr_role.name) _ ')'; %]
+          instructorString = instructorString _ ' (' _ l(instructor.usr_role) _ ')'; %]
           <span class="course-instructor-div">[% instructorString %].</span>
         [% END %]
       </div>