-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_metadata_analyzer.module
executable file
·363 lines (319 loc) · 10.5 KB
/
islandora_metadata_analyzer.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* @file
* Hook implementations.
*/
/**
* Implements hook_init().
* Add ajax and javascript
*/
function islandora_metadata_analyzer_init(){
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system', 'drupal.ajax');
}
/**
* Implements hook_menu().
*/
function islandora_metadata_analyzer_menu() {
$items = array();
$items['metadata_analyzer'] = array(
'title' => 'Islandora Metadata Analyzer',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_metadata_analyzer_form'),
'access arguments' => array('administer site configuration'),
'expanded' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['metadata_analyzer/results'] = array(
'title' => 'Metadata Analysis Results',
'page callback' => 'islandora_metadata_analyzer_results',
'file' => 'includes/analyzerViews.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['metadata_analyzer/resultsdownload'] = array(
'title' => 'Metadata Analysis Results Download',
'page callback' => 'islandora_metadata_analyzer_results_download',
'file' => 'includes/analyzerViews.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['metadata_analyzer/deleteResult'] = array(
'title' => 'Remove Metadata Analysis Results',
'page callback' => 'islandora_metadata_analyzer_delete_result',
'file' => 'includes/analyzer.inc',
'page arguements' => array(1),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
);
/*
$items['metadata_analyzer/searchReplace'] = array(
'title' => 'Islandora Metadata Search Replace',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_metadata_analyzer_search_replace_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
*/
$items['metadata_analyzer/elementCount'] = array(
'title' => 'Collection Element Analysis Results',
'page callback' => 'islandora_metadata_analyzer_element_counts',
'page arguements' => array(1),
'file' => 'includes/analyzerViews.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
);
$items['metadata_analyzer/populateSearchReplace'] = array(
'title' => 'Collection Element Analysis Results',
'page callback' => 'islandora_metadata_analyzer_populate_form',
'page arguements' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/ajax-path'] = array(
'title' => 'Get data element at this path',
'page callback' => 'islandora_metadata_analyzer_path_ajax',
'access callback' => TRUE,
'file' => 'includes/ajax.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/ajax-data'] = array(
'title' => 'Get pids of objects that have this data element',
'page callback' => 'islandora_metadata_analyzer_data_ajax',
'access callback' => TRUE,
'file' => 'includes/ajax.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/downloads'] = array(
'title' => 'Collection Element Analysis Results',
'page callback' => 'islandora_metadata_analyzer_download_pids',
'page arguements' => array(1),
'file' => 'includes/ajax.inc',
'access callback' => TRUE,
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/ajax-allpath'] = array(
'title' => 'Get PIDS that have this path',
'page callback' => 'islandora_metadata_analyzer_allpath_ajax',
'access callback' => TRUE,
'file' => 'includes/ajax.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/piddownloads'] = array(
'title' => 'Collection Element Analysis Results',
'page callback' => 'islandora_metadata_analyzer_download_all_pids',
'page arguements' => array(1),
'file' => 'includes/ajax.inc',
'access callback' => TRUE,
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/ajax-allpathmissing'] = array(
'title' => 'Get list of PIDS that do not have a path',
'page callback' => 'islandora_metadata_analyzer_allpath_missing_ajax',
'access callback' => TRUE,
'file' => 'includes/ajax.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['islandora_metadata_analyzer/missingpiddownloads'] = array(
'title' => 'Download list of PIDS missing a path',
'page callback' => 'islandora_metadata_analyzer_download_all_missing_pids',
'page arguements' => array(1),
'file' => 'includes/ajax.inc',
'access callback' => TRUE,
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/*
* implements hook_theme
*
* Theme functions for output
*
*/
function islandora_metadata_analyzer_theme($existing, $type, $theme, $path) {
return array(
'results_list' => array(
'variables' => array(
'resultArray' => NULL,
),
'template' => 'theme/islandora-metadata-analyzer-result-list', // do not include .tpl.php
'path' => drupal_get_path('module', 'islandora_metadata_analyzer'), '/theme',
),
'element_count' => array(
'variables' => array(
'result_id' => NULL,
'title' => NULL,
'pid' => NULL,
'query_time' => NULL,
'countArray' => NULL,
'stream' => NULL,
'record_count' => NULL,
'path_data' => NULL,
),
'template' => 'theme/islandora-metadata-analyzer-element-count', // do not include .tpl.php
'path' => drupal_get_path('module', 'islandora_metadata_analyzer'), '/theme',
),
);
}
/*
* stub callback to manipulate and set variables for theme
*/
function template_preprocess_results_list(&$vars) {
// This variable will be available in the template file as $custom_value
}
/*
* Implements template_preprocess_hook
*
* Unserialize array for theme
*
*/
function template_preprocess_element_count(&$vars) {
//Add javascript for closing PID views
drupal_add_js(drupal_get_path('module', 'islandora_metadata_analyzer') . '/js/element.js',
array(
'group' => JS_THEME,
'preprocess' => TRUE,
'scope' => 'footer',
'weight' => '9999',
)
);
}
/*
* implements hook_form()
* @params $form form_state
*
* Form for selecting repair parameters
*
*/
function islandora_metadata_analyzer_search_replace_form($form, &$form_state){
$form['metadata_stream'] = array(
'#type' => 'select',
'#title' => t('Metadata Stream'),
'#options' => drupal_map_assoc(array(t('DC'), t('MODS'))),
'#description' => t('Select the metadata stream to analyze.'),
);
$form['path_to_element'] = array(
'#type' => 'textfield',
'#size' => 100,
'#default_value' => '/language/languageTerm@authority=iso639-2b,type=code,',
'#required' => TRUE,
'#title' => t('Path to Element'),
);
$form['old_data'] = array(
'#type' => 'textfield',
'#size' => 60,
'#default_value' => 'eng',
'#required' => TRUE,
'#title' => t('Old Data'),
);
$form['new_data'] = array(
'#type' => 'textfield',
'#size' => 60,
'#default_value' => 'dutch',
'#required' => TRUE,
'#title' => t('New Data'),
);
$form['pid_list'] = array(
'#type' => 'textfield',
'#size' => 100,
'#default_value' => 'islandora:43, islandora:1542',
'#required' => TRUE,
'#title' => t('PIDs to Repair'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
return $form;
}
/*
* implements hook_submit
*
* Collect input and pass to processing functions
*
*/
function islandora_metadata_analyzer_search_replace_form_submit($form, &$form_state){
$params = array('stream' => $form_state['values']['metadata_stream'],
'path' => $form_state['values']['path_to_element'],
'old_data' => $form_state['values']['old_data'],
'new_data' => $form_state['values']['new_data'],
'pid_list' => $form_state['values']['pid_list'],
);
module_load_include('inc', 'islandora_metadata_analyzer', 'includes/search_replace');
islandora_metadata_analyzer_search_replace($params);
return $form;
}
/*
* implements hook_form()
* @params $form form_state
*
* Form for selecting analysis parameters
*
*/
function islandora_metadata_analyzer_form($form, &$form_state){
$form['results_link'] = array(
'#markup' => '<a href="metadata_analyzer/results">View Results</a>',
);
$form['result_set_title'] = array(
'#type' => 'textfield',
'#size' => 30,
'#required' => TRUE,
'#title' => t('Title of result set'),
);
$form['metadata_stream'] = array(
'#type' => 'select',
'#title' => t('Metadata Stream'),
'#options' => drupal_map_assoc(array(t('DC'), t('MODS'))),
'#description' => t('Select the metadata stream to analyze.'),
);
$form['collection_pid'] = array(
'#type' => 'textfield',
'#size' => 30,
'#required' => TRUE,
'#title' => t('PID of collection to analyze'),
);
$form['capture_fields'] = array(
'#type' => 'textarea',
'#cols' => 128,
'#rows' => 5,
'#required' => FALSE,
'#title' => t('Comma separated list of top level elements to capture'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
return $form;
}
/*
* hook_validata stub
*
*/
function islandora_metadata_analyzer_form_validate($form, &$form_state){
}
/*
* implements hook_submit
*
* Collect input and pass to processing functions
*
*/
function islandora_metadata_analyzer_form_submit($form, &$form_state){
$stream = $form_state['values']['metadata_stream'];
$collection_pid = $form_state['values']['collection_pid'];
$result_set_title = $form_state['values']['result_set_title'];
$capture_fields = $form_state['values']['capture_fields'];
$params = array('capture_fields' => $capture_fields,
'result_set_title' => $result_set_title,
'stream' => $stream,
'pid' => $collection_pid);
module_load_include('inc', 'islandora_metadata_analyzer', 'includes/analyzer');
islandora_metadata_analyzer($params);
return $form;
}