-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetDestinationFields.php
More file actions
46 lines (35 loc) · 1.25 KB
/
getDestinationFields.php
File metadata and controls
46 lines (35 loc) · 1.25 KB
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
<?php
/*
$data_entry_trigger_builder = new BCCHR\DataEntryTriggerBuilder\DataEntryTriggerBuilder();
$fields = $data_entry_trigger_builder->retrieveProjectMetadata($_POST["pid"]);
*/
// $det_builder = new BCCHR\DETBuilder\DETBuilder();
// $fields = $det_builder->retrieveProjectMetadata($_POST["pid"]);
// print json_encode($fields);
use BCCHR\DETBuilder\DETBuilder;
use ExternalModules\AbstractExternalModule;
$det_builder = new DETBuilder();
$raw = $det_builder->retrieveProjectMetadata($_POST['pid'] ?? null);
if (!is_array($raw)) {
$raw = [
'fields' => [],
'events' => [],
'isLongitudinal' => false,
];
}
$fields = isset($raw['fields']) && is_array($raw['fields']) ? $raw['fields'] : [];
$events = isset($raw['events']) && is_array($raw['events']) ? $raw['events'] : [];
$isLongitudinal = !empty($raw['isLongitudinal']);
$sanitized = [
'fields' => [],
'events' => [],
'isLongitudinal' => (bool) $isLongitudinal,
];
foreach ($fields as $field) {
$sanitized['fields'][] = $module->escape((string) $field);
}
foreach ($events as $event) {
$sanitized['events'][] = $module->escape((string) $event);
}
header('Content-Type: application/json');
echo json_encode($sanitized);