-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpld_downloads.module
123 lines (100 loc) · 3.74 KB
/
pld_downloads.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
<?php
function pld_downloads_block_info() {
$blocks['pld_downloads'] = array(
'info' => t('Prov Lib Digital Object Downloads')
);
return $blocks;
}
function pld_downloads_block_view($delta = '') {
switch($delta) {
case 'pld_downloads':
if(user_access('access content')) {
$block['subject'] = NULL;
$block['content'] = pld_downloads_available_downloads();
return $block;
}
}
}
function pld_downloads_available_downloads() {
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
$items = array();
$pid = arg(2);
$base_url = '/islandora/object/';
if($pid != 'islandora:root') {
$object = islandora_object_load($pid);
$obj_models = $object->relationships->get('info:fedora/fedora-system:def/model#', 'hasModel');
$content_model = $obj_models[0]['object']['value'];
switch($content_model) {
case 'islandora:collectionCModel':
return;
break;
case 'islandora:sp_basic_image':
$parents = $object->getParents();
if(!empty($parents)):
// get parent if parents array is not empty
$parent_object = islandora_object_load($parents[0]);
$parent_label = $parent_object->label;
// get datastreams
endif;
if(empty($parents)):
$relationships = $object->relationships->get('info:fedora/fedora-system:def/relations-external#', 'isConstituentOf');
$parent = $relationships[0]['object']['value'];
$parent_object = islandora_object_load($parent);
$collection = $parent_object->getParents();
$collection_object = islandora_object_load($collection[0]);
$collection_label = $collection_object->label;
$collection_pid = $collection_object->id;
$finding_aid = $collection_object['FINDING_AID'];
if($finding_aid != NULL) {
$finding_aid_url = $base_url . $collection_pid . '/datastream/FINDING_AID/view';
$items['collection_finding_aid'] = $finding_aid_url;
} else {
$items['collection_finding_aid'] = NULL;
}
$items['in_collection'] = $collection_label;
$items['collection_pid'] = $collection_pid;
$items['MODS_URL'] = $base_url . $pid .'/datastream/MODS/view';
$items['DC_URL'] = $base_url . $pid .'/datastream/DC/view';
$items['marc_xml'] = $base_url . $pid .'/download_mods_as_marcxml';
$items['OBJ_URL'] = $base_url . $pid . '/datastream/OBJ/view';
endif;
break;
case 'islandora:compoundCModel':
$parents = $object->getParents();
$parent_object = islandora_object_load($parents[0]);
$parent_label = $parent_object->label;
$parent_pid = $parent_object->id;
$items['in_collection'] = $parent_label;
$items['collection_pid'] = $parent_pid;
if($finding_aid != NULL) {
$finding_aid_url = $base_url . $parent_pid . '/datastream/FINDING_AID/view';
$items['collection_finding_aid'] = $finding_aid_url;
} else {
$items['collection_finding_aid'] = NULL;
}
$parts = islandora_compound_object_get_parts($pid);
$first_child = $parts[0];
$items['MODS_URL'] = $base . $pid . '/datastream/MODS/view';
$items['DC_URL'] = $base . $pid . '/datastream/DC/view';
$items['marc_xml'] = $base . $pid . '/download_mods_as_marcxml';
$items['OBJ_URL'] = $base . $first_child . '/datastream/OBJ/view';
break;
}
}
if(!empty($items)):
return theme('pld_downloadsds_available_downloads', array('items' => $items));
endif;
}
function pld_downloads_theme() {
$base = array(
'path' => drupal_get_path('module', 'pld_downloads') . '/theme',
);
return array(
'pld_downloads_available_downloads' => $base + array(
'template' => 'pld-downloads',
'variables' => array( 'items' => NULL,),
),
);
}
?>