LP#1795906: Allow more configuration of queue position calculation user/miker/lp1795906-hold_queue_pos_by_depth
authorMike Rylander <mrylander@gmail.com>
Tue, 22 Jan 2019 16:45:54 +0000 (11:45 -0500)
committerMike Rylander <mrylander@gmail.com>
Tue, 22 Jan 2019 16:45:54 +0000 (11:45 -0500)
Here we convert the global flag to a YAOUS that allows each library to specify
a "sharing depth" for hold queue position as shown to the patron.  Staff
retain direct control over the context of this calculation by means of an org
selector in the relevant UIs.

Values of note for the YAOUS:
 * Completely unset: restrict peer holds to the context hold's pickup library
 * Depth == 0: Treat all holds as queue peers, regardless of pickup library

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql

index 4109948..25e1643 100644 (file)
@@ -1365,19 +1365,32 @@ sub retrieve_hold_queue_status_impl {
     # share the same hold type and target.  The latter part exists to
     # accomodate holds that currently have no potential copies.
     #
-    # The global flag circ.holds.queue_position_relative_to_pickup_lib
-    # controls whether or not to restrict that set of holds to the
-    # ones that also share the same pickup library. Restricting the set
-    # to the pickup library offers a modest performance benefit and
+    # The org setting circ.holds.queue_position_relative_to_pickup_depth
+    # controls the org depth used to restrict that set of holds to the
+    # ones that also share the same pickup library ranged to the depth
+    # specified by the setting. Restricting the set to the pickup library
+    # modulo the specifed depth offers a modest performance benefit and
     # makes the queue position in the public catalog match the position
     # displayed in the staff hold shelf list. However, if resources
     # are shared across the entire consortium, a pickup-library-restricted
     # queue position may make patrons think that they are going to
-    # get their materials sooner than they should expect; this is why
-    # the global flag is provided.
+    # get their materials sooner than they should expect; this setting
+    # allows administrators to specify the effective share depth for any
+    # given set of libraries.  The default is the pickup library and its
+    # descendants when no setting value is present.
 
-    my $relative_to_pickup_lib = $e->retrieve_config_global_flag('circ.holds.queue_position_relative_to_pickup_lib');
-    $relative_to_pickup_lib = ($relative_to_pickup_lib and $U->is_true($relative_to_pickup_lib->enabled));
+    my $relative_to_pickup_lib = $U->ou_ancestor_setting_value(
+        $hold->pickup_lib, 
+        'circ.holds.queue_position_relative_to_pickup_depth', $e);
+
+    if (!defined($relative_to_pickup_lib) or $relative_to_pickup_library > 0) {
+        # restricted sharing b/c depth is not set (pickup lib) or is set but > 0
+        $relative_to_pickup_lib = $U->get_org_descendants(
+            $hold->pickup_lib, $relative_to_pickup_lib); # returns an id list, which is what we want
+    } else {
+        # consortial-wide sharing b/c depth == 0
+        $relative_to_pickup_lib = undef;
+    };
 
     my $q_holds = $e->json_query({
 
@@ -1386,7 +1399,7 @@ sub retrieve_hold_queue_status_impl {
         select => {ahr => ['id', 'cut_in_line', 'request_time']},
         from   => 'ahr',
         where => {
-            ($relative_to_pickup_lib) ? ( pickup_lib => $hold->pickup_lib ) : (),
+            ($relative_to_pickup_lib) ? ( pickup_lib => $relative_to_pickup_lib ) : (),
             id => { in => {
                 select => { ahcm => ['hold'] },
                 from   => {
@@ -1430,7 +1443,7 @@ sub retrieve_hold_queue_status_impl {
                 { "class" => "ahr", "field" => "request_time" }
             ],
             where    => {
-                ($relative_to_pickup_lib) ? ( pickup_lib => $hold->pickup_lib ) : (),
+                ($relative_to_pickup_lib) ? ( pickup_lib => $relative_to_pickup_lib ) : (),
                 hold_type => $hold->hold_type,
                 target    => $hold->target,
                 capture_time => undef,
index 61f7e37..28a4561 100644 (file)
@@ -13672,6 +13672,7 @@ INSERT INTO config.usr_setting_type (name,grp,opac_visible,label,description,dat
         'description'
     ),
     'string'
+
 ), (
     'ui.grid_columns.actor.user.event_log',
     'gui',
@@ -15114,6 +15115,22 @@ INSERT INTO config.org_unit_setting_type
         ),
         'circ',
         'bool'
+    ), (
+        'circ.holds.queue_position_relative_to_pickup_depth',
+        oils_i18n_gettext(
+            'circ.holds.queue_position_relative_to_pickup_depth',
+            'Patron-visible Hold Queue Position Calculation Depth',
+            'coust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'circ.holds.queue_position_relative_to_pickup_depth',
+            'For patron-visible hold queue position calculation, adjust the org unit depth used to find peer holds. Unset means pickup library and descendants, 0 means "full org tree".',
+            'coust',
+            'description'
+        ),
+        'hold',
+        'integer'
     );
 
 INSERT INTO config.org_unit_setting_type 
@@ -19413,13 +19430,3 @@ VALUES (
     )
 );
 
-INSERT INTO config.global_flag (name, label, enabled) VALUES (
-    'circ.holds.queue_position_relative_to_pickup_lib',
-    oils_i18n_gettext(
-        'circ.holds.queue_position_relative_to_pickup_lib',
-        'Calculate hold queue position relative to pickup library (as opposed to entire consortium)',
-        'cgf',
-        'label'
-    ),
-    TRUE
-);