forked from roblib/islandora_solution_pack_chemistry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_chem_sp.module
394 lines (346 loc) · 13.8 KB
/
islandora_chem_sp.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/**
* @file
*
* Provides the functionality to process and view chemical structure files.
*/
define('ISLANDORA_CHEM_SP_MODS_FORM_NAME', 'Islandora Chem MODS Form');
define('ISLANDORA_CHEM_SP_MADS_FORM_NAME', 'Islandora Chem MADS Form');
/**
* Declare the objects that are required by this solution pack
* @return type
*/
function islandora_chem_sp_required_fedora_objects() {
$module_path = drupal_get_path('module', 'islandora_chem_sp');
// Put the form in the database
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
if (!XMLFormDatabase::Exists(ISLANDORA_CHEM_SP_MODS_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/xml/mods_chem.xml');
XMLFormDatabase::Create(ISLANDORA_CHEM_SP_MODS_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_CHEM_SP_MADS_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/xml/mads_chem.xml');
XMLFormDatabase::Create(ISLANDORA_CHEM_SP_MADS_FORM_NAME, $definition);
}
// Associates the form with the content model
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:sp_chem_CM', 'Islandora Chem MODS Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:sp_chem_CM';
$object->form_name = 'Islandora Chem MODS Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result2 = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:sp_chem_researcher_CM', 'Islandora Chem MADS Form'));
if (!$result2) {
$object2 = new stdClass();
$object2->content_model = 'islandora:sp_chem_researcher_CM';
$object2->form_name = 'Islandora Chem MADS Form';
$object2->dsid = 'MADS';
$object2->title_field = "['titleInfo']['title']";
$object2->transform = 'mads_to_dc.xsl';
$result2 = drupal_write_record('islandora_content_model_forms', $object2);
}
return array(
'islandora_chem_sp' => array(
'module' => 'islandora_chem_sp',
'title' => 'Islandora Chem Solution Pack',
'objects' => array(
array(
'pid' => 'islandora:sp_chem_CM',
'label' => 'Islandora chemistry content model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/xml/CHEMCM.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:sp_chem_researcher_CM',
'label' => 'Islandora chemistry researcher content model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/xml/CHEMRSCM.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'quantumchem:sp_collection',
'label' => 'Quantumchem',
'cmodel' => 'islandora:collectionCModel',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_chem.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/COLLECTION-COLLECTION POLICY.xml",
),
),
),
array(
'pid' => 'quantumchem:sp_chem_calculations',
'label' => 'Calculations',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'quantumchem:sp_collection',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_chem.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/CHEM-COLLECTION POLICY.xml",
),
),
),
array(
'pid' => 'quantumchem:sp_chem_researchers',
'label' => 'Researchers',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'quantumchem:sp_collection',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_chem.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/CHEM_RESEARCHER_POLICY.xml",
),
),
),
),
),
);
}
/**
* Create the callbacks for each of the pages
* @return array
*/
function islandora_chem_sp_menu() {
$items = array();
$items['structure_search'] = array(
'title' => t('Structure search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_structure_search_form'),
'type' => MENU_NORMAL_ITEM, //MENU_CALLBACK,
'access arguments' => array('structure search'),
);
$items['inchi_search'] = array(
'title' => t('Structure search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_inchi_search_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('structure search'),
);
$items['fragment_search'] = array(
'title' => t('Fragment search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_fragment_search_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('structure search'),
);
$items['substructure'] = array(
'title' => t('Substructure search intermeditate page'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_substructure_search_intermediate_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('structure search'),
);
$items['substructure_search'] = array(
// 'title' => t('Substructure search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_substructure_search_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('structure search'),
);
$items['mw_search'] = array(
'title' => t('Molecular weight search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_mw_search_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['download'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_download_form'),
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['r_autocomplete'] = array(
'title' => 'Auto Complete List of Researchers.',
'description' => 'Lists Researchers.',
'file' => 'autocomplete.inc',
'page callback' => 'islandora_content_model_forms_autocomplete_researchers',
'access arguments' => array('view fedora collection'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['i_autocomplete'] = array(
'title' => 'Auto Complete List of Institutions.',
'description' => 'Lists Institutions.',
'file' => 'autocomplete.inc',
'page callback' => 'islandora_content_model_forms_autocomplete_institutions',
'access arguments' => array('view fedora collection'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['ingest'] = array(
'title' => t('Ingest'),
'file' => 'islandora_chem_sp_blocks.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_ingest_form'),
'type' => MENU_NORMAL_ITEM, //MENU_CALLBACK,
'access arguments' => array('ingest new fedora objects'),
);
$items['advanced_search'] = array(
'title' => t('Advanced search'),
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_chem_sp_advanced_search_form'),
'type' => MENU_NORMAL_ITEM, //MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['advanced_search/field/add'] = array(
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'islandora_chem_sp_search_advanced_add_field',
'access callback' => 'user_access',
'access arguments' => array('view fedora collection'),
'type' => MENU_CALLBACK,
);
$items['advanced_search/field/remove'] = array(
'file' => 'islandora_chem_sp_search.inc',
'page callback' => 'islandora_chem_sp_search_advanced_remove_field',
'access callback' => 'user_access',
'access arguments' => array('view fedora collection'),
'type' => MENU_CALLBACK,
);
return $items;
}
function islandora_chem_sp_perm() {
return array(
'structure search',
);
}
function islandora_chem_sp_cron() {
module_load_include('inc', 'islandora_chem_sp', 'islandora_chem_sp_cron');
islandora_chem_cron();
}
function islandora_chem_sp_download_form($form_state, $pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'islandora_chem_sp', 'FileConversion');
$object = new Fedora_Item($pid);
$list = $object->get_datastreams_list_as_array();
// $ext = ltrim(strstr($list['OBJ']['MIMEType'], '-'), '-');
$ext = system_mime_type_extension($list['OBJ']['MIMEType']);
$fedora_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
$file = $fedora_url . '/objects/' . $pid . '/datastreams/OBJ/content';
$name = str_replace(':', '-', $pid);
header("Content-type: " . $mime);
header("Content-disposition: attachment; filename=" . $name . '.' . $ext . ";");
readfile($file);
exit;
}
function islandora_chem_sp_block($op = 'list', $delta = 0, $edit = array()) {
module_load_include('inc', 'islandora_chem_sp', 'islandora_chem_sp_search');
module_load_include('inc', 'islandora_chem_sp', 'islandora_chem_sp_blocks');
module_load_include('inc', 'islandora_chem_sp', 'islandora_chem_sp_home');
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Molecular weight search');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks[1]['info'] = t('Ingest block');
$blocks[1]['cache'] = BLOCK_NO_CACHE;
$blocks[2]['info'] = t('My files');
$blocks[2]['cache'] = BLOCK_NO_CACHE;
$blocks[3]['info'] = t('People');
$blocks[3]['cache'] = BLOCK_NO_CACHE;
$blocks[4]['info'] = t('Groups');
$blocks[4]['cache'] = BLOCK_NO_CACHE;
return $blocks;
case 'view':
if ($delta == 0) {
$block['subject'] = t('Molecular weight search');
$block['content'] = drupal_get_form('islandora_chem_sp_mw_search_form');
}
elseif ($delta == 1) {
$block['subject'] = t('Upload structures');
$block['content'] = drupal_get_form('islandora_chem_sp_ingest_form');
}
elseif ($delta == 2) {
$block['subject'] = t('My files');
$block['content'] = drupal_get_form('islandora_chem_sp_object_form');
}
elseif ($delta == 3) {
$block['subject'] = t('People');
$block['content'] = drupal_get_form('islandora_chem_sp_people_form');
}
elseif ($delta == 4) {
$block['subject'] = t('Groups');
$block['content'] = drupal_get_form('islandora_chem_sp_group_form');
}
return $block;
}
}
function islandora_chem_sp_islandora_solr_primary_display() {
return array(
'islandora_chem_sp' => array(
'name' => t('Chemistry'),
'module' => 'islandora_chem_sp',
'file' => 'IslandoraSolrResultsChem.inc',
'class' => "IslandoraSolrResultsChem",
'function' => "displayResultsChem",
'description' => t("Results displayed in a format suited for chemistry."),
)
);
}
/**
* Implementation of hook_form_alter().
*/
function islandora_chem_sp_form_alter(&$form, &$form_state, $form_id) {
switch($form_id) {
case 'user_admin_settings':
if (is_array($form['email']) && $form['email']['#type'] == 'fieldset') {
foreach ($form['email'] AS $key => $value) {
if (is_array($value) && $value['#type'] == 'fieldset') {
$form['email'][$key]['#description'] .= '<br />' . t('Also available variables are: ') . '!profile_first_name, !profile_last_name, !profile_full_name, !profile_title';
}
}
}
break;
}
}
/**
* Implementation of hook_mail_alter().
*/
function islandora_chem_sp_mail_alter(&$message) {
switch ($message['id']) {
case "user_register_admin_created":
case "user_register_no_approval_required":
case "user_register_pending_approval":
case "user_password_reset":
case "user_status_activated":
case "user_status_blocked":
case "user_status_deleted":
case "logintoboggan_register_no_approval_required":
$token_replacements = array(
'!profile_first_name' => $message['params']['account']->profile_firstname,
'!profile_last_name' => $message['params']['account']->profile_lastname,
'!profile_full_name' => $message['params']['account']->profile_firstname . ' ' . $message['params']['account']->profile_lastname,
'!profile_title' => $message['params']['account']->profile_title,
);
// You can also use $message['params']['account']->uid to get more values related to the user like number of new messages (privatemsg) he/she got on the site
$message['subject'] = strtr($message['subject'], $token_replacements);
$message['body'][0] = strtr($message['body'][0], $token_replacements);
break;
}
}