$F$ LANGUAGE PLPGSQL STABLE;
--- SEED DATA ---------------------------------------------------------------
-
--- by default, use the same format record attribute as that used for icons
--- TODO: verify attr name still matches
-INSERT INTO config.global_flag (name, label, value, enabled) VALUES (
- 'opac.metarecord.holds.format_attr',
- 'OPAC Metarecord Hold Formats Attribute',
- 'local_format',
- TRUE
-);
-
CREATE OR REPLACE FUNCTION evergreen.ranked_volumes(
bibid BIGINT[],
ouid INT,
RETURNS TABLE (id BIGINT, name TEXT, label_sortkey TEXT, rank INT)
AS $$ SELECT * FROM evergreen.located_uris(ARRAY[$1],$2,$3) $$ LANGUAGE SQL STABLE;
+
+-- SEED DATA ---------------------------------------------------------------
+
+-- TODO: i18n
+
+INSERT INTO config.global_flag (name, label, value, enabled) VALUES (
+ 'opac.metarecord.holds.format_attr',
+ 'OPAC Metarecord Hold Formats Attribute',
+ 'metarecord_hold_format',
+ TRUE
+);
+
+INSERT INTO config.record_attr_definition
+ (name, label, multi, filter, composite) VALUES
+ ('metarecord_hold_format', 'Metarecord Hold Formats', TRUE, TRUE, TRUE);
+
+-- these formats are take verbatim from the JSPAC MR hold format selector
+
+INSERT INTO config.coded_value_map
+ (ctype, code, value, search_label) VALUES
+('metarecord_hold_format', 'book', 'Books', 'Books'),
+('metarecord_hold_format', 'large_print_book', 'Large Print Books','Large Print Books'),
+('metarecord_hold_format', 'e-book', 'E-Books', 'E-Books'),
+('metarecord_hold_format', 'audiobook', 'Audiobooks', 'Audiobooks'),
+('metarecord_hold_format', 'video_recording', 'Video Recordings', 'Video Recordings'),
+('metarecord_hold_format', 'music', 'Music', 'Music');
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id,
+'[{"_attr":"item_type","_val":"a"},{"_attr":"item_type","_val":"t"}]'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'book';
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id,
+'[{"_attr":"item_type","_val":"a"},{"_attr":"item_type","_val":"t"},{"_attr":"item_form","_val":"d"}]'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'large_print_book';
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id,
+'[{"_attr":"item_type","_val":"a"},{"_attr":"item_type","_val":"t"},{"_attr":"item_form","_val":"s"}]'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'e-book';
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id, '{"_attr":"item_type","_val":"i"}'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'audiobook';
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id, '{"_attr":"item_type","_val":"g"}'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'video_recording';
+
+INSERT INTO config.composite_attr_entry_definition (coded_value, definition)
+SELECT ccvm.id, '{"_attr":"item_type","_val":"j"}'
+FROM config.coded_value_map ccvm
+WHERE ccvm.ctype = 'metarecord_hold_format' AND ccvm.code = 'music';
+
+
COMMIT;