-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscholar.install
281 lines (261 loc) · 11.4 KB
/
scholar.install
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
<?php
/**
* @file
*/
define('ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME', 'Islandora Scholar Journal Form');
define('ISLANDORA_SCHOLAR_THESIS_FORM_NAME', 'Islandora Scholar Thesis Form');
define('ISLANDORA_SCHOLAR_BOOK_FORM_NAME', 'Islandora Scholar Book Form');
define('ISLANDORA_SCHOLAR_CHAPTER_FORM_NAME', 'Islandora Scholar Book Chapter Form');
define('ISLANDORA_SCHOLAR_CONFERENCE_FORM_NAME', 'Islandora Scholar Conference Paper Form');
define('ISLANDORA_SCHOLAR_MADS_FORM_NAME', 'Islandora Scholar MADS Form');
define('ISLANDORA_SCHOLAR_MADS_DEPT_FORM_NAME', 'Islandora Scholar MADS Dept Form');
define('ISLANDORA_SCHOLAR_SIGNATURE_PROJECT_FORM', 'Islandora Scholar Signature Project Form');
/**
* Implementation of hook_install
* @global type $base_url
*/
function scholar_install() {
$module_path = drupal_get_path('module', 'scholar');
// Put the form in the database
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/journal_article_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_THESIS_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/thesis_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_THESIS_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_BOOK_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/book_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_BOOK_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_CHAPTER_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/book_chapter_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_CHAPTER_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_CONFERENCE_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/conference_paper_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_CONFERENCE_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_MADS_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/mads_scholar.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_MADS_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_MADS_DEPT_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/MADS_dept_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_MADS_DEPT_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_SIGNATURE_PROJECT_FORM)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/signature_project_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_SIGNATURE_PROJECT_FORM, $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:citationCModel', 'Islandora Scholar Journal Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:citationCModel';
$object->form_name = 'Islandora Scholar Journal Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:thesisCModel', 'Islandora Scholar Thesis Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:thesisCModel';
$object->form_name = 'Islandora Scholar Thesis Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:thesisCModel', 'Islandora Scholar Signature Project Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:thesisCModel';
$object->form_name = 'Islandora Scholar Signature Project Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:citationCModel', 'Islandora Scholar Book Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:citationCModel';
$object->form_name = 'Islandora Scholar Book Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:citationCModel', 'Islandora Scholar Book Chapter Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:citationCModel';
$object->form_name = 'Islandora Scholar Book Chapter Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:citationCModel', 'Islandora Scholar Book Conference Paper Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:citationCModel';
$object->form_name = 'Islandora Scholar Book Conference Paper Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:researcherCModel', 'Islandora Scholar MADS Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:researcherCModel';
$object->form_name = 'Islandora Scholar MADS Form';
$object->dsid = 'MADS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mads_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:departmentCModel', 'Islandora Scholar MADS Dept Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:departmentCModel';
$object->form_name = 'Islandora Scholar MADS Dept Form';
$object->dsid = 'MADS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'dept_mads_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
if (drupal_install_schema('scholar')) {
drupal_set_message(t('Database tables created!'));
}
}
function scholar_schema() {
$result = @db_result(db_query("SELECT pid FROM {islandora_scholar_citation_counts}"));
if (!$result) {
$schema['islandora_scholar_dept_citation_counts'] = array(
'description' => t('This table is used to store the citation counts for fedora objects'),
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'pid' => array(
'description' => t('PID of the object'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'full_name' => array(
'description' => t('Full name'),
'type' => 'varchar',
'length' => 128,
),
'citation_count' => array(
'description' => t('Number of citations'),
'type' => 'int',
'length' => 64,
'not null' => TRUE,
),
),
'primary key' => array('id'),
'indexes' => array(
'pid' => array('pid'),
),
);
}
$schema['islandora_scholar_researcher_citation_counts'] = array(
'description' => t('This table is used to store the citation counts for fedora objects'),
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'pid' => array(
'description' => t('PID of the object'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
),
'full_name' => array(
'description' => t('Full name'),
'type' => 'varchar',
'length' => 128,
),
'department' => array(
'description' => t('Department'),
'type' => 'varchar',
'length' => 64,
),
'citation_count' => array(
'description' => t('Number of citations'),
'type' => 'int',
'length' => 64,
'not null' => TRUE,
),
),
'primary key' => array('id'),
'indexes' => array(
'pid' => array('pid'),
'department' => array('department'),
),
);
return $schema;
}
/**
* Creates a new fedora object.
*
* @param string $pid
* The Fedora Object's PID
* @param string $label
* The Fedora Objects label.
* @param array $relationships
* @param array $datastreams
*/
function scholar_create_fedora_object($pid, $label, array $relationships = array(), array $datastreams = array()) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!Fedora_Item::fedora_item_exists($pid)) {
$foxml = Fedora_Item::create_object_FOXML($pid, 'A', $label);
$object = Fedora_Item::ingest_from_FOXML($foxml);
if ($object->exists()) {
foreach ($relationships as $type => $values) {
$values = is_array($values) ? $values : array($values);
foreach ($values as $value) {
$object->add_relationship($type, $value);
}
}
foreach ($datastreams as $datastream) {
list($url, $dsid, $label, $mime, $control) = $datastream;
$object->add_datastream_from_url($url, $dsid, $label, $mime, $control);
}
return;
}
else {
drupal_set_message('MORE TIME NEEDED.');
}
drupal_set_message(t('There was an error creating %pid (%label). See watchdog for details.', array('%pid' => $pid, '%label' => $label)), 'Error');
}
}
/**
* Adds the required namespaces for the scholar module.
*/
function scholar_add_required_namespaces() {
$namespaces = variable_get('fedora_pids_allowed', 'demo: changeme: islandora:');
if (preg_match('/ir\:/', $namespaces) == 0) {
variable_set('fedora_pids_allowed', $namespaces . ' ir:');
drupal_set_message('Added \'ir:\' to the set of allowed namespaces.', 'info');
}
}