-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatementsController.php
260 lines (218 loc) · 11.3 KB
/
StatementsController.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
<?php
require_once realpath(dirname(__FILE__)) . '/classes/ArticleIndexHelper.php';
/**
* This file is part of the {@link http://amsl.technology amsl} project.
*
* @author Sebastian Nuck
* @copyright Copyright (c) 2015, {@link http://ub.uni-leipzig.de Leipzig University Library}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* Statments component controller.
*
* @category OntoWiki
* @package Extensions_Statements
*/
class StatementsController extends OntoWiki_Controller_Component
{
/**
* Displays an information page.
* @return [type]
*/
public function collectiontolibraryAction()
{
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->getCustomLogger('statements');
$translate = $this->_owApp->translate;
$this->view->placeholder('main.window.title')->set($translate->_('Select Metadata Collections'));
$this->addModuleContext('main.window.fulltextsearch.info');
$_owApp->getNavigation()->disableNavigation();
$dicoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($dicoveryIndex);
$membership = $_owApp->getUser()->getIsMemberOf();
$this->view->label = $articleIndex->getOrganisationLabel($membership);
$this->view->membership = (isset($membership) && $membership !== "") ? $membership : $translate->_("The current user has no membership");
}
/**
* Retrieves the metadata sources from the virtuoso (is called via javascript).
* @return response
*/
public function metadatasourcesAction() {
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$dicoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($dicoveryIndex);
$models = $articleIndex->getMetadataSources();
$this->_response->setBody(json_encode($models));
}
public function checkallAction(){
$source = $this->_request->getParam("source");
$discoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndex);
$metadataCollections = $articleIndex->queryMetadataCollections($source);
$_owApp = OntoWiki::getInstance();
$membership = $_owApp->getUser()->getIsMemberOf();
$stmt = array();
foreach($metadataCollections as $collection){
if(($collection['usedBy'] == null && $collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/No') || ($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/Yes' && $collection['permittedForLibrary'] == $membership)) {
$stmt[$collection['collection']]['http://vocab.ub.uni-leipzig.de/amsl/metadataUsedByLibrary'][] = array('value' => $membership, 'type' => 'uri');
}
}
$store = $this->_erfurt->getStore();
$store->addMultipleStatements($discoveryIndex, $stmt);
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
}
public function uncheckallAction(){
$source = $this->_request->getParam("source");
$discoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndex);
$metadataCollections = $articleIndex->queryMetadataCollections($source);
$_owApp = OntoWiki::getInstance();
$membership = $_owApp->getUser()->getIsMemberOf();
$stmt = array();
foreach($metadataCollections as $collection){
if(($collection['usedBy'] != null && $collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/No') || ($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/Yes' && $collection['permittedForLibrary'] == $membership)) {
$stmt[$collection['collection']]['http://vocab.ub.uni-leipzig.de/amsl/metadataUsedByLibrary'][] = array('value' => $membership, 'type' => 'uri');
}
}
$store = $this->_erfurt->getStore();
$store->deleteMultipleStatements($discoveryIndex, $stmt);
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
}
public function evaluateallAction(){
$source = $this->_request->getParam("source");
$discoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndex);
$metadataCollections = $articleIndex->queryMetadataCollections($source);
$_owApp = OntoWiki::getInstance();
$membership = $_owApp->getUser()->getIsMemberOf();
$stmt = array();
foreach($metadataCollections as $collection){
if(($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/No') || ($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/Yes' && $collection['permittedForLibrary'] == $membership)){
$stmt[$collection['collection']]['http://vocab.ub.uni-leipzig.de/amsl/evaluateHoldingsFileFor'][] = array('value' => $membership, 'type' => 'uri');
}
}
$store = $this->_erfurt->getStore();
$store->addMultipleStatements($discoveryIndex, $stmt);
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
}
public function evaluetenoneAction(){
$source = $this->_request->getParam("source");
$discoveryIndex = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndex);
$metadataCollections = $articleIndex->queryMetadataCollections($source);
$_owApp = OntoWiki::getInstance();
$membership = $_owApp->getUser()->getIsMemberOf();
$stmt = array();
foreach($metadataCollections as $collection) {
if (($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/No') || ($collection['isRestricted'] == 'http://vocab.ub.uni-leipzig.de/amsl/Yes' && $collection['permittedForLibrary'] == $membership)) {
$stmt[$collection['collection']]['http://vocab.ub.uni-leipzig.de/amsl/evaluateHoldingsFileFor'][] = array('value' => $membership, 'type' => 'uri');
}
}
$store = $this->_erfurt->getStore();
$store->deleteMultipleStatements($discoveryIndex, $stmt);
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
}
/**
* Saves the users decision whether or not the EZB holdings files shall be checked
*/
public function checkholdingsfilesAction(){
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
$collection = $params['collection'];
$source = $params['source'];
$checked = $params['checked'];
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->getCustomLogger('statements');
$logger->debug('StatementsController:deletestatementAction: ' . $collection . ' --> ' . $source);
$membership = $_owApp->getUser()->getIsMemberOf();
$discoveryIndexUri = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndexUri);
if(isset($membership)) {
if ($_owApp->erfurt->getAc()->isModelAllowed('edit', $discoveryIndexUri) === true) {
if($checked == "true"){
$return = $articleIndex->saveCheckHoldingsFiles($collection, $membership);
}else{
$return = $articleIndex->deleteCheckHoldingsFiles($collection, $membership);
}
$this->_response->setBody(json_encode($return));
return;
} else {
$msg = 'StatementsController:deletestatementAction: not allowed to edit ';
$msg.= $discoveryIndexUri . '. Statement not deleted.';
$logger->debug($msg);
}
}
$this->_response->setHeader('HTTP/1.1 403 Forbidden');
}
/**
* Saves one collection after the checkbox has been checked while it was unchecked before.
*/
public function savearticleindexstatementAction() {
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
$collection = $params['collection'];
$source = $params['source'];
if (empty($collection) || empty($source)) {
return;
}
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->getCustomLogger('statements');
$logger->debug('StatementsController:savestatementAction: ' . $collection . ' --> ' . $source);
$membership = $_owApp->getUser()->getIsMemberOf();
$discoveryIndexUri = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndexUri);
if(isset($membership)) {
if ($_owApp->erfurt->getAc()->isModelAllowed('edit', $discoveryIndexUri) === true) {
$return = $articleIndex->saveStatement($collection, $membership);
$this->_response->setBody(json_encode($return));
return;
} else {
$msg = 'StatementsController:deletestatementAction: not allowed to edit ';
$msg.= $discoveryIndexUri . '. Statement not saved.';
$logger->debug($msg);
}
}
$this->_response->setHeader('HTTP/1.1 403 Forbidden');
}
/**
* Saves one collection after the checkbox has been unchecked while it was checked before.
*/
public function deletearticleindexstatementAction() {
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
$collection = $params['collection'];
$source = $params['source'];
if (empty($collection) || empty($source)) {
return;
}
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->getCustomLogger('statements');
$logger->debug('StatementsController:deletestatementAction: ' . $collection . ' --> ' . $source);
$membership = $_owApp->getUser()->getIsMemberOf();
$discoveryIndexUri = $this->_privateConfig->statements->discoveryIndex;
$articleIndex = new ArticleIndexHelper($discoveryIndexUri);
if(isset($membership)) {
if ($_owApp->erfurt->getAc()->isModelAllowed('edit', $discoveryIndexUri) === true) {
$return = $articleIndex->deleteStatement($collection, $membership);
$this->_response->setBody(json_encode($return));
return;
} else {
$msg = 'StatementsController:deletestatementAction: not allowed to edit ';
$msg.= $discoveryIndexUri . '. Statement not deleted.';
$logger->debug($msg);
}
}
$this->_response->setHeader('HTTP/1.1 403 Forbidden');
}
}