-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalElementsPlugin.php
122 lines (100 loc) · 3.11 KB
/
ConditionalElementsPlugin.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
<?php
/**
* ConditionalElements plugin.
*
* @package Omeka\Plugins\ConditionalElements
*/
class ConditionalElementsPlugin extends Omeka_Plugin_AbstractPlugin {
/**
* @var array This plugin's hooks.
*/
protected $_hooks = array(
'initialize',
'install',
'uninstall',
'admin_head', // embed our jQuery code when adding / editing objects
'define_acl',
);
protected $_options = array(
'conditional_elements_dependencies' => "[]",
);
/**
* Install the plugin.
*/
public function hookInstall() {
SELF::_installOptions();
}
/**
* Uninstall the plugin.
*/
public function hookUninstall() {
SELF::_uninstallOptions();
}
/**
* @var array This plugin's filters.
*/
protected $_filters = array('admin_navigation_main');
/**
* Add the translations.
*/
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
/**
* Define the ACL.
*
* @param array $args
*/
function hookDefineAcl($args)
{
// Restrict access to super and admin users.
$args['acl']->addResource('ConditionalElements_Index');
}
function filterAdminNavigationMain($nav)
{
if(is_allowed('ConditionalElements_Index', 'index')) {
$nav[] = array('label' => __('Conditional Elements'), 'uri' => url('conditional-elements'));
}
return $nav;
}
public function hookAdminHead($args) {
// Core hookAdminHead taken from ElementTypes plugin
$request = Zend_Controller_Front::getInstance()->getRequest();
$module = $request->getModuleName();
if (is_null($module)) { $module = 'default'; }
$controller = $request->getControllerName();
$action = $request->getActionName();
if ($module === 'default' &&
$controller === 'items' &&
in_array($action, array('add', 'edit')) )
{
// ------------------------------------------
// An array of dependencies:
// Each dependency is represented by a "dependee", a "term", and a "dependent".
// ... meaning: If and only if the "dependee"'s value equals the "term", the "dependent" will be visible.
// Retrieve dependencies from Database
/* */
$json=get_option('conditional_elements_dependencies');
if (!$json) { $json="[]"; } # else { $json = $this->_removeOutdatedDependencies($json); }
/* */
echo "<script>var conditionalElementsDep=$json;</script>";
// ------------------------------------------
queue_js_file('conditionalelements');
} # if ($module === 'default' ...
} # public function hookAdminHead()
/**
* Deliver element set IDs that are suitable to become dependent / dependee elements
* i.e. 1 (for Dublin Core elements) and (usually) 3 (for metadata elements)
*/
public function conditionalElementsValidElementSets() {
$db = get_db();
$query = "SELECT id FROM `$db->ElementSets`".
" WHERE name='Dublin Core'".
" OR (record_type='Item' and name='Item Type Metadata')";
$ids = $db->fetchAll($query);
$result = array();
foreach($ids as $id) { $result[] = $id["id"]; }
return $result;
}
} # class