-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.php
105 lines (83 loc) · 3 KB
/
plugin.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
<?php
define('MODS_PLUGIN_VERSION', get_plugin_ini('MODS', 'version'));
add_plugin_hook('install', 'MODSPlugin::install');
add_plugin_hook('uninstall', 'MODSPlugin::uninstall');
class MODSPlugin
{
private $_db;
private $_elements;
public function __construct()
{
$this->_db = get_db();
$this->_setElements();
}
public static function install()
{
set_option('mods_plugin_version',
MODS_PLUGIN_VERSION);
$elementSetMetadata = array( 'name' => 'MODS',
'description' => 'MODS support according to Columbia University Libraries MODS profile');
$mods = new MODSPlugin;
insert_element_set($elementSetMetadata, $mods->getElements());
}
public static function uninstall()
{
delete_option('mods_plugin_version');
$mods = new MODSPlugin;
$mods->_deleteElementSet();
}
public function getElements()
{
return $this->_elements;
}
private function _setElements()
{
include 'elements.php';
$this->_elements = $elements;
}
// ---------------------------------------------------------------- //
private function _addElements()
{
// Add the new elements to the Dublin Core element set.
$elementSet = $this->_getElementSet();
// Iterate through the elements.
foreach ($this->_elements as $key => $element) {
$e = new Element;
$e->record_type_id = $this->_getRecordTypeId('Item');
$e->data_type_id = $this->_getDataTypeId($element['data_type']);
$e->element_set_id = $elementSet->id;
$e->name = $element['name'];
$e->description = $element['description'];
$e->order = $key + 1;
$e->save();
}
}
private function _deleteElementSet()
{
$mods_element_set = $this->_db->getTable('ElementSet')->findByName('MODS');
if (isset($mods_element_set)) {
$sql = "DELETE FROM `{$this->_db->prefix}elements` WHERE ELEMENT_SET_ID = ( ? )";
$this->_db->query($sql, $mods_element_set->id);
$sql = "DELETE FROM `{$this->_db->prefix}element_sets` WHERE ID = ( ? )";
$this->_db->query($sql, $mods_element_set->id);
}
}
private function _getElementSet()
{
return $this->_db->getTable('ElementSet')->findByName('MODS');
}
private function _getElement($elementName)
{
return $this->_db
->getTable('Element')
->findByElementSetNameAndElementName('MODS', $elementName);
}
private function _getRecordTypeId($recordTypeName)
{
return $this->_db->getTable('RecordType')->findIdFromName($recordTypeName);
}
private function _getDataTypeId($dataTypeName)
{
return $this->_db->getTable('DataType')->findIdFromName($dataTypeName);
}
}