From 45c91997dd39d6817a5a470aaca5479b4ce8ffa2 Mon Sep 17 00:00:00 2001 From: ppound Date: Tue, 12 Dec 2023 09:48:01 -0400 Subject: [PATCH] added udm local type method --- udm_citeproc.module | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/udm_citeproc.module b/udm_citeproc.module index 6346736..9cc3af9 100644 --- a/udm_citeproc.module +++ b/udm_citeproc.module @@ -13,6 +13,7 @@ */ function udm_citeproc_convert_mods_to_citeproc_jsons_alter(&$output, $mods) { module_load_include('inc', 'citeproc', 'includes/converter'); + $output['type'] = udm_citeproc_local_to_csl_type($mods); if(empty($output['author'])){ $names = udm_convert_mods_to_citeproc_json_names($mods); $output = array_merge($output, $names); @@ -247,4 +248,39 @@ function udm_convert_mods_to_citeproc_json_name_role(SimpleXMLElement $name, arr return array_key_exists($role, $valid_roles) ? $valid_roles[$role] : FALSE; } return $default_role; -} \ No newline at end of file +} + +/** + * Converts our local types that mostly came from refworks to CSL types. + * + * @param SimpleXML $mods + * @return string + * The CSL type. + */ +function udm_citeproc_local_to_csl_type($mods) { + $genre = $mods->xpath("//mods:mods[1]/mods:genre"); + + if(empty($genre)){ + return convert_mods_to_citeproc_json_type($mods); + } + $term = strtolower(trim((string)$genre[0])); + switch ($term) { + case 'article scientifique': + case '': + return 'article-journal'; + case 'book chapter': + case 'book section': + case 'book, section': + case 'chapitre de livre': + return 'chapter'; + case 'book, whole': + case 'livre': + return 'book'; + case 'conference proceedings': + case 'conference abstract': + case 'Contribution à un congrès, un colloque, une conférence': + return 'paper-conference'; + default: + return convert_mods_to_citeproc_json_type($mods); + } +}