/
SchemaPlugin.inc.php
274 lines (236 loc) · 6.4 KB
/
SchemaPlugin.inc.php
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
<?php
/**
* @file classes/plugins/SchemaPlugin.inc.php
*
* Copyright (c) 2005-2012 Alec Smecher and John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @package plugins
* @class SchemaPlugin
*
* @brief Abstract class for schema plugins
*/
// $Id$
import('classes.plugins.Plugin');
class SchemaPlugin extends Plugin {
function SchemaPlugin() {
parent::Plugin();
}
/**
* Register this plugin for all the appropriate hooks.
*/
function register($category, $path) {
$success = parent::register($category, $path);
if ($success) {
HookRegistry::register('OAI::metadataFormats', array(&$this, 'callback_formatRequest'));
}
return $success;
}
/**
* Get the display name of this plugin's protocol.
* @return String
*/
function getSchemaDisplayName() {
fatalError('ABSTRACT CLASS');
}
/**
* Get the symbolic name of this plugin. Should be unique within
* the category.
*/
function getName() {
fatalError('ABSTRACT CLASS');
}
/**
* Get a description of the plugin.
*/
function getDescription() {
fatalError('ABSTRACT CLASS');
}
/**
* Get a name for a field.
* @param $fieldSymbolic string Symbolic name for the field
* @param $locale string Name of locale (optional)
* @return string
*/
function getFieldName($fieldSymbolic, $locale = null) {
return null;
}
/**
* Get the ID for a field, building it if necessary.
*/
function getFieldId($fieldName) {
$fieldDao =& DAORegistry::getDAO('FieldDAO');
$field =& $fieldDao->buildField($fieldName, $this->getName());
return $field->getFieldId();
}
/**
* Get a description for a field.
* @param $fieldSymbolic string Symbolic name for the field
* @param $locale string Name of locale (optional)
* @return string
*/
function getFieldDescription($fieldSymbolic, $locale = null) {
return null;
}
/**
* Get a list of symbolic names for fields in this schema.
* @return array
*/
function getFieldList() {
fatalError('ABSTRACT CLASS!');
}
/**
* Get the value of a field by symbolic name for sort indexing.
* @var $record object
* @var $name string
* @return mixed null on failure
*/
function getFieldValue(&$record, $name, $type) {
fatalError('ABSTRACT CLASS!');
}
/**
* Get the schema object associated with this plugin
*/
function &getSchema() {
$schemaDao =& DAORegistry::getDAO('SchemaDAO');
$schema =& $schemaDao->buildSchema($this->getName());
return $schema;
}
/**
* Parse a record's contents into an object
* @param $contents string
* @return object
*/
function &parseContents(&$contents) {
fatalError('ABSTRACT CLASS!');
}
/**
* Display a record summary.
*/
function displayRecordSummary(&$record) {
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign_by_ref('record', $record);
$templateMgr->display($this->getTemplatePath() . 'summary.tpl', null, 'SchemaPlugin::displayRecordSummary');
}
function getRtVersion(&$archive) {
// Get the Reading Tools, if any.
$rtDao =& DAORegistry::getDAO('RTDAO');
$versionId = $archive->getSetting('rtVersionId');
$version =& $rtDao->getVersion($versionId, $archive->getArchiveId());
$defineTermsContextId = null;
if ($version === null) { // Fall back on the site default
$site =& Request::getSite();
$versionId = $site->getSetting('rtVersionId');
$version =& $rtDao->getVersion($versionId, 0);
}
if ($version) {
// Determine the "Define Terms" context ID.
foreach ($version->getContexts() as $context) {
if ($context->getDefineTerms()) {
$defineTermsContextId = $context->getContextId();
break;
}
}
}
return array(&$version, $defineTermsContextId);
}
/**
* Display a record.
*/
function displayRecord(&$record) {
$templateMgr =& TemplateManager::getManager();
$archive =& $record->getArchive();
$templateMgr->assign_by_ref('archive', $archive);
$templateMgr->assign_by_ref('record', $record);
list($version, $defineTermsContextId) = $this->getRtVersion($archive);
if ($version) {
$templateMgr->assign_by_ref('version', $version);
$templateMgr->assign('defineTermsContextId', $defineTermsContextId);
}
$templateMgr->display($this->getTemplatePath() . 'record.tpl', null, 'SchemaPlugin::displayRecord');
}
/**
* Get a URL for the supplied record, if available; null otherwise.
* @param $record object
* @return string
*/
function getUrl(&$record) {
return null;
}
/**
* Get the title for the supplied record, if available; null otherwise.
* @param $record object
* @return string
*/
function getTitle(&$record) {
return null;
}
/**
* Get the authors for the supplied record, if available
* @param $record object
* @return array
*/
function getAuthors(&$record) {
return array();
}
/**
* Get the author string for the supplied record, if available; null otherwise.
* @param $record object
* @return string
*/
function getAuthorString(&$record) {
return (join('; ', $this->getAuthors($record)));
}
/**
* Get the field type for the specified field.
* Child classes should probably override this.
*/
function getFieldType($fieldId) {
// The default type for all fields is string.
return FIELD_TYPE_STRING;
}
/**
* Parse a date into a value suitable for indexing.
* @return int timestamp or string date, or null on failure
*/
function parseDate($fieldName, $value, $attributes = null) {
if (empty($value)) return null;
$date = strtotime($value);
if ($date === false || $date === -1) return null;
return date('Y-m-d H:i:s', $date);
}
/**
* Get the metadata prefix for this plugin's format.
*/
function getMetadataPrefix() {
return 'Base OAIMetadata plugin class: abstract function getMetadataPrefix()';
}
function getSchemaName() {
return '';
}
function getNamespace() {
return '';
}
/**
* Get a hold of the class that does the formatting.
*/
function getFormatClass() {
return 'Base OAIMetadata plugin class: abstract function getFormatClass()';
}
function callback_formatRequest($hookName, $args) {
$namesOnly = $args[0];
$identifier = $args[1];
$formats =& $args[2];
if ($namesOnly) {
$formats = array_merge($formats,array($this->getMetadataPrefix()));
} else {
$formatClass = $this->getFormatClass();
$formats = array_merge(
$formats,
array($this->getMetadataPrefix() => new $formatClass($this->getMetadataPrefix(), $this->getSchemaName(), $this->getNamespace()))
);
}
return false;
}
}
?>