|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Activity\Controller; |
|
23
|
|
|
|
|
24
|
|
|
use OCP\AppFramework\Controller; |
|
25
|
|
|
use OCP\AppFramework\Http; |
|
26
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
27
|
|
|
use OCP\IRequest; |
|
28
|
|
|
|
|
29
|
|
|
class EndPoint extends Controller { |
|
30
|
|
|
|
|
31
|
|
|
/** @var OCSEndPoint */ |
|
32
|
|
|
protected $ocsEndPoint; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* OCSEndPoint constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $appName |
|
38
|
|
|
* @param IRequest $request |
|
39
|
|
|
* @param OCSEndPoint $ocsEndPoint |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct($appName, |
|
42
|
|
|
IRequest $request, |
|
43
|
|
|
OCSEndPoint $ocsEndPoint) { |
|
44
|
|
|
parent::__construct($appName, $request); |
|
45
|
|
|
$this->ocsEndPoint = $ocsEndPoint; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @NoAdminRequired |
|
50
|
|
|
* @NoCSRFRequired |
|
51
|
|
|
* |
|
52
|
|
|
* @return JSONResponse |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getDefault() { |
|
55
|
|
|
$response = $this->ocsEndPoint->getDefault([]); |
|
56
|
|
|
return $this->ocsToJsonResponse($response); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @NoAdminRequired |
|
61
|
|
|
* @NoCSRFRequired |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $filter |
|
64
|
|
|
* @return JSONResponse |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getFilter($filter) { |
|
67
|
|
|
$response = $this->ocsEndPoint->getFilter(['filter' => $filter]); |
|
68
|
|
|
return $this->ocsToJsonResponse($response); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param \OC_OCS_Result $ocsResult |
|
73
|
|
|
* @return JSONResponse |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function ocsToJsonResponse(\OC_OCS_Result $ocsResult) { |
|
76
|
|
|
$response = new JSONResponse( |
|
77
|
|
|
[ |
|
78
|
|
|
'ocs' => [ |
|
79
|
|
|
'meta' => [ |
|
80
|
|
|
'status' => 'ok', |
|
81
|
|
|
'statuscode' => 100, |
|
82
|
|
|
'message' => null, |
|
83
|
|
|
], |
|
84
|
|
|
'data' => $ocsResult->getData(), |
|
85
|
|
|
], |
|
86
|
|
|
], |
|
87
|
|
|
$ocsResult->getStatusCode() === 100 ? Http::STATUS_OK : $ocsResult->getStatusCode() |
|
88
|
|
|
); |
|
89
|
|
|
$response->setHeaders(\array_merge( |
|
90
|
|
|
$ocsResult->getHeaders(), |
|
91
|
|
|
[ |
|
92
|
|
|
'Content-Type' => 'application/json; charset=utf-8' |
|
93
|
|
|
] |
|
94
|
|
|
)); |
|
95
|
|
|
return $response; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|