-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_3dmodel.module
154 lines (140 loc) · 5.09 KB
/
islandora_3dmodel.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
<?php
/**
* @file
* Handles the creation and display of 3D objects.
*/
/**
* Implements hook_menu().
*/
function islandora_3dmodel_menu() {
$items = array();
$items['islandora/object/%islandora_object/modelfile/%'] = array (
'page callback' => 'islandora_3dmodel_modelfile_router',
'page arguments' => array(2,4),
'access callback' => TRUE,
);
$items['islandora/previews/3dmodel/upload'] = array(
'title' => '3D Model Object Preview Upload',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_3dmodel_preview_upload_form'),
'access arguments' => array('access content'),
'file' => 'includes/preview.inc',
);
$items['islandora/previews/3dmodel/view'] = array(
'title' => '3D Model Object Preview',
'page callback' => 'islandora_3dmodel_preview_display',
'access arguments' => array('access content'),
'file' => 'includes/preview.inc',
);
return $items;
}
/**
* Implements hook_islandora_view_object().
*/
function islandora_3dmodel_islandora_3dModelCModel_islandora_view_object($object) {
$output = theme('islandora_3dmodel', array('islandora_object' => $object));
return array('' => $output);
}
/**
* Implements hook_theme().
*/
function islandora_3dmodel_theme($existing, $type, $theme, $path) {
return array(
'islandora_3dmodel' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-3dmodel',
'pattern' => 'islandora_3dmodel__',
'variables' => array('islandora_object' => NULL),
),
);
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_3dmodel_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora_3dmodel');
$islandora_path = drupal_get_path('module', 'islandora');
// 3D Model Content Model.
$object_content_model = $connection->repository->constructObject('islandora:3dModelCModel');
$object_content_model->owner = 'fedoraAdmin';
$object_content_model->label = 'Islandora 3D Model Content Model';
$object_content_model->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream.
$datastream = $object_content_model->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_3dmodel_ds_composite_model.xml", FALSE);
$object_content_model->ingestDatastream($datastream);
// 3D Model Collection.
$object_collection = $connection->repository->constructObject('islandora:3dModel_collection');
$object_collection->owner = 'fedoraAdmin';
$object_collection->label = '3D Model Collection';
$object_collection->models = 'islandora:collectionCModel';
$object_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection policy datastream.
$policy_ds = $object_collection->constructDatastream('COLLECTION_POLICY', 'X');
$policy_ds->label = 'Collection policy';
$policy_ds->mimetype = 'application/xml';
$policy_ds->setContentFromFile("$module_path/xml/islandora_3dmodel_collection_policy.xml", FALSE);
$object_collection->ingestDatastream($policy_ds);
// TN Datastream.
$datastream = $object_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$islandora_path/images/folder.png", FALSE);
$object_collection->ingestDatastream($datastream);
return array(
'islandora_3dmodel' => array(
'title' => 'Islandora 3D Model',
'objects' => array(
$object_content_model,
$object_collection,
),
),
);
}
/**
* Implements hook_islandora_importer().
*/
function islandora_3dmodel_islandora_importer() {
$path_parts = explode('/', current_path());
if (count($path_parts) >= 3) {
$collection = islandora_object_load($path_parts[2]);
if ($collection && in_array('islandora:collectionCModel', $collection->models)) {
$policy = new CollectionPolicy($collection['COLLECTION_POLICY']->content);
if (in_array('islandora:3dModelCModel', array_keys($policy->getContentModels()))) {
return array(
'3dmodel_importer' => array(
'title' => t('3D Model Zip Importer'),
'class' => '_3dModelZipBatchImporter',
),
);
}
}
}
}
/**
* Implements hook_islandora_CMODEL_PID_derivative().
*/
function islandora_3dmodel_islandora_3dModelCModel_islandora_derivative() {
return array(
array(
'source_dsid' => 'MODS',
'destination_dsid' => 'TN',
'weight' => '0',
'function' => array(
'islandora_3dmodel_create_thumbnail',
),
'file' => drupal_get_path('module', 'islandora_3dmodel') . '/includes/derivatives.inc',
),
);
}
function islandora_3dmodel_modelfile_router($pid, $filename) {
$object = islandora_object_load($pid);
$dsmap = json_decode($object['DSMAP']->content, TRUE);
if (array_key_exists($filename, $dsmap)) {
$dsid = $dsmap[$filename];
}
$path = '/islandora/object/' . $pid . "/datastream/" . $dsid . "/view";
drupal_goto($path);
}