-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemic_cwrc.module
323 lines (293 loc) · 9.57 KB
/
emic_cwrc.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
<?php
function emic_cwrc_form_islandora_book_admin_settings_alter(&$form, &$form_state) {
module_load_include('module', 'taxonomy', 'module');
$taxonomies = taxonomy_get_vocabularies();
$taxes = array('none' => t('None'));
if (!empty($taxonomies)) {
foreach ($taxonomies as $tax) {
$taxes[$tax->vid] = $tax->name;
}
}
$current_tax = variable_get('EMIC_TAX', '');
$form['emic_taxonomy_vid'] = array(
'#title' => t("Taxonomy for Category Type"),
'#type' => 'select',
'#options' => $taxes,
'#default_value' => $current_tax,
'#weight' => 0
);
$form['emic_enforce_taxonomy'] = array(
'#type' => 'radios',
'#title' => t('Annotation Categories'),
'#options' => array(0 => t('User defined'), 1 => t("Administrator defined")),
'#description' => t('Allows administrators to select predefined taxonomies to determine annotation categorization terminology'),
'#default_value' => variable_get('emic_annotation_categories', 0),
'#weight' => -1,
);
}
function emic_cwrc_menu() {
$items = array();
$items['cwrc/page'] = array(
'file' => 'emic_cwrc.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('cwrc_page_select_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['cwrc/save'] = array(
'file' => 'emic_cwrc.inc',
'page callback' => 'save_cwrc_data',
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['cwrc/getCWRC'] = array(
'file' => 'emic_cwrc.inc',
'page callback' => 'get_cwrc_data',
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['cwrc/setupCWRC'] = array(
'file' => 'emic_cwrc.inc',
'page callback' => 'setupCWRC',
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['cwrc/authorities'] = array(
'file' => 'emic_cwrc.inc',
'page callback' => 'emic_cwrc_get_authorities',
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['cwrc/editor'] = array(
'file' => 'emic_cwrc.module',
'page callback' => 'editor_as_link',
'type' => MENU_CALLBACK,
'access arguments' => array('use CWRC'),
);
$items['emic/cwrc/create'] = array(
'file' => 'emic_cwrc_edition.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('emic_cwrc_create_edition'),
'type' => MENU_CALLBACK,
'access arguments' => array('create critical edition'),
);
$items['emic/cwrc/editions'] = array(
'file' => 'emic_cwrc_edition.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('emic_cwrc_manage_editions'),
'type' => MENU_CALLBACK,
'access arguments' => array('manage critical editions'),
);
return $items;
}
function emic_cwrc_perm() {
return array(
'use CWRC',
'edit CWRC',
'create critical edition',
'manage critical editions'
);
}
/**
* Implementation of hook_theme
*/
function emic_cwrc_theme($existing, $type, $theme, $path) {
$path = drupal_get_path('module', 'emic_cwrc') . '/theme';
$file = 'emic_cwrc.theme.inc';
return array(
'emic_cwrc' => array(
'arguments' => array('src' => NULL),
'path' => $path,
'file' => $file,
'template' => 'emic-cwrc',
),
'emic_editions_table' => array(
'arguments' => array('element' => NULL),
'file' => 'emic_cwrc_edition.inc',
)
);
}
function emic_cwrc_islandora_book_links($pid) {
if (!user_access('use CWRC')) {
return;
}
global $base_url;
$path = drupal_get_path('module', 'emic_cwrc');
module_load_include('inc', 'islandora_book', 'book_pack_utils');
$pages = get_page_pids($pid);
$first_page = $pages[0];
$cwrc_host = "$base_url/$path/resources/index.php";
$options = array(
'attributes' => array('target' => '_blank'),
'query' => array(
'PID' => $first_page,
),
);
$link = l('Edit with CWRCWriter', "$cwrc_host", $options);
return $link;
}
function editor_as_link($pid, $book_pid = null) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if ($book_pid) {
$item = new Fedora_Item($book_pid);
$rels = $item->get_rdf_relationships();
if ($rels['isCriticalEditionOf']) {
$book_pid = $rels['isCriticalEditionOf'][0];
}
}
global $base_url;
$path = drupal_get_path('module', 'emic_cwrc');
$src = "$base_url/$path/resources/index.php?PID=" . $pid;
$variables = array('src' => $src, 'pid' => $pid, 'book_pid' => $book_pid);
return theme('emic_cwrc', $variables);
}
function emic_cwrc_islandora_book_get_pageview_links($pid) {
$text = t("Critical Edition");
if (user_access('use CWRC')) {
$text = t("Editor");
}
$path = drupal_get_path('module', 'emic_cwrc');
$link = l($text, "cwrc/editor/$pid");
return $link;
}
/**
* Responds to hook_islandora_get_bookview_links
* Returns an array of links to be added to the 'About' tab
* associated with book objects in the Islandora Book Solution Pack
*
* @param PID> $pid
* @return array
*/
function emic_cwrc_links($pid) {
module_load_include('inc', 'islandora_book', 'book_pack_utils');
module_load_include('inc', 'emic_cwrc', 'emic_cwrc_utils');
$editions = emic_cwrc_get_critical_editions($pid);
//get pid of
$pages = get_page_pids($pid);
$first_page = $pages[1];
if (!$first_page) {
return;
}
$links = array();
if (user_access('create critical edition')) {
$links[] = l('Create new Critical Edition', "emic/cwrc/create/$pid");
}
module_load_include('inc', 'emic_cwrc', 'emic_cwrc_utils');
// returns associative array of critical editons in PID=> LABEL format
$editions = emic_cwrc_get_critical_editions($pid);
if (!empty($editions)) {
if (user_access('manage critical editions')) {
$links[] = l('Manage Critical Editions', "emic/cwrc/editions/$pid");
}
foreach ($editions as $key => $value) {
$pages = get_page_pids($key);
$first_page = $pages[1];
$links[] = l($value, "cwrc/editor/$first_page/$key");
}
}
return $links;
}
function emic_cwrc_islandora_tabs($content_models, $pid) {
module_load_include('inc', 'islandora_book', 'page_object_manager');
module_load_include('inc', 'islandora_book', 'book_object_manager');
module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent');
$tabset = array();
$content_model = $content_models[0]->pid;
if ($content_model == 'islandora:bookCModel' || $content_model == 'islandora:iaBookCModel') {
$return_tabs = get_emic_management_content($pid);
$return_tabs['fedora_object_details'] = null;
return $return_tabs;
}
}
function get_emic_management_content($pid) {
$links = emic_cwrc_links($pid);
if (!isset($links)) {
return;
}
$list = theme_item_list($links);
$form['manage_page_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Critical Editions'),
'#content' => $list,
'#selected' => FALSE,
);
return $form;
}
function emic_cwrc_fedora_repository_required_fedora_objects() {
module_load_include('inc', 'fedora_repository', 'fedora_repository.solutionpacks');
$module_path = drupal_get_path('module', 'emic_cwrc');
$islandora_path = drupal_get_path('module', 'fedora_repository');
return array(
'emic_cwrc' => array(
'module' => 'emic_cwrc',
'title' => 'Cwrc Module',
'objects' => array(
array(
'pid' => 'islandora:authorities',
'label' => 'Authority Collections',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:root',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
array(
'pid' => 'islandora:personsAuthority',
'label' => 'Persons Authorities',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:authorities',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
array(
'pid' => 'islandora:eventsAuthority',
'label' => 'Events Authorities',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:authorities',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
array(
'pid' => 'islandora:orgsAuthority',
'label' => 'Organizations Authorities',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:authorities',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
array(
'pid' => 'islandora:placesAuthority',
'label' => 'Places Authorities',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:authorities',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
),
),
);
}