-
Notifications
You must be signed in to change notification settings - Fork 3
/
ADRBasic.inc
178 lines (154 loc) · 4.92 KB
/
ADRBasic.inc
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
<?php
// $Id$
/**
* @file
*
* Basic viewer for Colorado Alliance style Fedora Objects.
*/
/**
* A viewer for Fedora Objects
*/
class ADRBasic {
/**
* The PID of the object to be viewed/managed.
*
* @var string
*/
protected $pid;
/**
* Create a view for describing/managing an object.
*
* @param string $pid
*/
public function __construct($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$this->pid = $pid;
}
/**
* Can we show the manage panel.
*
* Checks user permissions to decide if the user can manage this collection.
*
* @return boolean
*/
private function canShowManagePanel() {
module_load_include('inc','islandora_xacml_api','Xacml');
module_load_include('inc','islandora_xacml_api','XacmlException');
global $user;
if ($user->uid == 1 || in_array('administrator', $user->roles)) {
$show = TRUE;
}
else {
try {
$xacml = Xacml::constructFromPid($this->pid);
if($xacml->managementRule->isPopulated()) {
$show = $xacml->managementRule->hasPermission($user->name, $user->roles);
}
else {
$show = FALSE;
}
}
catch (XacmlException $e) {
$show = FALSE;
}
}
$show &= user_access('purge objects and datastreams')
|| user_access('add fedora datastreams')
|| user_access('edit fedora meta data');
return $show;
}
/**
*
*/
private function includeRequiredScripts() {
$path = drupal_get_path('module', 'adr_basic_viewer');
module_load_include('module', 'ext', 'ext');
drupal_add_css("$path/stylesheets/Clear.css", 'theme', 'all');
ext_load_library();
drupal_add_css("$path/stylesheets/ADRBasic.css", 'theme', 'all');
module_load_include('inc', 'adr_basic_viewer', 'ADRBasicViewer');
ADRBasicViewer::includeRequiredJSForViewers($this->pid);
$data_stores = array(
'Datastreams.js',
'ObjectProperties.js',
'OverviewDatastreams.js',
'ControlGroups.js',
'MIMETypes.js',
'State.js',
);
$custom_components = array(
'FilesXTemplate.js',
'FileUploadField.ui.js',
'FileUploadField.js',
);
$main_viewer = array(
'ADRBasicViewer.ui.js',
'ADRBasicViewer.js',
'OverviewPanel.ui.js',
'OverviewPanel.js',
'DescriptionPanel.ui.js',
'DescriptionPanel.js',
'Files.ui.js',
'Files.js',
'ViewerPanel.ui.js',
'ViewerPanel.js',
);
$manage_panel = array(
'ManagePanel.ui.js',
'ManagePanel.js',
);
$manage_windows = array(
'AddFileWindow.ui.js',
'AddFileWindow.js',
//'ReplaceFileWindow.ui.js',
//'ReplaceFileWindow.js',
'EditObjectWindow.ui.js',
'EditObjectWindow.js',
);
$canEditObjects = user_access("edit fedora meta data");
$canEditPermissions = user_access("Edit XACML Policies");
$canDeleteObject = user_access("purge objects and datastreams");
$canAddStream = user_access("add fedora datastreams");
$canEditStream = user_access("edit fedora meta data");
$canDeleteStream = user_access("purge objects and datastreams");
$permissions_block =
"UserObjectPermissions.manage_canEditObjects=" . ($canEditObjects ? "true" : "false") . ";" .
"UserObjectPermissions.manage_canEditPermissions=" . ($canEditPermissions ? "true" : "false") . ";" .
"UserObjectPermissions.manage_canDeleteObject=" . ($canDeleteObject ? "true" : "false") . ";" .
"UserObjectPermissions.datastream_canAddStream=" . ($canAddStream ? "true" : "false") . ";" .
"UserObjectPermissions.datastream_canEditStream=" . ($canEditStream ? "true" : "false") . ";" .
"UserObjectPermissions.datastream_canDeleteStream=" . ($canDeleteStream ? "true" : "false") . ";";
drupal_add_js($permissions_block, 'inline');
drupal_add_js("$path/js/IncludeFirst.js");
$this->includeScripts($data_stores, $path);
$this->includeScripts($custom_components, $path);
$this->includeScripts($main_viewer, $path);
if($this->canShowManagePanel()){
$this->includeScripts($manage_panel, $path);
$this->includeScripts($manage_windows, $path);
}
drupal_add_js("$path/js/ADRBasic.js");
drupal_add_js("$path/js/resize.js");
}
/**
*
* @param array $scripts
* @param string $path
*/
private function includeScripts($scripts, $path) {
foreach ($scripts as $file) {
drupal_add_js("$path/js/$file");
}
}
/**
*
*/
public function render() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($this->pid);
$models = (isset($item->objectProfile->objModels->model) ? $item->objectProfile->objModels->model : array());
if(!in_array('info:fedora/islandora:iaBookCModel', $models) && !in_array('info:fedora/islandora:bookCModel', $models)) {
$this->includeRequiredScripts(); // Javascript all the way!
}
}
}