-
Notifications
You must be signed in to change notification settings - Fork 35
/
islandora_marcxml.module
147 lines (138 loc) · 5.01 KB
/
islandora_marcxml.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @file
* Defines all the hooks this module implements.
*/
// Permissions.
define('ISLANDORA_MARCXML_VIEW_PERMISSION', 'view marcxml output');
/**
* Implements hook_menu().
*/
function islandora_marcxml_menu() {
return array(
'islandora/object/%islandora_object/view_mods_as_marcxml' => array(
'title' => 'MARCXML',
'type' => MENU_LOCAL_TASK,
'page callback' => 'islandora_marcxml_view',
'page arguments' => array(2),
'access callback' => 'islandora_marcxml_access_callback',
'access arguments' => array(2),
'file' => 'includes/utilities.inc',
),
'islandora/object/%islandora_object/download_mods_as_marcxml' => array(
'title' => 'Download MARCXML',
'type' => MENU_CALLBACK,
'page callback' => 'islandora_marcxml_transform_mods_to_marcxml',
'page arguments' => array(2),
'access callback' => 'islandora_marcxml_access_callback',
'access arguments' => array(2),
'delivery callback' => 'islandora_marcxml_xml_download',
'file' => 'includes/utilities.inc',
),
'islandora/object/%islandora_object/update_mods_from_marcxml' => array(
'title' => 'Update MODS',
'description' => 'Updates the MODS datastream from a new MARCXML source.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_marcxml_edit_file_form', 2),
'access callback' => 'islandora_marcxml_update_access_callback',
'access arguments' => array(2),
'file' => 'includes/edit.form.inc',
),
'admin/islandora/tools/islandora_marcxml' => array(
'title' => 'Islandora MARCXML',
'description' => 'Configure the Islandora MARCXML module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_marcxml_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin.form.inc',
),
);
}
/**
* Implements hook_permission().
*/
function islandora_marcxml_permission() {
return array(
ISLANDORA_MARCXML_VIEW_PERMISSION => array(
'title' => t('View MARCXML Output'),
'description' => t("View MODS to MARCXML output."),
),
);
}
/**
* Delivery callback used to download the output as XML.
*
* @param string $output
* The content to download.
*/
function islandora_marcxml_xml_download($output) {
drupal_add_http_header('Content-type', 'text/xml;charset=utf8');
drupal_add_http_header('Content-length', strlen($output));
drupal_add_http_header('Content-Disposition', 'attachment; filename="marc.xml"');
print $output;
drupal_page_footer();
}
/**
* Access callback.
*
* Requires that the given object contains a MODS datastream (and to be
* viewable, as per the stock permissions).
*
* @param AbstractObject $object
* The object to test, if NULL the given object doesn't exist or is
* inaccessible.
*
* @return bool
* TRUE if the user is allowed to access the marcxml interface, FALSE
* otherwise.
*/
function islandora_marcxml_access_callback($object) {
return is_object($object) && isset($object['MODS']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object['MODS']) && user_access(ISLANDORA_MARCXML_VIEW_PERMISSION);
}
/**
* Callback for re-transforming a MARCXML file and storing in MODS.
*
* @param AbstractObject $object
* An object attempting to have its MODS updated.
*
* @return bool
* TRUE if the user has access to the object and the ability to update, FALSE
* otherwise.
*/
function islandora_marcxml_update_access_callback(AbstractObject $object) {
return variable_get('islandora_marcxml_allow_editing_of_existing_mods', FALSE) && islandora_object_access(ISLANDORA_METADATA_EDIT, $object);
}
/**
* Implements hook_islandora_ingest_steps_alter().
*/
function islandora_marcxml_islandora_ingest_steps_alter(array &$steps, array &$form_state) {
$add_marcxml = variable_get('islandora_marcxml_ingest_step', TRUE);
if ($add_marcxml == TRUE) {
if (isset($steps['xml_form_builder_metadata_step'])) {
$association = isset($steps['xml_form_builder_metadata_step']['args'][0]) ? $steps['xml_form_builder_metadata_step']['args'][0] : NULL;
if (isset($association['dsid']) && $association['dsid'] == 'MODS') {
$steps['islandora_marcxml_upload'] = array(
'type' => 'form',
'weight' => 1,
'form_id' => 'islandora_marcxml_file_form',
'args' => array(),
'file' => 'includes/file.form.inc',
'module' => 'islandora_marcxml',
);
}
}
}
}
/**
* Implements hook_islandora_edit_datastream_registry().
*/
function islandora_marcxml_islandora_edit_datastream_registry(AbstractObject $object, AbstractDatastream $datastream) {
if (variable_get('islandora_marcxml_allow_editing_of_existing_mods', FALSE) && $datastream->id == 'MODS') {
return array(
'islandora_marcxml_update_mods_from_marcxml' => array(
'name' => t('Update MODS from a user provided MARCXML'),
'url' => "islandora/object/{$object->id}/update_mods_from_marcxml",
),
);
}
}