3 INSERT INTO config.upgrade_log (version) VALUES ('0282');
5 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
6 VALUES ('history.hold.retention_age', TRUE, 'Historical Hold Retention Age', 'Historical Hold Retention Age', 'interval');
7 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
8 VALUES ('history.hold.retention_count', TRUE, 'Historical Hold Retention Count', 'Historical Hold Retention Count', 'integer');
11 -- Logic reversal, fixing
12 CREATE OR REPLACE FUNCTION action.usr_visible_circs (usr_id INT) RETURNS SETOF action.circulation AS $func$
14 c action.circulation%ROWTYPE;
16 usr_view_age actor.usr_setting%ROWTYPE;
17 usr_view_start actor.usr_setting%ROWTYPE;
19 SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_age';
20 SELECT * INTO usr_view_start FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_start_date';
22 IF usr_view_age.value IS NOT NULL AND usr_view_start.value IS NOT NULL THEN
23 -- User opted in and supplied a retention age
24 IF oils_json_to_string(usr_view_age.value)::INTERVAL > AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ) THEN
25 view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
27 view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
29 ELSIF usr_view_start.value IS NOT NULL THEN
31 view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
33 -- User did not opt in
39 FROM action.circulation
41 AND parent_circ IS NULL
42 AND xact_start > NOW() - view_age
50 $func$ LANGUAGE PLPGSQL;
52 CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$
54 h action.hold_request%ROWTYPE;
57 usr_view_count actor.usr_setting%ROWTYPE;
58 usr_view_age actor.usr_setting%ROWTYPE;
60 SELECT * INTO usr_view_count FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_count';
61 SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_age';
63 IF usr_view_count.value IS NULL AND usr_view_age.value IS NULL THEN
64 -- Only show "open" holds
67 FROM action.hold_request
69 AND fulfillment_time IS NULL
70 AND cancel_time IS NULL
79 IF usr_view_age.value IS NOT NULL THEN
80 view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
82 view_age := '2000 years'::INTERVAL;
85 IF usr_view_count.value IS NOT NULL THEN
86 view_count := oils_json_to_string(usr_view_count.value)::INT;
91 -- Else, show those /and/ some fulfilled/canceled holds
94 FROM action.hold_request
96 AND fulfillment_time IS NULL
97 AND cancel_time IS NULL
100 FROM action.hold_request
102 AND ( fulfillment_time IS NOT NULL OR cancel_time IS NOT NULL )
103 AND request_time > NOW() - view_age
104 ORDER BY request_time
112 $func$ LANGUAGE PLPGSQL;