-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeletonConnector.php
171 lines (154 loc) · 5.37 KB
/
SkeletonConnector.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
<?php
// set a namespace for the module
namespace SkeletonConnector;
// These can be left as is. We want to have access to the commonconnector tools as well as basic http / exception functions
require_once(ROOT . '/src/Lib/default/local_tool_connectors/CommonConnectorTools.php');
use CommonConnectorTools\CommonConnectorTools;
use Cake\Http\Client;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\Http\Client\Response;
class SkeletonConnector extends CommonConnectorTools
{
/*
*
* ====================================== Metainformation block ======================================
*
*/
public $description = '';
public $connectorName = 'SkeletonConnector';
public $name = 'Skeleton';
public $version = '0.1';
// exposed function list and configuration
public $exposedFunctions = [
'myIndexAction' => [
'type' => 'index',
'scope' => 'child',
'params' => [
'quickFilter',
'sort',
'direction',
'page',
'limit'
]
],
'myFormAction' => [
'type' => 'formAction',
'scope' => 'childAction',
'params' => [
'setting',
'value'
],
'redirect' => 'serverSettingsAction'
]
];
public function health(Object $connection): array
{
/*
returns an array with 2 keys:
[
status: the numeric response code (0: UNKNOWN, 1: OK, 2: ISSUES, 3: ERROR),
message: status message shown
]
*/
return $health;
}
/*
*
* ====================================== Exposed custom functions ======================================
*
*/
public function myIndexAction(array $params): array
{
// $data = get data from local tool
//if we want to filter it via the quicksearch
if (!empty($params['quickFilter'])) {
// filter $data
}
// return the data embedded in a generic index parameter array
return [
'type' => 'index',
'title' => false,
'description' => false,
'data' => [
'data' => $data,
'skip_pagination' => 1,
'top_bar' => [
'children' => [
[
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value',
'additionalUrlParams' => $urlParams
]
]
],
'fields' => [
[
'name' => 'field1_name',
'sort' => 'field1.path',
'data_path' => 'field1.path',
]
],
'pull' => 'right',
'actions' => [
[
'open_modal' => '/localTools/action/' . h($params['connection']['id']) . '/myForm?myKey={{0}}',
'modal_params_data_path' => ['myKey'],
'icon' => 'font_awesome_icon_name',
'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/myIndex'
]
]
]
];
}
public function myFormAction(array $params): array
{
if ($params['request']->is(['get'])) {
return [
'data' => [
'title' => __('My Form Title'),
'description' => __('My form description'),
'submit' => [
'action' => $params['request']->getParam('action')
],
'url' => ['controller' => 'localTools', 'action' => 'action', h($params['connection']['id']), 'myFormAction']
]
];
} elseif ($params['request']->is(['post'])) {
// handle posted data
if ($success) {
return ['success' => 1, 'message' => __('Action successful.')];
} else {
return ['success' => 0, 'message' => __('Action failed spectacularly.')];
}
}
throw new MethodNotAllowedException(__('Invalid http request type for the given action.'));
}
/*
*
* ====================================== Inter connection functions ======================================
*
*/
public function initiateConnection(array $params): array
{
// encode initial connection in local tool
// build and return initiation payload
return $payload;
}
public function acceptConnection(array $params): array
{
// encode acceptance of the connection request in local tool, based on the payload from the initiation
// return payload for remote to encode the connection
return $payload;
}
public function finaliseConnection(array $params): bool
{
// based on the payload from the acceptance, finalise the connection
// return true on success
return $success;
}
}
?>