-
Notifications
You must be signed in to change notification settings - Fork 5
/
islandora_scg.module
executable file
·131 lines (116 loc) · 4.22 KB
/
islandora_scg.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
<?php
/**
* @file
* Placeholder module file for Islandora Sample Content Generator.
*/
/**
* Implements hook_menu().
*/
function islandora_scg_menu() {
$items = array();
$items['admin/islandora/tools/islandora_scg'] = array(
'title' => 'Islandora Sample Content Generator',
'description' => 'Load sample objects into your repository.',
'access arguments' => array('generate sample Islandora content'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scg_generate_form'),
'file' => 'includes/generate.form.inc',
);
$items['islandora_scg_load_progress'] = array(
'title' => 'Progress bar progress',
'page callback' => 'islandora_scg_progress_bar',
'type' => MENU_CALLBACK,
'access arguments' => array('generate sample Islandora content'),
'file' => 'includes/generate.form.inc',
);
return $items;
}
/**
* Implements hook_theme().
*/
function islandora_scg_theme() {
return array(
'islandora_scg_metadata_ds' => array(
'variables' => array(
'metadata' => NULL,
),
'template' => 'theme/islandora_scg_metadata_ds',
),
);
}
/**
* Implements hook_permission().
*/
function islandora_scg_permission() {
return array(
'generate sample Islandora content' => array(
'title' => t('Generate sample Islandora content'),
'description' => t('Generate sample objects using the Islandora Sample Content Generator'),
),
);
}
/**
* Implements hook_preprocess_theme().
*/
function islandora_scg_preprocess_islandora_scg_metadata_ds(array &$variables) {
// Read the sample metadata file.
$sample_metadata = &drupal_static(__FUNCTION__);
if (!isset($sample_metadata)) {
$path = $variables['metadata_file'];
$sample_metadata = file($path);
}
// Grab a random row from the sample metadata file.
$random_line_number = array_rand($sample_metadata);
$metadata = explode("\t", $sample_metadata[$random_line_number]);
// Populate the singleton and repeatable variables.
$variables['title'] = htmlspecialchars($metadata[0]);
$variables['date_issued'] = htmlspecialchars($metadata[1]);
$place_names = explode(';', $metadata[2]);
$variables['geographics'] = array();
foreach ($place_names as &$place_name) {
$place_name = trim($place_name);
$place_name = htmlspecialchars($place_name);
$variables['geographics'][] = $place_name;
}
$topics = explode(';', $metadata[3]);
$variables['topics'] = array();
foreach ($topics as &$topic) {
$topic = trim($topic);
$topic = htmlspecialchars($topic);
$variables['topics'][] = $topic;
}
$variables['abstract'] = htmlspecialchars(trim($metadata[4]));
unset($variables['metadata_file']);
}
/**
* Form submit handler.
*/
function islandora_scg_generate_form_submit($form, &$form_state) {
$_SESSION['islandora_scg_num_objects_generated'] = 0;
$_SESSION['islandora_scg_num_objects_to_generate'] = $form_state['values']['islandora_scg_quantity'];
module_load_include('inc', 'islandora_scg', 'includes/utilities');
$cmodel = $form_state['values']['islandora_scg_cmodel'];
$registry = islandora_scg_get_cmodel_associations();
$path_to_metadata_file = drupal_get_path('module', 'islandora_scg') .
DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'sample_metadata.tsv';
$path_to_data_dir = file_directory_temp() . DIRECTORY_SEPARATOR . 'islandora_scg';
$options = array(
'quantity' => $form_state['values']['islandora_scg_quantity'],
'content_model' => $form_state['values']['islandora_scg_cmodel'],
'parent' => $form_state['values']['islandora_scg_collection'],
'namespace' => $form_state['values']['islandora_scg_namespace'],
'bgcolor' => $form_state['values']['islandora_scg_color'],
'metadata_file' => $path_to_metadata_file,
'timer' => FALSE,
'load_content' => TRUE,
'data_dir' => $path_to_data_dir,
);
$generator = new $registry[$cmodel]['class']($options);
$generator->createDataDir();
$generator->generateContent();
$generator->loadContent();
$generator->removeDataDir();
// Sadly, this does not appear on the form, it appears when
// you visit the selected collection.
drupal_set_message(t('!num sample objects loaded.', array('!num' => $form_state['values']['islandora_scg_quantity'])));
}