-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkandcreateController.php
75 lines (68 loc) · 2.42 KB
/
LinkandcreateController.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
<?php
/**
* This file is part of the {@link http://amsl.technology amsl} project.
*
* @author Norman Radtke
* @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)
*/
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* Controller for the linkandcreate extension
*
* @category OntoWiki
* @package OntoWiki_extensions_files
*/
class LinkandcreateController extends OntoWiki_Controller_Component
{
/*
* This action can be used to add a predicate and object to the selected Resource.
* It uses access control, adding triples to models one isn't allowed to won't be possible
*
*/
public function linktripleAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
if ($this->_request->isPost()) {
$post = $this->_request->getPost();
if (isset($post['predicate'])
&& isset($post['object']))
{
// everything fine
} else {
// necessarry parameters are missing
$this->_response->setHeader(http_response_code(500));
return;
}
$predicate = urldecode($post['predicate']);
$object = urldecode($post['object']);
$subject = urldecode($post['subject']);
if($subject == null){
$subject = (string)$this->_owApp->selectedResource;
}
if (Erfurt_Uri::check($predicate) && Erfurt_Uri::check($object)) {
$this->_owApp->selectedModel->addStatement(
$subject,
$predicate,
array('value' => $object, 'type' => 'uri')
);
$this->_response->setHeader(http_response_code(200));
return;
} else {
// data contains no valid URIs
$this->_response->setHeader(http_response_code(500));
return;
}
} else {
// no post request
$this->_response->setHeader(http_response_code(500));
return;
}
}
}