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
|
<?php
define('APP_ID', 'data-quest Test');
define('BASE_URL', 'http://localhost:8080/edu-sharing');
define('USERNAME', 'root@studip');
header('Accept: application/json');
header('Content-Type: application/json');
require_once "../edu-sharing-helper.php";
require_once "../edu-sharing-helper-base.php";
require_once "../edu-sharing-auth-helper.php";
require_once "../edu-sharing-node-helper.php";
$privatekey = @file_get_contents('private.key');
if(!$privatekey) {
die('no private key');
} else {
$key["privatekey"] = $privatekey;
}
// init the base class instance we use for all helpers
$base = new EduSharingHelperBase(BASE_URL, $key["privatekey"], APP_ID);
$postData = json_decode(file_get_contents('php://input'));
$action = $postData->action;
$result = null;
if ($action === 'BASE_URL') {
$result = BASE_URL;
} else if ($action === 'GET_NODE') {
$nodeHelper = new EduSharingNodeHelper($base);
$result = $nodeHelper->getNodeByUsage(
new Usage(
$postData->nodeId,
$postData->nodeVersion,
$postData->containerId,
$postData->resourceId,
$postData->usageId
)
);
} else if ($action === 'CREATE_USAGE') {
$nodeHelper = new EduSharingNodeHelper($base);
$result = $nodeHelper->createUsage(
$postData->ticket,
$postData->containerId,
$postData->resourceId,
$postData->nodeId
);
} else if ($action === 'DELETE_USAGE') {
$nodeHelper = new EduSharingNodeHelper($base);
$nodeHelper->deleteUsage(
$postData->nodeId,
$postData->usageId
);
} else if ($action === 'TICKET') {
$authHelper = new EduSharingAuthHelper($base);
$ticket = $authHelper->getTicketForUser(USERNAME);
$result = $ticket;
}
echo json_encode($result);
|